summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.h2
-rw-r--r--src/graphics_c3.c20
-rw-r--r--src/hackvr.c144
-rw-r--r--src/math.c15
4 files changed, 111 insertions, 70 deletions
diff --git a/src/config.h b/src/config.h
index 8017254..4df7467 100644
--- a/src/config.h
+++ b/src/config.h
@@ -15,7 +15,7 @@
#define SHAPES 65535
#define PERIODIC_OUTPUT 100
-#define MAX_SIDES 8
+#define MAX_SIDES 20
#define MAXWIDTH 4000
#define WIDTH 1024
#define MAXHEIGHT 3000
diff --git a/src/graphics_c3.c b/src/graphics_c3.c
index 9db6657..5f89c34 100644
--- a/src/graphics_c3.c
+++ b/src/graphics_c3.c
@@ -192,6 +192,10 @@ void draw_minimap_line(c3_t p1,c3_t p2) {
}
*/
+void draw_c3_line(c3_group_rot_t eye,c3_t p1, c3_t p2) {
+ draw_c2_line(c3_to_c2(eye,p1),c3_to_c2(eye,p2));
+}
+
void draw_c3_shape(c3_group_rot_t eye,c3_s_t s) {//outlined. needs to be filled? //draw minimap shit in here too? probably...
int i;
char drawthefucker=0;//I don't wanna!
@@ -478,18 +482,32 @@ void draw_screen() {
draw_c2_line((c2_t){0,0},rotate_c2((c2_t){-40,0},(c2_t){0,0},d2r((degrees){360-global.eye[en].r.y.d})));
set_color_blue();
draw_c2_line((c2_t){0,0},rotate_c2((c2_t){40,0},(c2_t){0,0},d2r(global.eye[en].r.z)));
+
+ c3_t mouse_v3 = (c3_t){gra_global.mouse.x,gra_global.mouse.y,0};//dunno about the 'z' for mouse.
+ set_color_red();
+ draw_c3_line(global.eye[en],c3_add(mouse_v3,(c3_t){ 1,0,0}),c3_add(mouse_v3,(c3_t){ 5,0,0}));
+ draw_c3_line(global.eye[en],c3_add(mouse_v3,(c3_t){-1,0,0}),c3_add(mouse_v3,(c3_t){-5,0,0}));
+ set_color();
+ draw_c3_line(global.eye[en],c3_add(mouse_v3,(c3_t){0, 1,0}),c3_add(mouse_v3,(c3_t){0, 5,0}));
+ draw_c3_line(global.eye[en],c3_add(mouse_v3,(c3_t){0,-1,0}),c3_add(mouse_v3,(c3_t){0,-5,0}));
+ set_color_blue();
+ draw_c3_line(global.eye[en],c3_add(mouse_v3,(c3_t){0,0, 1}),c3_add(mouse_v3,(c3_t){0,0, 5}));
+ draw_c3_line(global.eye[en],c3_add(mouse_v3,(c3_t){0,0,-1}),c3_add(mouse_v3,(c3_t){0,0,-5}));
}
//just draw a line from center to 40 away from the center at the angle of the camera's y-rotation
//this should be minimap shit
//draw a line from the center to 80 away from the center in the angle of what should point at the mouse.
//draw_c2_line((c2_t){0,0},gra_global.mouse);
+
+ //software mouse cursor
set_color();
draw_c2_line(c2_add(gra_global.mouse,(c2_t){0,1}) , c2_add(gra_global.mouse,(c2_t){0,5}) );
draw_c2_line(c2_add(gra_global.mouse,(c2_t){0,-1}) , c2_add(gra_global.mouse,(c2_t){0,-5}) );
draw_c2_line(c2_add(gra_global.mouse,(c2_t){1,0}) , c2_add(gra_global.mouse,(c2_t){5,0}) );
draw_c2_line(c2_add(gra_global.mouse,(c2_t){-1,0}) , c2_add(gra_global.mouse,(c2_t){-5,0}) );
- set_color();
+
+
//if(points_on_same_side_of_line(gra_global.mouse,(c2_t){80,80},(c2_t){0,0},(c2_t){0,80})) {
//draw_c2_line((c2_t){0,0},rotate_c2((c2_t){80,0},(c2_t){0,0},points_to_angle((c2_t){0,0},gra_global.mouse)));
//}
diff --git a/src/hackvr.c b/src/hackvr.c
index b895f58..cf441ea 100644
--- a/src/hackvr.c
+++ b/src/hackvr.c
@@ -38,7 +38,7 @@ struct hvr_global global;
int lum_based_on_distance(c3_s_t *s) {
int i;
- real sum;
+ real sum=0;
for(i=0;i < s->len;i++) {
sum+=distance2((c2_t){s->p[i].x,s->p[i].z},(c2_t){0,0});
}
@@ -154,11 +154,14 @@ int hackvr_handler(char *line) {
int ret=0;
int len;
int j,i,k,l;
+ int key_count;
c3_group_rot_t *gr;
real tmpx,tmpy,tmpz;
char **a;
+ char **keys;
char tmp[256];
struct entry *m;
+ struct entry *next;
char helping=0;//a flag that we can check for to see if we need to output our help
// radians tmpradx,tmprady,tmpradz;
radians tmprady;
@@ -167,6 +170,8 @@ int hackvr_handler(char *line) {
//might use these so make command code easier to read.
char *command;
//char **args;
+
+
if(!line) return -1;//EOF
if(*line == '#') return 0;
// fprintf(stderr,"# read command: %s\n",line);
@@ -177,31 +182,31 @@ int hackvr_handler(char *line) {
// printf("\n");
id=a[0];
if(len > 1) {
- command=a[1];
+ command=a[1];
} else {
- command=a[0];//meh
+ command=a[0];//meh
}
if(len < 2) {
- if(!strcmp(id,"version")) {
- hvr_version();
- return 0;
- }
- if(!strcmp(id,"help")) {
- helping=1;
+ if(!strcmp(id,"version")) {
+ hvr_version();
+ return 0;
+ }
+ if(!strcmp(id,"help")) {
+ helping=1;
#ifdef GRAPHICAL
- fprintf(stderr,"# NOT built headless.\n");
+ fprintf(stderr,"# NOT built headless.\n");
#else
- fprintf(stderr,"# built headless.\n");
+ fprintf(stderr,"# built headless.\n");
#endif
- fprintf(stderr,"# commands that don't get prepended with groupname: help, version\n");
- fprintf(stderr,"# command format:\n");
- fprintf(stderr,"# group names can be globbed in some cases to operate on multiple groups\n");
- fprintf(stderr,"# some commands that take numbers as arguments can be made to behave relative\n");
- fprintf(stderr,"# by putting + before the number. makes negative relative a bit odd like:\n");
- fprintf(stderr,"# user move +-2 +-2 0\n");
- fprintf(stderr,"# groupnam* command arguments\n");
- fprintf(stderr,"# commands:\n");
- }
+ fprintf(stderr,"# commands that don't get prepended with groupname: help, version\n");
+ fprintf(stderr,"# command format:\n");
+ fprintf(stderr,"# group names can be globbed in some cases to operate on multiple groups\n");
+ fprintf(stderr,"# some commands that take numbers as arguments can be made to behave relative\n");
+ fprintf(stderr,"# by putting + before the number. makes negative relative a bit odd like:\n");
+ fprintf(stderr,"# user move +-2 +-2 0\n");
+ fprintf(stderr,"# groupnam* command arguments\n");
+ fprintf(stderr,"# commands:\n");
+ }
}
ret=1;
@@ -209,36 +214,44 @@ int hackvr_handler(char *line) {
/* ---------- */
if(helping) fprintf(stderr,"# deleteallexcept grou*\n");
if(!strcmp(command,"deleteallexcept")) {
- if(len == 3) {
- for(j=0;global.shape[j] && j < MAXSHAPES;j++) {//mark first. compress later.
- if(glob_match(a[2],global.shape[j]->id)) {
- free(global.shape[j]->id);
- free(global.shape[j]);
- global.shape[j]=0;
- }
- }
- for(k=0;k<j;k++) {
- if(global.shape[k]) continue;
- for(l=k;global.shape[l] == 0 && l<j;l++);
- global.shape[k]=global.shape[l];
- global.shape[l]=0;
- }
- ret=1;
- //now do the same stuff but for the group_rot structs.
- for(i=0;i < global.ht_group.kl;i++) {//for each bucket and item in each bucket...
- for(m=global.ht_group.bucket[global.ht_group.keys[i]]->ll;m;m=m->next) {
- if(!glob_match(a[2],m->original)) {
- if(m->target != &global.camera) {
- gr=m->target;
- ht_delete(&global.ht_group,gr->id);
- free(gr->id);
- free(gr);//pretty sure this does NOT get free()d by ht_delete, because the HT can't /know/ its value is a pointer to something malloc()d
- }
+ if(len == 3) {
+ for(j=0;global.shape[j] && j < MAXSHAPES;j++) {//mark first. compress later.
+ if(glob_match(a[2],global.shape[j]->id)) {
+ free(global.shape[j]->id);
+ free(global.shape[j]);
+ global.shape[j]=0;
+ }
}
- }
+ for(k=0;k<j;k++) {//compress the shape array around the gaps
+ if(global.shape[k]) continue;
+ for(l=k;global.shape[l] == 0 && l<j;l++);
+ global.shape[k]=global.shape[l];
+ global.shape[l]=0;
+ }
+ //now do the same stuff but for the group_rot structs.
+ if(!strchr(a[2],'*')) {//no globs, this is easy...
+ ht_delete(&global.ht_group,m->original);
+ } else {
+ keys=ht_getkeys(&global.ht_group,&key_count);
+ for(i=0;i<key_count;i++) {
+ if((m=ht_getentry(&global.ht_group,keys[i]))) {
+ if(!glob_match(a[2],m->original)) {
+ if(m->target != &global.camera) {
+ free(m->target->id);
+ free(m->target);//ht_delete doesn't know that the target is a malloc()d structure, so we have to do this.
+ ht_delete(&global.ht_group,m->original);
+ }
+ }
+ } else {
+ fprintf(stderr,"# somehow an item is in the list of keys but ht_getentry failed. '%s'\n",a[2]);
+ abort();
+ }
+ }
+ free(keys);
+ }
+ ret=1;
+ return ret;
}
- return ret;
- }
}
@@ -261,18 +274,23 @@ int hackvr_handler(char *line) {
global.shape[k]=global.shape[l];
global.shape[l]=0;
}
- //we need to glob match all keys...
- for(i=0;i < global.ht_group.kl;i++) {//for each bucket and item in each bucket...
- for(m=global.ht_group.bucket[global.ht_group.keys[i]]->ll;m;m=m->next) {
- if(!glob_match(a[2],m->original)) {
- if(m->target != &global.camera) {//ah! don't delete the camera!
- gr=m->target;//this almost CERTAINLY exists... I think.
- ht_delete(&global.ht_group,gr->id);
- free(gr->id);
- free(gr);
- }
+ if(!strchr(a[2],'*') {//don't bother looping over everything if it isn't a glob..
+ ht_delete(&global.ht_group,a[2]);
+ } else {
+ keys=ht_getkeys(&global.ht_group,&key_count);
+ for(i=0;i<key_count;i++) {
+ if((m=ht_getentry(&global.ht_group,keys[i]))) {
+ if(m->target != &global.camera) {
+ free(m->target->id);
+ free(m->target);
+ ht_delete(&global.ht_group,m->original);
+ }
+ } else {
+ fprintf(stderr,"# somehow an item is in the list of keys but ht_getentry failed. '%s'\n",a[2]);
+ abort();
+ }
}
- }
+ free(keys);
}
ret=1;
return ret;
@@ -669,8 +687,9 @@ int hackvr_handler(char *line) {
tmpx=0;
tmpz=0;
}
- snprintf(tmp,sizeof(tmp)-1,"%s move +%f +%f +%f\n",global.user,tmpx,tmpy,tmpz);
- selfcommand(tmp);//selfcommand inside move is ugly. :/ just set it the right way.
+ gr->p.x+=tmpx;
+ gr->p.y+=tmpy;
+ gr->p.z+=tmpz;
} else {
fprintf(stderr,"# ERROR: wrong amount of parts for move. got: %d expected: 4 or 2\n",len);
}
@@ -733,6 +752,9 @@ int main(int argc,char *argv[]) {
//I could just read
}
global.user=strdup(getenv("USER"));//this gets free()d later so we need to strdup it.
+ if(!strcmp(global.user,"help") || !strcmp(global.user,"version")) {
+ fprintf(stderr,"# /!\\ WARNING /!\\/ a USER of help or version maybe cause problems when piped into another hackvr. right now it is '%s'\n",global.user);
+ }
global.localecho=1;
inittable(&global.ht_group,65536);
diff --git a/src/math.c b/src/math.c
index 9d9245b..9e7afbd 100644
--- a/src/math.c
+++ b/src/math.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "common.h"
#include "math.h"
@@ -11,20 +12,20 @@ extern struct hvr_global global;
//ONE OF THESE DAYS I NEED TO RENAME ALL THE GROUP_ROT SHIT TO GROUP_REL since it doesn't just have rotations anymore.
//this function needs to create a group_relative if one doesn't already exist.
-c3_group_rot_t *get_group_relative(char *id) {//crashes in here somehwere...
+c3_group_rot_t *get_group_relative(char *id) {
c3_group_rot_t *gr;
- struct entry *tmp;
- if((tmp=ht_getnode(&global.ht_group,id))) {
- gr=tmp->target;//target is a void *
+ if((gr=ht_getvalue(&global.ht_group,id))) {
if(gr) return gr;
}
//if we got here, we need to make a new one.
- gr=malloc(sizeof(c3_group_rot_t));
+ assert(gr=malloc(sizeof(c3_group_rot_t)));//just exit on malloc error? sure...
memset(gr,0,sizeof(c3_group_rot_t));
gr->s=(c3_t){1,1,1};//scale needs to be all 1s, since it is multiplied against the coordinates.
gr->id=strdup(id);//don't forget to free this when it gets deleted.
- ht_setkey(&global.ht_group,gr->id,gr);
- return gr;//check only for the case of malloc errors.
+ if(ht_setkey(&global.ht_group,id,gr)) {
+ abort();
+ }
+ return gr;
}
c3_t rotate_c3_xr(c3_t p1,c3_t p2,radians xr) {//rotate y and z around camera based on xr (looking up and down)