summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2017-03-19 04:51:01 -0500
committerepoch <epoch@hacking.allowed.org>2017-03-19 04:51:01 -0500
commit781ecd6529505e4bf1fd400634ee83bcb9a07c81 (patch)
treea5f51756d54dff5ebb47f5435198e1db15ce345d /src
parent17347b2e23292aad11c879d3df4a0e73c31e2ae8 (diff)
downloadhackvr-781ecd6529505e4bf1fd400634ee83bcb9a07c81.tar.gz
hackvr-781ecd6529505e4bf1fd400634ee83bcb9a07c81.zip
I have no idea why I am doing this...
Diffstat (limited to 'src')
-rw-r--r--src/HACKING20
-rw-r--r--src/Makefile21
-rw-r--r--src/common.h19
-rw-r--r--src/config.h5
-rw-r--r--src/graphics_c2.c41
-rw-r--r--src/graphics_c2.h17
-rw-r--r--src/graphics_c2_opengl.c193
-rw-r--r--src/graphics_c2_opengl.h (renamed from src/graphics_opengl.h)0
-rw-r--r--src/graphics_c3.c (renamed from src/graphics.c)225
-rw-r--r--src/graphics_c3.h (renamed from src/graphics.h)2
-rw-r--r--src/graphics_cs.h (renamed from src/graphics_backend.h)8
-rw-r--r--src/graphics_cs_opengl.c0
-rw-r--r--src/graphics_cs_x11.c (renamed from src/graphics_x11.c)116
-rw-r--r--src/graphics_opengl.c151
-rw-r--r--src/hackvr.c106
-rw-r--r--src/math.c15
-rw-r--r--src/math.h1
-rwxr-xr-xsrc/testit.sh4
18 files changed, 563 insertions, 381 deletions
diff --git a/src/HACKING b/src/HACKING
new file mode 100644
index 0000000..98bac03
--- /dev/null
+++ b/src/HACKING
@@ -0,0 +1,20 @@
+oh god. I have no idea what I'm doing.
+
+may the gods have mercy on my soul for this monstrosity..
+
+so.
+
+hackvr.c can optionally use graphics or not.
+
+if you choose to have graphics you can choose between:
+
+x11 or opengl+glut
+
+There are three layers of the graphics code..
+
+I'm not exactly sure how I'm going to combine these.
+
+graphics_c3.c uses functions defined in a graphics_c2* file.
+graphics_c2.c uses function defined in a graphics_cs* file.
+
+some graphical backends may provide their own graphics_c3.c?
diff --git a/src/Makefile b/src/Makefile
index d3e80a2..c41781e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,17 +1,18 @@
CFLAGS=-Wall -pedantic -std=c99 -DGRAPHICAL -ffast-math
-#all: hackvr_headless hackvr_x11 hackvr_opengl slowcat ### when hackvr_opengl gets useful at all I'll start including it in default build.
-all: hackvr_headless hackvr_x11 slowcat
- ln -s hackvr_x11 hackvr
+all: hackvr_headless hackvr_x11 hackvr_opengl slowcat ### when hackvr_opengl gets useful at all I'll start including it in default build.
+#all: hackvr_headless hackvr_x11 slowcat
+ ln -sf hackvr_x11 hackvr
hackvr_headless: LDLIBS=-lm
hackvr_headless: hackvr_headless.o math.o
hackvr_x11: LDLIBS=-lm -lX11
-hackvr_x11: hackvr_x11.o graphics.o graphics_x11.o math.o
+hackvr_x11: hackvr_x11.o graphics_c3.o graphics_c2.o graphics_cs_x11.o math.o
+#notice how all the targets have generic graphics objects up until a specific one.
hackvr_opengl: LDLIBS=-lm -lGL -lGLU -lglut
-hackvr_opengl: hackvr_opengl.o graphics.o graphics_opengl.o math.o
+hackvr_opengl: hackvr_opengl.o graphics_c3.o graphics_c2_opengl.o graphics_cs_opengl.o math.o
hackvr_opengl.o: LDLIBS=-lm -lGL -lGLU -lglut
hackvr_x11.o: LDLIBS=-lm -lX11
@@ -19,9 +20,13 @@ hackvr_x11.o: LDLIBS=-lm -lX11
hackvr_headless.o: CFLAGS=-Wall -pedantic -std=c99 -ffast-math
hackvr_headless.o: LDLIBS=-lm
-graphics.o: LDLIBS=-lm
-graphics_x11.o: LDLIBS=-lm -lX11
-graphics_opengl.o: LDLIBS=-lm -lGL -lGLU -lglut
+graphics_c3.o: LDLIBS=-lm
+graphics_c2.o: LDLIBS=-lm
+
+graphics_cs_x11.o: LDLIBS=-lm -lX11
+
+graphics_c2_opengl.o: LDLIBS=-lm -lGL -lGLU -lglut
+graphics_cs_opengl.o: LDLIBS=-lm -lGL -lGLU -lglut
math.o: LDLIBS=-lm
clean:
diff --git a/src/common.h b/src/common.h
index 859c826..bdabb4f 100644
--- a/src/common.h
+++ b/src/common.h
@@ -1,9 +1,15 @@
#include "config.h"
+#include "math.h"
#ifndef _HACKVR_COMMON_H_
#include <X11/Xlib.h>
#define _HACKVR_COMMON_H_
+#define TOP 240.0
+#define BOTTOM -240.0
+#define RIGHT 320.0
+#define LEFT -320.0
+
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
@@ -33,17 +39,17 @@ typedef struct {
short y;
} cs_t;
-typedef struct c3_rotation {
+typedef struct {
degrees x;
degrees y;
degrees z;
} c3_rot_t;
-struct camera {
- c3_t p;
+typedef struct {
+ char *id;
c3_rot_t r;
- real zoom;
-} camera;
+ c3_t p;
+} c3_group_rot_t;
typedef struct c3_line {
char *id;
@@ -80,6 +86,9 @@ struct global {
real mmz;
struct c3_shape *shape[SHAPES];
int shapes;
+ c3_group_rot_t *group_rot[256];//meh
+ c3_group_rot_t camera;
+ real zoom;
int derp;
real split;
};
diff --git a/src/config.h b/src/config.h
index 08ce918..2ef2d1a 100644
--- a/src/config.h
+++ b/src/config.h
@@ -8,14 +8,15 @@
#define DEBUG 1
#define WALK_SPEED 1
-#define SPLIT_SCREEN 2
+#define SPLIT_SCREEN 1
#define CAMERA_SEPARATION -1
-#define RED_AND_BLUE 1
+#define RED_AND_BLUE 0
#define SHAPES 16386
#define MAX_SIDES 8
#define WIDTH 4000
#define HEIGHT 3000
#define DEFAULT_MINIMAP 0
#define FORCE_REDRAW 1
+#define MAXSHAPES 3000
#endif
diff --git a/src/graphics_c2.c b/src/graphics_c2.c
new file mode 100644
index 0000000..17f1828
--- /dev/null
+++ b/src/graphics_c2.c
@@ -0,0 +1,41 @@
+#include "graphics_cs.h"
+#include "graphics_c3.h"
+
+extern struct gra_global gra_global;
+
+int c2sX(real x) { return (gra_global.width/(gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen: 1))) * ((x + RIGHT) / (RIGHT *2)) + gra_global.xoff; }
+int s2cX(real x) { return (x/(gra_global.width/(gra_global.split_screen / (gra_global.red_and_blue?gra_global.split_screen :1))))*(RIGHT*2)-RIGHT; }
+
+int c2sY(real y) { return gra_global.height * ((TOP-y) / (TOP*2)); }
+int s2cY(real y) { return -((y/gra_global.height) * (TOP*2) - TOP); }
+
+cs_t c2_to_cs(c2_t p) {
+ return (cs_t){c2sX(p.x),c2sY(p.y)};
+}
+c2_t cs_to_c2(cs_t p) {
+ return (c2_t){s2cX(p.x),s2cY(p.y)};
+}
+
+void draw_c2_line(c2_t p1,c2_t p2) {
+ draw_cs_line(c2_to_cs(p1),c2_to_cs(p2));
+}
+
+void draw_c2_shape(c2_s_t s) {
+ int i;
+ cs_s_t ss;
+ ss.len=s.len;
+ ss.id=s.id;
+ for(i=0;i<s.len;i++) {
+ ss.p[i]=c2_to_cs(s.p[i]);
+ }
+ draw_cs_shape(ss);
+}
+
+void draw_c2_filled_shape(c2_s_t s) {
+ draw_c2_shape(s);//heh. TODO: fixme
+}
+
+void draw_c2_text(c2_t p,char *text) {
+ cs_t p2=c2_to_cs(p);
+ draw_cs_text(p2,text);
+}
diff --git a/src/graphics_c2.h b/src/graphics_c2.h
new file mode 100644
index 0000000..35920fd
--- /dev/null
+++ b/src/graphics_c2.h
@@ -0,0 +1,17 @@
+#ifndef _HACKVR_GRAPHICS_C2_H_
+#define _HACKVR_GRAPHICS_C2_H_
+
+#include "math.h"
+
+int c2sX(real x);
+int s2cX(real x);
+int c2sY(real y);
+int s2cY(real y);
+cs_t c2_to_cs(c2_t p);
+c2_t cs_to_c2(cs_t p);
+void draw_c2_line(c2_t p1,c2_t p2);
+void draw_c2_shape(c2_s_t s);
+void draw_c2_filled_shape(c2_s_t s);
+void draw_c2_text(c2_t p,char *text);
+
+#endif
diff --git a/src/graphics_c2_opengl.c b/src/graphics_c2_opengl.c
new file mode 100644
index 0000000..3429193
--- /dev/null
+++ b/src/graphics_c2_opengl.c
@@ -0,0 +1,193 @@
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <GL/glut.h>
+#include <GL/freeglut_ext.h>
+
+#include "common.h"
+#include "graphics_cs.h"
+#include "graphics_c2.h"
+#include "graphics_c3.h"
+
+extern struct gra_global gra_global;
+
+GLenum doubleBuffer;
+GLubyte ubImage[65536];
+
+#define RIGHT 320.0
+#define LEFT -320.0
+#define TOP 240.0
+#define BOTTOM -240.0
+
+int c2sX(real x) { return (gra_global.width/(gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen: 1))) * ((x + RIGHT) / (RIGHT *2)) + gra_global.xoff; }
+int s2cX(real x) { return (x/(gra_global.width/(gra_global.split_screen / (gra_global.red_and_blue?gra_global.split_screen :1))))*(RIGHT*2)-RIGHT; }
+
+int c2sY(real y) { return gra_global.height * ((TOP-y) / (TOP*2)); }
+int s2cY(real y) { return -((y/gra_global.height) * (TOP*2) - TOP); }
+
+cs_t c2_to_cs(c2_t p) {
+ return (cs_t){c2sX(p.x),c2sY(p.y)};
+}
+
+c2_t cs_to_c2(cs_t p) {
+ return (c2_t){s2cX(p.x),s2cY(p.y)};
+}
+
+void set_aspect_ratio(int w,int h) {
+ glViewport(0,0,w,h);
+// glMatrixMode(GL_PROJECTION);
+// glLoadIdentity();
+// glOrtho(LEFT,RIGHT,BOTTOM,TOP,0,0);
+// glTranslatef(0,-h,0);
+}
+
+void set_color_based_on_distance(real d) {
+ //scale this color based on distance... closer is lighter.
+// float g;
+// g=d/100.0
+ glColor3f(0.0, 1.0, 0.0);
+}
+
+void set_clipping_rectangle(int x,int y,int w,int h) {
+
+}
+
+void draw_c2_line(c2_t p1,c2_t p2) {
+ //glBegin(GL_TRIANGLES);
+ glBegin(GL_LINES);
+ glColor3f(0.0, 1.0, 0.0);
+ glVertex2i(p1.x,p1.y);
+ glVertex2i(p2.x,p2.y);
+ //glVertex2i(p2.x,p2.y);
+ glEnd();
+}
+
+void draw_c2_text(c2_t p,char *s) {
+// printf("@%lF,%lF: %s\n",p.x,p.y,s);
+}
+
+void draw_c2_shape(c2_s_t s) {
+ int i;
+// printf("drawing shaep!\n");
+ for(i=0;i<s.len+(s.len==1);i++) {//this shape is closed!
+ draw_c2_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]);
+ }
+/* glBegin(GL_LINE_STRIP);
+ glColor3f(0.0, 1.0, 0.0);
+ for(i=0;i<s.len+(s.len==1);i++) {
+ glVertex2i(s.p[i].x,s.p[i].y);
+ }
+ glEnd();
+*/
+}
+
+void draw_c2_filled_shape(c2_s_t s) {
+ draw_c2_shape(s);
+// glBegin(GL_POLYGON);
+// glVertex2s();
+// glEnd();
+}
+
+void set_color() {
+ glColor3f(0.0, 1.0, 0.0);
+}
+
+void set_color_red() {
+ glColor3f(1.0, 0.0, 0.0);
+}
+
+void set_color_blue() {
+ glColor3f(0.0, 0.0, 1.0);
+}
+
+void clear_backbuffer() {
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+// glFlush();
+}
+
+void flipscreen() {
+// glutSwapBuffers();
+ glFlush();
+}
+
+void red_and_blue_magic() {
+
+}
+
+void keypress_handler(unsigned char key, int x, int y) {//x and y are mouse positions.
+ switch (key) {
+ case 27:
+ exit(0);
+ }
+}
+
+/* draw_screen is in graphics.c
+void draw_screen(void)
+{
+
+
+}*/
+
+
+void derp_screen() {
+ printf("derpsceen being called.\n");
+ clear_backbuffer();
+ set_color();
+
+ //this should work for draw_c2_line, not cs_line... merp.
+// draw_c2_line((c2_t){LEFT,0},(c2_t){RIGHT,0}); //horizon
+// draw_cs_line((cs_t){0,0},(cs_t){1,1});
+// draw_cs_line((cs_t){-1,0},(cs_t){0,1});
+// draw_cs_line((cs_t){0,0},(cs_t){-1,1});
+ /*draw_cs_line((cs_t){10,10},(cs_t){200,210});
+ draw_cs_line((cs_t){50,10},(cs_t){200,210});
+ draw_cs_line((cs_t){0,60},(cs_t){200,210});*/
+ flipscreen();
+}
+
+void empty() {
+}
+
+int graphics_sub_init(void)
+{
+// GLenum type;
+
+// type = GLUT_RGB;
+// type |= GLUT_DOUBLE;
+ int argc=0;
+ char *argv[]={"derp",0};
+ glutInit(&argc,argv);
+// glutInitDisplayMode(type);
+ glutCreateWindow("hackvr opengl and glut testing");
+ glutInitWindowSize(320,240);
+ glScalef((1.0/320.0),(1.0/240.0),-1);//only do this once!
+// glMatrixMode(GL_PROJECTION);
+// glLoadIdentity();
+// gluPerspective(60.0, 1.0, 0.1, 1000.0);
+// glMatrixMode(GL_MODELVIEW);
+// glDisable(GL_DITHER);
+
+ printf("test");
+
+ glutKeyboardFunc(keypress_handler);
+ glutDisplayFunc(draw_screen);//this is probably what should happen...
+ glutReshapeFunc(set_aspect_ratio);
+ return 0;//we're fine
+}
+
+
+int graphics_event_handler() {//return values: -1 exit, 0 don't redraw, anything else redraw
+ glutMainLoopEvent();
+ glutPostRedisplay();//heh. wonder if this works...
+ return 1;
+}
+
+/*
+void main(int argc,char *argv[]) {
+ graphics_init();
+ while(1) {
+ graphics_event_handler();
+ }
+}
+*/
diff --git a/src/graphics_opengl.h b/src/graphics_c2_opengl.h
index a5aa15d..a5aa15d 100644
--- a/src/graphics_opengl.h
+++ b/src/graphics_c2_opengl.h
diff --git a/src/graphics.c b/src/graphics_c3.c
index 3cb973f..5d18db3 100644
--- a/src/graphics.c
+++ b/src/graphics_c3.c
@@ -14,8 +14,10 @@
#include "config.h"
#include "common.h"
-#include "graphics_backend.h" //this header includes all the functions you'll need to implement if you want to port hackvr to something else
-#include "graphics.h"
+//#include "graphics_cs.h" //this header includes all the functions you'll need to implement if you want to port hackvr to something else
+#include "graphics_c3.h"//we're defining these functions in this file.
+#include "graphics_c2.h"//we're using these functions make them.
+#include "graphics_cs.h"//we'll need generic function that don't give a damn about which dimension it is?
//typedef float real; //think this conflicts?
@@ -39,18 +41,6 @@ struct gra_global gra_global;
#define RIGHT 320.0
#define LEFT -320.0
-int c2sX(real x) { return (gra_global.width/(gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen: 1))) * ((x + RIGHT) / (RIGHT *2)) + gra_global.xoff; }
-int s2cX(real x) { return (x/(gra_global.width/(gra_global.split_screen / (gra_global.red_and_blue?gra_global.split_screen :1))))*(RIGHT*2)-RIGHT; }
-
-int c2sY(real y) { return gra_global.height * ((TOP-y) / (TOP*2)); }
-int s2cY(real y) { return -((y/gra_global.height) * (TOP*2) - TOP); }
-
-cs_t c2_to_cs(c2_t p) {
- return (cs_t){c2sX(p.x),c2sY(p.y)};
-}
-c2_t cs_to_c2(cs_t p) {
- return (c2_t){s2cX(p.x),s2cY(p.y)};
-}
/*
real distance2(c2_t p1,c2_t p2) {
return sqrtl(( (p1.x-p2.x)*(p1.x-p2.x) )+( (p1.y-p2.y)*(p1.y-p2.y) ));
@@ -152,20 +142,53 @@ int get_2D_intersection_Y(x,y,d,x,z,d) {
}
*/
-void draw_c2_line(c2_t p1,c2_t p2) {
- draw_cs_line(c2_to_cs(p1),c2_to_cs(p2));
+c3_t c3_add(c3_t p1,c3_t p2) {
+ return (c3_t){p1.x+p2.x,p1.y+p2.y,p1.z+p2.z};
+}
+
+c3_t c3_subtract(c3_t p1,c3_t p2) {
+ return (c3_t){p1.x-p2.x,p1.y-p2.y,p1.z-p2.z};
+}
+
+#define MAGIC(x) (1.0l-(1.0l/powl(1.01l,(x)))) //??? might want to have some changables in here
+
+real magic(real x) {
+ return MAGIC(x);
+}
+
+c2_t c3_to_c2(c3_t p3) { //DO NOT DRAW STUFF IN HERE
+ c2_t p2;
+// c3_t tmp1;
+// c3_t tmp2;
+// c3_t tmp3;
+ c3_t final;
+//these rotations need to be about the previous axis after the axis itself has been rotated.
+
+ final=rotate_c3_yr(p3,global.camera.p,d2r(global.camera.r.y));//rotate everything around the camera's location.
+ //now to rotate the shape around it's group's center.
+// final=rotate_c3_yr(p3,(c3_t){0,0,0},d2r(camera.yr));//rotate everything around the center no matter what.
+// tmp2=rotate_c3_xr(tmp1,camera.p,d2r(camera.xr));
+// final=rotate_c3_zr(tmp2,camera.p,d2r(camera.zr));
+ real delta_x=(global.camera.p.x - final.x);
+ real delta_y=(global.camera.p.y - final.y);
+ real delta_z=(global.camera.p.z - final.z);
+// real d=distance3(camera.p,final);
+ p2.y=global.zoom * (delta_y * MAGIC(delta_z) - delta_y);
+ p2.x=global.zoom * (delta_x * MAGIC(delta_z) - delta_x);
+ return p2;
}
void draw_c3_shape(c3_s_t s) {//outlined. needs to be filled? //draw minimap shit in here too? probably...
int i;
- cs_s_t ss;
- ss.id=s.id;//it shouldn't disappear and we shouldn't need to make a copy.
- ss.len=s.len;
+ c2_s_t s2;
+ s2.id=s.id;//it shouldn't disappear and we shouldn't need to make a copy.
+ s2.len=s.len;
+ c3_group_rot_t *gr=get_group_rotation(s.id);
for(i=0;i<s.len+(s.len==1);i++) {
- ss.p[i]=c3_to_cs(s.p[i]);
+ s2.p[i]=c3_to_c2(gr?c3_add(gr->p,rotate_c3_yr(s.p[i],gr->p,d2r(gr->r.y))):s.p[i]);
}
if(gra_global.draw3d == 1) {
- draw_cs_shape(ss);
+ draw_c2_shape(s2);
}
if(gra_global.draw3d == 2) {
//set foreground to a gray based on distance
@@ -173,20 +196,14 @@ void draw_c3_shape(c3_s_t s) {//outlined. needs to be filled? //draw minimap shi
// color_based_on_distance();//I don't have the distance in here. :/
//foreground_set();
//how... I want to draw the outline as one color and the fill as another.
- draw_cs_filled_shape(ss);
+ draw_c2_filled_shape(s2);
set_color();//resets it to the default color.
- if(!strcmp(global.selected_object,ss.id)) {
- draw_cs_shape(ss);
+ if(!strcmp(global.selected_object,s2.id)) {
+ draw_c2_shape(s2);
}
}
}
-#define MAGIC(x) (1.0l-(1.0l/powl(1.01l,(x)))) //??? might want to have some changables in here
-
-real magic(real x) {
- return MAGIC(x);
-}
-
void draw_graph(real (*fun)(real x)) {
c2_t pa;
draw_c2_line((c2_t){LEFT,0},(c2_t){RIGHT,0});
@@ -202,37 +219,18 @@ void draw_graph(real (*fun)(real x)) {
}
}
-c2_t c3_to_c2(c3_t p3) { //DO NOT DRAW STUFF IN HERE
- c2_t p2;
-// c3_t tmp1;
-// c3_t tmp2;
-// c3_t tmp3;
- c3_t final;
-//these rotations need to be about the previous axis after the axis itself has been rotated.
- final=rotate_c3_yr(p3,camera.p,d2r(camera.r.y));//rotate everything around the camera's location.
-// final=rotate_c3_yr(p3,(c3_t){0,0,0},d2r(camera.yr));//rotate everything around the center no matter what.
-// tmp2=rotate_c3_xr(tmp1,camera.p,d2r(camera.xr));
-// final=rotate_c3_zr(tmp2,camera.p,d2r(camera.zr));
- real delta_x=(camera.p.x - final.x);
- real delta_y=(camera.p.y - final.y);
- real delta_z=(camera.p.z - final.z);
-// real d=distance3(camera.p,final);
- p2.y=camera.zoom * (delta_y * MAGIC(delta_z) - delta_y);
- p2.x=camera.zoom * (delta_x * MAGIC(delta_z) - delta_x);
- return p2;
-}
void draw_c3_line(c3_t p1,c3_t p2) {
// if(!between_angles(points_to_angle((c2_t){camera.p.x,camera.p.z},(c2_t){p1.x,p1.z}),0,90) ||
// !between_angles(points_to_angle((c2_t){camera.p.x,camera.p.z},(c2_t){p2.x,p2.z}),0,90)) return;
if(gra_global.drawminimap == 1) {
- draw_c2_line((c2_t){(camera.p.x-2)*global.mmz,(camera.p.z+2)*global.mmz},(c2_t){(camera.p.x+2)*global.mmz,(camera.p.z-2)*global.mmz});
- draw_c2_line((c2_t){(camera.p.x+2)*global.mmz,(camera.p.z+2)*global.mmz},(c2_t){(camera.p.x-2)*global.mmz,(camera.p.z-2)*global.mmz});
+ draw_c2_line((c2_t){(global.camera.p.x-2)*global.mmz,(global.camera.p.z+2)*global.mmz},(c2_t){(global.camera.p.x+2)*global.mmz,(global.camera.p.z-2)*global.mmz});
+ draw_c2_line((c2_t){(global.camera.p.x+2)*global.mmz,(global.camera.p.z+2)*global.mmz},(c2_t){(global.camera.p.x-2)*global.mmz,(global.camera.p.z-2)*global.mmz});
draw_c2_line((c2_t){p1.x*global.mmz,p1.z*global.mmz},(c2_t){p2.x*global.mmz,p2.z*global.mmz});
}
if(gra_global.drawminimap == 2) {//map rotates.
- c3_t t1=rotate_c3_yr(p1,camera.p,d2r(camera.r.y));
- c3_t t2=rotate_c3_yr(p2,camera.p,d2r(camera.r.y));
+ c3_t t1=rotate_c3_yr(p1,global.camera.p,d2r(global.camera.r.y));
+ c3_t t2=rotate_c3_yr(p2,global.camera.p,d2r(global.camera.r.y));
draw_c2_line((c2_t){t1.x*global.mmz,t1.z*global.mmz},(c2_t){t2.x*global.mmz,t2.z*global.mmz});
}
if(gra_global.draw3d != 0) draw_c2_line(c3_to_c2(p1),c3_to_c2(p2));
@@ -251,13 +249,18 @@ real shitdist2(c3_t p1,c3_t p2) {
((p1.z - p2.z) * (p1.z - p2.z)));
}
-real shitdist(struct c3_shape *s,c3_t p) {
-// apply rotation then find distance?
+real shitdist(struct c3_shape *s,c3_t p) {//this function is a killer. :/
int i;
real total=0;
for(i=0;i< s->len+(s->len==1);i++) {
-// total=total+shitdist2(rotate_c3_yr(s->p[i],(c3_t){0,0,0},d2r(camera.yr)),camera.p);
- total=total+shitdist2(rotate_c3_yr(s->p[i],camera.p,d2r(camera.r.y)),camera.p);
+ c3_group_rot_t *gr=get_group_rotation(s->id);
+ total=total+shitdist2(
+ rotate_c3_yr(//we're rotating the point around the camera...
+ gr?
+ c3_add(gr->p,rotate_c3_yr(s->p[i],gr->p,d2r(gr->r.y)))://after applying the rotation of the group it is in.
+ s->p[i],global.camera.p
+ ,d2r(global.camera.r.y))
+ ,global.camera.p);
}
return (total) / (real)(s->len+(s->len==1));
}
@@ -289,14 +292,9 @@ void HatchLines(c2_t p1,c2_t p2,c2_t p3,int density) {
//black out the rest of the triangle first?
//sounds alright to me...
-void draw_c2_text(c2_t p,char *text) {
- cs_t p2=c2_to_cs(p);
- draw_cs_text(p2,text);
-}
-
void draw_c3_text(c3_t p,char *text) {
- cs_t p2=c3_to_cs(p);
- draw_cs_text(p2,text);
+ c2_t p2=c3_to_c2(p);
+ draw_c2_text(p2,text);
}
/*
@@ -342,20 +340,20 @@ void draw_screen() {
char tmp[256];
zsort_t zs[SHAPES];
clear_backbuffer();
- real oldx=camera.p.x;
- real oldz=camera.p.z;
+ real oldx=global.camera.p.x;
+ real oldz=global.camera.p.z;
for(i=0;global.shape[i];i++) zs[i].s=global.shape[i];
- for(i=0;global.shape[i];i++) zs[i].d=shitdist(zs[i].s,camera.p);
- qsort(&zs,i,sizeof(zs[0]),(__compar_fn_t)compar);//sort these zs structs based on d.
+ for(i=0;global.shape[i];i++) zs[i].d=shitdist(zs[i].s,global.camera.p);
+ qsort(&zs,i,sizeof(zs[0]),(__compar_fn_t)compar);//sort these zs structs based on d. farthest first.
if(i > 0 && zs[i-1].s) strcpy(global.selected_object,zs[i-1].s->id);
if(gra_global.split_screen > 1) {
//oh... this will need to be a couple more lines
- radians tmprad=d2r((degrees){camera.r.y.d+180});
- radians tmprad2=d2r((degrees){camera.r.y.d+180});
- camera.p.z-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*cosl( tmprad.r ));
- camera.p.x-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*sinl( tmprad2.r ));
+ radians tmprad=d2r((degrees){global.camera.r.y.d+180});
+ radians tmprad2=d2r((degrees){global.camera.r.y.d+180});
+ global.camera.p.z-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*cosl( tmprad.r ));
+ global.camera.p.x-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*sinl( tmprad2.r ));
}
for(cn=0;cn<gra_global.split_screen;cn++) {
set_color();//restart each draw with the default color.
@@ -386,15 +384,17 @@ void draw_screen() {
gra_global.fps=0;
}
//XSetForeground(global.dpy, global.backgc, global.green.pixel);
- if(global.debug) {
+ if(global.debug) {//the way I have text done won't scale...
+/* draw_c2_text((cs_t){0,0},global.user);
snprintf(tmp,sizeof(tmp)-1,"debug: %s minimap: %d 3d: %d fps: %d shapes: %d",global.debug?"on":"off",gra_global.drawminimap,gra_global.draw3d,gra_global.oldfps,global.shapes);
- draw_cs_text((cs_t){gra_global.xoff,(gra_global.height/2)+10},tmp);
+ draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+10},tmp);
snprintf(tmp,sizeof(tmp)-1,"x: %d y: %d",gra_global.mousex,gra_global.mousey);
- draw_cs_text((cs_t){gra_global.xoff,(gra_global.height/2)+20},tmp);
- snprintf(tmp,sizeof(tmp)-1,"cx: %Lf cy: %Lf cz: %Lf",camera.p.x,camera.p.y,camera.p.z);
- draw_cs_text((cs_t){gra_global.xoff,(gra_global.height/2)+30},tmp);
- snprintf(tmp,sizeof(tmp)-1,"xr: %d yr: %d zr: %d",camera.r.x.d,camera.r.y.d,camera.r.z.d);
- draw_cs_text((cs_t){gra_global.xoff,(gra_global.height/2)+40},tmp);
+ draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+20},tmp);
+ snprintf(tmp,sizeof(tmp)-1,"cx: %Lf cy: %Lf cz: %Lf",global.camera.p.x,global.camera.p.y,global.camera.p.z);
+ draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+30},tmp);
+ snprintf(tmp,sizeof(tmp)-1,"xr: %d yr: %d zr: %d",global.camera.r.x.d,global.camera.r.y.d,global.camera.r.z.d);
+ draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+40},tmp);
+*/
}
// if(global.drawminimap) {//this isn't even useful I guess.
@@ -407,16 +407,19 @@ void draw_screen() {
// draw_c2_line((c2_t){10,10},(c2_t){-10,10});
// }
- for(i=0;global.shape[i];i++) {
- zs[i].d=shitdist(zs[i].s,camera.p);
- }
- qsort(&zs,i,sizeof(zs[0]),(__compar_fn_t)compar);//sort these zs structs based on d.
+ for(i=0;global.shape[i];i++) {
+ zs[i].d=shitdist(zs[i].s,global.camera.p);
+ }
+ qsort(&zs,i,sizeof(zs[0]),(__compar_fn_t)compar);//sort these zs structs based on d.
//draw all triangles
- if(global.debug) {
- snprintf(tmp,sizeof(tmp)-1,"selected object: %s",global.selected_object);
- draw_cs_text((cs_t){gra_global.xoff,(gra_global.height/2)+50},tmp);
- }
- for(i=0;global.shape[i];i++) {
+ if(global.debug) {
+ snprintf(tmp,sizeof(tmp)-1,"selected object: %s",global.selected_object);
+ draw_c2_text((c2_t){gra_global.xoff,(gra_global.height/2)+50},tmp);
+ }
+ //i already equals the length of the array.
+ i-=gra_global.maxshapes;
+ if(i<0) i=0;
+ for(;global.shape[i];i++) {
//now we pick the color of this triangle!
if(gra_global.red_and_blue) {
if(cn%2==0) {
@@ -439,12 +442,11 @@ void draw_screen() {
//}
}
// XSetForeground(global.dpy, global.backgc, global.green.pixel);
- radians tmprad=d2r((degrees){camera.r.y.d+180});
- radians tmprad2=d2r((degrees){camera.r.y.d+180});
- camera.p.z+=(gra_global.split_flip)*(gra_global.split*cosl( tmprad.r ));
- camera.p.x+=(gra_global.split_flip)*(gra_global.split*sinl( tmprad2.r ));
+ radians tmprad=d2r((degrees){global.camera.r.y.d+180});
+ radians tmprad2=d2r((degrees){global.camera.r.y.d+180});
+ global.camera.p.z+=(gra_global.split_flip)*(gra_global.split*cosl( tmprad.r ));
+ global.camera.p.x+=(gra_global.split_flip)*(gra_global.split*sinl( tmprad2.r ));
}
-
//TODO: figure out what all this shit is and either update or remove.
//DONT USE WIDTH for shit.
/*
@@ -474,7 +476,40 @@ void draw_screen() {
y2=nextY(x1,y1,d2r(camera.yr-90),c);
XDrawLine(global.dpy,w,gc,x1,y1,x2,y2);
*/
- camera.p.x = oldx;
- camera.p.z = oldz; //-= cn*CAMERA_SEPARATION;
+ global.camera.p.x = oldx;
+ global.camera.p.z = oldz; //-= cn*CAMERA_SEPARATION;
flipscreen();
}
+
+int graphics_init() {
+
+ global.zoom=30.0l;
+ global.camera.r.x.d=270;
+ global.camera.r.y.d=90;
+ global.camera.r.z.d=0;
+ global.mmz=1;
+ global.camera.p.x=0;
+ global.camera.p.z=-6;
+ global.camera.p.y=5;
+
+ gra_global.split_screen=SPLIT_SCREEN;
+ gra_global.split_flip=-1;
+ gra_global.split=CAMERA_SEPARATION;
+ gra_global.maxshapes=MAXSHAPES;
+ gra_global.red_and_blue=RED_AND_BLUE;
+ gra_global.greyscale=1;
+ gra_global.zsort=1;
+ if(gra_global.red_and_blue) {
+ gra_global.width=WIDTH;
+ } else {
+ gra_global.width=WIDTH*gra_global.split_screen;
+ }
+ gra_global.height=HEIGHT;
+ gra_global.mapxoff=gra_global.width/2;
+ gra_global.mapyoff=gra_global.height/2;
+ gra_global.drawminimap=DEFAULT_MINIMAP;
+ gra_global.draw3d=1;
+ gra_global.force_redraw=FORCE_REDRAW;
+ graphics_sub_init();
+ return 0;//we're fine
+}
diff --git a/src/graphics.h b/src/graphics_c3.h
index eadaa54..b6e1a5a 100644
--- a/src/graphics.h
+++ b/src/graphics_c3.h
@@ -29,6 +29,7 @@ struct gra_global {
int rmousex;
int rmousey;
int buttonpressed;
+ int maxshapes;
};
typedef struct {
@@ -37,6 +38,7 @@ typedef struct {
} zsort_t;
int graphics_init();
+int graphics_sub_init();
int graphics_event_handler();
void draw_screen();
void set_aspect_ratio();
diff --git a/src/graphics_backend.h b/src/graphics_cs.h
index 1f88ec6..b5e02fb 100644
--- a/src/graphics_backend.h
+++ b/src/graphics_cs.h
@@ -1,5 +1,7 @@
-#ifndef _HACKVR_GRAPHICS_BACKEND_H_
-#define _HACKVR_GRAPHICS_BACKEND_H_
+#ifndef _HACKVR_GRAPHICS_CS_H_
+#define _HACKVR_GRAPHICS_CS_H_
+
+#include "math.h"
//these are just the functions that all backends need to implement to work with hackvr.
//the list of functions are subject to change.
@@ -15,7 +17,7 @@ void set_color();
void set_color_red();
void set_color_blue();
void clear_backbuffer();
-int keypress_handler(int sym);
+void keypress_handler(unsigned char sym,int x,int y);
int graphics_init();
int graphics_event_handler();
void set_clipping_rectangle(int x,int y,int width,int height);
diff --git a/src/graphics_cs_opengl.c b/src/graphics_cs_opengl.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/graphics_cs_opengl.c
diff --git a/src/graphics_x11.c b/src/graphics_cs_x11.c
index 31a78e4..ab80368 100644
--- a/src/graphics_x11.c
+++ b/src/graphics_cs_x11.c
@@ -18,9 +18,9 @@
#include "config.h"
#include "common.h"
-#include "graphics.h"
+#include "graphics_c3.h"//not needed?
#include "graphics_x11.h"
-#include "graphics_backend.h"
+#include "graphics_cs.h"
//typedef float real; //think this conflicts?
@@ -135,7 +135,7 @@ void red_and_blue_magic() {
}
//void draw_sky() {
-// XCopyArea(x11_global.dpy,skypixmap,x11_global.backbuffer,x11_global.backgc,((camera.yr.d*5)+SKYW)%SKYW,0,WIDTH,gra_global.height/2,0,0);
+// XCopyArea(x11_global.dpy,skypixmap,x11_global.backbuffer,x11_global.backgc,((global.camera.yr.d*5)+SKYW)%SKYW,0,WIDTH,gra_global.height/2,0,0);
//}
void set_color() {
@@ -164,7 +164,7 @@ void set_aspect_ratio() {
XSetWMNormalHints(x11_global.dpy,x11_global.w,hints);
}
-int keypress_handler(int sym) {
+void x11_keypress_handler(int sym,int x,int y) {
char line[1024];
radians tmprad;
radians tmprad2;
@@ -177,78 +177,68 @@ int keypress_handler(int sym) {
selfcommand(line);
break;
case XK_Up:
- tmprad=d2r((degrees){camera.r.y.d+90});
- tmprad2=d2r((degrees){camera.r.y.d+90});
+ tmprad=d2r((degrees){global.camera.r.y.d+90});
+ tmprad2=d2r((degrees){global.camera.r.y.d+90});
tmpx=WALK_SPEED*sinl(tmprad.r);
tmpz=WALK_SPEED*cosl(tmprad2.r);
- camera.p.x+=tmpx;
- camera.p.z+=tmpz;
- snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,tmpx,tmpz);
+ snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,-tmpx,tmpz);
selfcommand(line);
break;
case XK_Down:
- tmprad=d2r((degrees){camera.r.y.d+270});
- tmprad2=d2r((degrees){camera.r.y.d+270});
+ tmprad=d2r((degrees){global.camera.r.y.d+270});
+ tmprad2=d2r((degrees){global.camera.r.y.d+270});
tmpx=WALK_SPEED*sinl(tmprad.r);
tmpz=WALK_SPEED*cosl(tmprad2.r);
- camera.p.x+=tmpx;
- camera.p.z+=tmpz;
- snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,tmpx,tmpz);
+ snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,-tmpx,tmpz);
selfcommand(line);
break;
case XK_Left:
- tmprad=d2r(camera.r.y);
- tmprad2=d2r(camera.r.y);
+ tmprad=d2r(global.camera.r.y);
+ tmprad2=d2r(global.camera.r.y);
tmpx=WALK_SPEED*sinl(tmprad.r);
tmpz=WALK_SPEED*cosl(tmprad2.r);
- camera.p.x+=tmpx;
- camera.p.z+=tmpz;
- snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,tmpx,tmpz);
+ snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,-tmpx,tmpz);
selfcommand(line);
break;
case XK_Right:
- tmprad=d2r((degrees){camera.r.y.d+180});
- tmprad2=d2r((degrees){camera.r.y.d+180});
+ tmprad=d2r((degrees){global.camera.r.y.d+180});
+ tmprad2=d2r((degrees){global.camera.r.y.d+180});
tmpx=WALK_SPEED*sinl(tmprad.r);
tmpz=WALK_SPEED*cosl(tmprad2.r);
- camera.p.x+=tmpx;
- camera.p.z+=tmpz;
- snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,tmpx,tmpz);
+ snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,-tmpx,tmpz);
selfcommand(line);
break;
case XK_w:
- camera.p.y+=1;
snprintf(line,sizeof(line)-1,"%s move 0 1 0 0 0 0 0 0 0\n",global.user);
selfcommand(line);
break;
case XK_s:
- camera.p.y-=1;
snprintf(line,sizeof(line)-1,"%s move 0 -1 0 0 0 0 0 0 0\n",global.user);
selfcommand(line);
break;
case XK_r:
- camera.r.x.d+=5;
- while(camera.r.x.d > 360) camera.r.x.d-=360;
+ snprintf(line,sizeof(line)-1,"%s rotate %d 0 0\n",global.user,global.camera.r.x.d+5);
+ selfcommand(line);
break;
case XK_y:
- camera.r.x.d-=5;
- while(camera.r.x.d < 0) camera.r.x.d+=360;
+ snprintf(line,sizeof(line)-1,"%s rotate %d 0 0\n",global.user,global.camera.r.x.d-5);
+ selfcommand(line);
break;
case XK_q:
- camera.r.y.d+=5;
- while(camera.r.y.d > 360) camera.r.y.d-=360;
+ snprintf(line,sizeof(line)-1,"%s rotate 0 %d 0\n",global.user,global.camera.r.y.d+5);
+ selfcommand(line);
break;
case XK_e:
- camera.r.y.d-=5;
- while(camera.r.y.d < 0) camera.r.y.d+=360;
+ snprintf(line,sizeof(line)-1,"%s rotate 0 %d 0\n",global.user,global.camera.r.y.d-5);
+ selfcommand(line);
break;
case XK_u:
- camera.r.z.d+=5;
- while(camera.r.z.d > 360) camera.r.z.d-=360;
+ snprintf(line,sizeof(line)-1,"%s rotate 0 0 %d\n",global.user,global.camera.r.z.d+5);
+ selfcommand(line);
break;
case XK_o:
- camera.r.z.d-=5;
- while(camera.r.z.d < 0) camera.r.z.d+=360;
+ snprintf(line,sizeof(line)-1,"%s rotate 0 0 %d\n",global.user,global.camera.r.z.d-5);
+ selfcommand(line);
break;
case XK_p:
gra_global.split+=.1;
@@ -256,12 +246,14 @@ int keypress_handler(int sym) {
case XK_l:
gra_global.split-=.1;
break;
- case XK_z: camera.zoom+=1; break;
- case XK_x: camera.zoom-=1; break;
+ case XK_z: global.zoom+=1; break;
+ case XK_x: global.zoom-=1; break;
case XK_c: global.mmz*=1.1; break;
case XK_v: global.mmz/=1.1; break;
case XK_h: global.split+=1; break;
case XK_j: global.split-=1; break;
+ case XK_6: gra_global.maxshapes+=10; break;
+ case XK_7: gra_global.maxshapes-=10; break;
case XK_d:
global.debug ^= 1;
break;
@@ -280,16 +272,14 @@ int keypress_handler(int sym) {
gra_global.draw3d %= 4;
break;
case XK_Escape:
- return -1;
+ exit(0);
default:
- return 0;
break;
}
- return 1;
}
#endif
-int graphics_init() {
+int graphics_sub_init() {
int i;
char tmp[64];
Cursor cursor;
@@ -310,11 +300,7 @@ int graphics_init() {
}
printf("# done.\n");
assert(x11_global.dpy);
- gra_global.split_screen=SPLIT_SCREEN;
- gra_global.split_flip=-1;
- gra_global.split=CAMERA_SEPARATION;
x11_global.root_window=0;
- gra_global.red_and_blue=RED_AND_BLUE;
//global.colors[0]=BlackPixel(x11_global.dpy,DefaultScreen(x11_global.dpy));
// int whiteColor = //WhitePixel(x11_global.dpy, DefaultScreen(x11_global.dpy));
attributes.background_pixel=x11_global.colors[0].pixel;
@@ -328,18 +314,11 @@ int graphics_init() {
}
XMapWindow(x11_global.dpy,x11_global.w);
XStoreName(x11_global.dpy,x11_global.w,"hackvr");
- gra_global.greyscale=1;
- gra_global.zsort=1;
global.shape[0]=0;//we'll allocate as we need more.
+ global.camera.id=global.user;
+ global.group_rot[0]=&global.camera;
+ global.group_rot[1]=0;
x11_global.gc=XCreateGC(x11_global.dpy,x11_global.w, 0, 0);
-
- if(gra_global.red_and_blue) {
- gra_global.width=WIDTH;
- } else {
- gra_global.width=WIDTH*gra_global.split_screen;
- }
- gra_global.height=HEIGHT;
-
x11_global.backbuffer=XCreatePixmap(x11_global.dpy,x11_global.w,gra_global.width,gra_global.height,DefaultDepth(x11_global.dpy,DefaultScreen(x11_global.dpy)));
x11_global.cleanbackbuffer=XCreatePixmap(x11_global.dpy,x11_global.w,gra_global.width,gra_global.height,DefaultDepth(x11_global.dpy,DefaultScreen(x11_global.dpy)));
@@ -380,22 +359,8 @@ int graphics_init() {
}
printf("done.\n");
*/
- gra_global.mapxoff=gra_global.width/2;
- gra_global.mapyoff=gra_global.height/2;
- gra_global.drawminimap=DEFAULT_MINIMAP;
- gra_global.draw3d=1;
- gra_global.force_redraw=FORCE_REDRAW;//use this for checking proper fps I guess.
-//this should be in graphics.c ?
- camera.zoom=30.0l;
- camera.r.x.d=270;
- camera.r.y.d=90;
- camera.r.z.d=0;
- global.mmz=1;
- camera.p.x=0;
- camera.p.z=-6;
- camera.p.y=5;
- return 0;
+ return 0;//we're fine
}
int graphics_event_handler() {
@@ -447,10 +412,7 @@ int graphics_event_handler() {
case KeyPress:
if(global.debug >= 2) printf("# KeyPress\n");
redraw=1;
- if(keypress_handler(XLookupKeysym(&e.xkey,0)) == -1) {
- printf("# exiting\n");
- return -1;
- }
+ x11_keypress_handler(XLookupKeysym(&e.xkey,0),gra_global.mousex,gra_global.mousey);
break;
default:
// printf("# received unknown event with type: %d\n",e.type);
diff --git a/src/graphics_opengl.c b/src/graphics_opengl.c
deleted file mode 100644
index 5d2e600..0000000
--- a/src/graphics_opengl.c
+++ /dev/null
@@ -1,151 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <GL/glut.h>
-#include <GL/freeglut_ext.h>
-
-#include "common.h"
-
-GLenum doubleBuffer;
-GLubyte ubImage[65536];
-
-void set_aspect_ratio(int w,int h) {
- glViewport(0,0,w,h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0,w,0,h,-1,1);
-// glScalef(1,-1,1);
-// glTranslatef(0,-h,0);
-}
-
-void set_color_based_on_distance(real d) {
- //scale this color based on distance... closer is lighter.
-// float g;
-// g=d/100.0
- glColor3f(0.0, 1.0, 0.0);
-}
-
-void set_clipping_rectangle(int x,int y,int w,int h) {
-
-}
-
-void draw_cs_line(cs_t p1,cs_t p2) {
- glBegin(GL_LINES);
- glColor3f(0.0, 1.0, 0.0);
- glVertex2i(p1.x,p1.y);
- glVertex2i(p2.x,p2.y);
- glEnd();
-}
-
-void draw_cs_text() {
-
-}
-
-void draw_cs_shape(cs_s_t s) {
- int i;
- for(i=0;i<s.len+(s.len==1);i++) {//this shape is closed!
- draw_cs_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]);
- }
-/* glBegin(GL_LINE_STRIP);
- glColor3f(0.0, 1.0, 0.0);
- for(i=0;i<s.len+(s.len==1);i++) {
- glVertex2i(s.p[i].x,s.p[i].y);
- }
- glEnd();
-*/
-}
-
-void draw_cs_filled_shape(cs_s_t s) {
- draw_cs_shape(s);
-// glBegin(GL_POLYGON);
-// glVertex2s();
-// glEnd();
-}
-
-void set_color() {
- glColor3f(0.0, 1.0, 0.0);
-}
-
-void set_color_red() {
- glColor3f(1.0, 0.0, 0.0);
-}
-
-void set_color_blue() {
- glColor3f(0.0, 0.0, 1.0);
-}
-
-void clear_backbuffer() {
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
-}
-
-void flipscreen() {
-// glutSwapBuffers();
- glFlush();
-}
-
-void red_and_blue_magic() {
-
-}
-
-void keypress_handler(unsigned char key, int x, int y) {
- switch (key) {
- case 27:
- exit(0);
- }
-}
-
-/* draw_screen is in graphics.c
-void draw_screen(void)
-{
-
-
-}*/
-
-
-/*void derp_screen() {
- glClear(GL_COLOR_BUFFER_BIT);
-
- draw_cs_line((cs_t){0,10},(cs_t){200,210});
-
-// clear_backbuffer();
-// set_color();
- flipscreen();
-}*/
-
-void graphics_init(void)
-{
-// GLenum type;
-
-// type = GLUT_RGB;
-// type |= GLUT_DOUBLE;
- int argc=0;
- char *argv[]={"derp",0};
- glutInit(&argc,argv);
-// glutInitDisplayMode(type);
- glutCreateWindow("hackvr opengl and glut testing");
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0, 1.0, 0.1, 1000.0);
- glMatrixMode(GL_MODELVIEW);
- glDisable(GL_DITHER);
-
- glutKeyboardFunc(keypress_handler);
-// glutDisplayFunc(derp_screen);
- glutReshapeFunc(set_aspect_ratio);
-}
-
-
-void graphics_event_handler() {
- glutMainLoopEvent();
-}
-
-/*
-void main(int argc,char *argv[]) {
- graphics_init();
- while(1) {
- graphics_event_handler();
- }
-}
-*/
diff --git a/src/hackvr.c b/src/hackvr.c
index 6828f59..c8e3899 100644
--- a/src/hackvr.c
+++ b/src/hackvr.c
@@ -16,7 +16,7 @@
#include "common.h"
#include "math.h"
#ifdef GRAPHICAL
-#include "graphics.h"
+#include "graphics_c3.h"
extern struct gra_global gra_global;
#endif
@@ -210,13 +210,13 @@ int load_stdin() {
continue;
}
if(!strcmp(command,"dump")) {
- printf("%s set camera.p.x %Lf\n",global.user,camera.p.x);
- printf("%s set camera.p.y %Lf\n",global.user,camera.p.y);
- printf("%s set camera.p.z %Lf\n",global.user,camera.p.z);
- printf("%s set camera.r.x %d\n",global.user,camera.r.x.d);
- printf("%s set camera.r.y %d\n",global.user,camera.r.y.d);
- printf("%s set camera.r.z %d\n",global.user,camera.r.z.d);
- printf("%s set camera.zoom %Lf\n",global.user,camera.zoom);
+ printf("%s set global.camera.p.x %Lf\n",global.user,global.camera.p.x);
+ printf("%s set global.camera.p.y %Lf\n",global.user,global.camera.p.y);
+ printf("%s set global.camera.p.z %Lf\n",global.user,global.camera.p.z);
+ printf("%s set global.camera.r.x %d\n",global.user,global.camera.r.x.d);
+ printf("%s set global.camera.r.y %d\n",global.user,global.camera.r.y.d);
+ printf("%s set global.camera.r.z %d\n",global.user,global.camera.r.z.d);
+ printf("%s set global.zoom %Lf\n",global.user,global.zoom);
continue;
}
if(!strcmp(command,"quit")) {
@@ -227,13 +227,13 @@ int load_stdin() {
if(len == 4) {
if(0);
#ifdef GRAPHICAL
- else if(!strcmp(a[2],"camera.p.x")) camera.p.x=strtold(a[3],0);
- else if(!strcmp(a[2],"camera.p.y")) camera.p.y=strtold(a[3],0);
- else if(!strcmp(a[2],"camera.p.z")) camera.p.z=strtold(a[3],0);
- else if(!strcmp(a[2],"camera.zoom")) camera.zoom=strtold(a[3],0);
- else if(!strcmp(a[2],"camera.r.x")) camera.r.x.d=atoi(a[3]);
- else if(!strcmp(a[2],"camera.r.y")) camera.r.y.d=atoi(a[3]);
- else if(!strcmp(a[2],"camera.r.z")) camera.r.z.d=atoi(a[3]);
+ else if(!strcmp(a[2],"camera.p.x")) global.camera.p.x=strtold(a[3],0);
+ else if(!strcmp(a[2],"camera.p.y")) global.camera.p.y=strtold(a[3],0);
+ else if(!strcmp(a[2],"camera.p.z")) global.camera.p.z=strtold(a[3],0);
+ else if(!strcmp(a[2],"global.zoom")) global.zoom=strtold(a[3],0);
+ else if(!strcmp(a[2],"camera.r.x")) global.camera.r.x.d=atoi(a[3]);
+ else if(!strcmp(a[2],"camera.r.y")) global.camera.r.y.d=atoi(a[3]);
+ else if(!strcmp(a[2],"camera.r.z")) global.camera.r.z.d=atoi(a[3]);
#endif
else printf("# unknown variable: %s\n",a[2]);
continue;
@@ -246,12 +246,13 @@ int load_stdin() {
printf("# %s toggled!\n",a[2]);
continue;
}
- if(!strcmp(command,"addshape")) {
+ if(!strcmp(command,"addshape")) {//need to add a grouprot with this.
if(len > 3) {
if(len != ((strtold(a[2],0)+(strtold(a[2],0)==1))*3)+3) {
printf("# ERROR: wrong amount of parts for addshape. got: %d expected %d\n",len,((int)strtold(a[2],0)+(strtold(a[2],0)==1))*3+3);
continue;
}
+ for(i=0;global.shape[i];i++);//just take me to the end.
global.shape[i]=malloc(sizeof(struct c3_shape));
global.shape[i]->len=strtold(a[2],0);
global.shape[i]->id=strdup(id);
@@ -263,6 +264,23 @@ int load_stdin() {
i++;
global.shapes=i;
global.shape[i]=0;
+
+ for(i=0;global.group_rot[i];i++) {
+ if(!strcmp(global.group_rot[i]->id,id)) {
+ break;
+ }
+ }
+ if(global.group_rot[i] == 0) {//we have ourselves a new grouprot!
+ global.group_rot[i]=malloc(sizeof(c3_group_rot_t));
+ global.group_rot[i]->id=strdup(id);
+ global.group_rot[i+1]=0;
+ global.group_rot[i]->p.x=0;
+ global.group_rot[i]->p.y=0;
+ global.group_rot[i]->p.z=0;
+ global.group_rot[i]->r.x=(degrees){0};
+ global.group_rot[i]->r.y=(degrees){0};
+ global.group_rot[i]->r.z=(degrees){0};
+ }
}
continue;
}
@@ -293,37 +311,50 @@ int load_stdin() {
}
continue;
}
- if(!strcmp(command,"rotate")) {//this probably won't be needed with the new rotation structs per group.
+ if(!strcmp(command,"rotate")) {
if(len > 4) {
- for(i=0;global.shape[i];i++) {
- if(!strcmp(global.shape[i]->id,id)) {
- for(j=0;j < global.shape[i]->len+(global.shape[i]->len==1);j++) {
- radians tmprad=points_to_angle((c2_t){global.shape[i]->p[j].x,global.shape[i]->p[j].z},(c2_t){0,0});
- radians tmprad2=d2r((degrees){atoi(a[2])});
- global.shape[i]->p[j]=rotate_c3_yr(global.shape[i]->p[j],(c3_t){0,0,0},(radians){tmprad.r+tmprad2.r});
- //global.shape[i]->p[j]=rotate_c3_yr(global.shape[i]->p[j],(c3_t){0,0,0},d2r(atoi(a[3])));
- //global.shape[i]->p[j]=rotate_c3_zr(global.shape[i]->p[j],(c3_t){0,0,0},d2r(atoi(a[4])));
- }
+ for(i=0;global.group_rot[i];i++) {
+ if(!strcmp(global.group_rot[i]->id,id)) {
+ break;
}
}
+ if(global.group_rot[i] == 0) {//we have ourselves a new grouprot!
+ global.group_rot[i]=malloc(sizeof(c3_group_rot_t));
+ global.group_rot[i]->id=strdup(id);
+ global.group_rot[i+1]=0;
+ global.group_rot[i]->p.x=0;//only set these if new.
+ global.group_rot[i]->p.y=0;
+ global.group_rot[i]->p.z=0;
+ }
+ global.group_rot[i]->r.x=(degrees){atoi(a[2])};
+ global.group_rot[i]->r.y=(degrees){atoi(a[3])};
+ global.group_rot[i]->r.z=(degrees){atoi(a[4])};
}
+ continue;
}
if(!strcmp(command,"move")) {
if(len > 4) {
- for(i=0;global.shape[i];i++) {
- if(!strcmp(global.shape[i]->id,id)) {
- for(j=0;j < global.shape[i]->len+(global.shape[i]->len==1);j++) {
- global.shape[i]->p[j].x+=strtold(a[2],0);
- global.shape[i]->p[j].y+=strtold(a[3],0);
- global.shape[i]->p[j].z+=strtold(a[4],0);
- }
+ for(i=0;global.group_rot[i];i++) {
+ if(!strcmp(global.group_rot[i]->id,id)) {
+ break;
}
}
+ if(global.group_rot[i] == 0) {//we have ourselves a new grouprot!
+ global.group_rot[i]=malloc(sizeof(c3_group_rot_t));
+ global.group_rot[i]->id=strdup(id);
+ global.group_rot[i+1]=0;
+ global.group_rot[i]->r.x=(degrees){0};//only set these if new.
+ global.group_rot[i]->r.y=(degrees){0};
+ global.group_rot[i]->r.z=(degrees){0};
+ }
+ global.group_rot[i]->p.x+=strtold(a[2],0);
+ global.group_rot[i]->p.y+=strtold(a[3],0);
+ global.group_rot[i]->p.z+=strtold(a[4],0);
}
else {
printf("# ERROR: wrong amount of parts for move. got: %d expected: 11\n",len);
}
- continue;//???
+ continue;
}
printf("# I don't know what command you're talking about. %s\n",command);
free(line);
@@ -363,9 +394,10 @@ int main(int argc,char *argv[]) {
if((redraw=graphics_event_handler()) == -1) {
return 0;
}
- if((redraw || gra_global.force_redraw) && !global.headless) {
- draw_screen();
- }
+// printf("redraw=%d gra_global.force_redraw=%d global.headless=%d\n",redraw,gra_global.force_redraw,global.headless);
+ //if((redraw || gra_global.force_redraw) && !global.headless) {
+ // draw_screen();
+ //}
#endif
switch(load_stdin()) {
case -1:
diff --git a/src/math.c b/src/math.c
index 0f74f3d..b5c82de 100644
--- a/src/math.c
+++ b/src/math.c
@@ -1,6 +1,19 @@
+#include <string.h>
+#include "common.h"
#include "math.h"
-//should these use the radians struct?
+extern struct global global;
+
+//might change this to use hashtables for faster lookups.
+c3_group_rot_t *get_group_rotation(char *id) {
+ int i;
+ for(i=0;global.group_rot[i];i++) {
+ if(!strcmp(global.group_rot[i]->id,id)) {
+ return global.group_rot[i];
+ }
+ }
+ return 0;//need to be sure to check return value for this function!
+}
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)
c2_t tmp;
diff --git a/src/math.h b/src/math.h
index dac2409..f369082 100644
--- a/src/math.h
+++ b/src/math.h
@@ -12,6 +12,7 @@ c2_t rotate_c2(c2_t p1,c2_t p2,radians dr);
c3_t rotate_c3_xr(c3_t p1,c3_t p2,radians xr);
c3_t rotate_c3_yr(c3_t p1,c3_t p2,radians yr);
c3_t rotate_c3_zr(c3_t p1,c3_t p2,radians zr);
+c3_group_rot_t *get_group_rotation(char *id);
radians d2r(degrees d);
radians points_to_angle(c2_t p1,c2_t p2);
diff --git a/src/testit.sh b/src/testit.sh
index 86aca19..ceb7698 100755
--- a/src/testit.sh
+++ b/src/testit.sh
@@ -3,5 +3,5 @@ cat <(sort -R ../meshes/female_basemesh1_2.hackvr) \
<(echo "woman move 10 0 -50") \
<(sort -R ../meshes/female_basemesh1_2.hackvr | sed 's/woman/woman2/g') \
<(echo "woman2 move -10 0 -200") \
- <(sort -R ../meshes/female_basemesh1_2.hackvr | sed 's/woman/woamn3/g') | ./slowcat 10000 | ./hackvr $USER
-#../tools/obj2hackvr.pl woman ../meshes/female_basemesh1_2.obj | ./hackvr epoch
+ <(sort -R ../meshes/female_basemesh1_2.hackvr | sed 's/woman/woamn3/g') | ./slowcat 10000 | ./hackvr_opengl $USER
+#../tools/obj2hackvr.pl woman ../meshes/female_basemesh1_2.obj | ./hackvr_opengl epoch