summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2020-03-07 05:31:38 -0600
committerepoch <epoch@hacking.allowed.org>2020-03-07 05:31:38 -0600
commitcedfda9327b862a03fcf2090ee6763db6040eebb (patch)
tree551cd5969b4232e8177568372757470a516c49b1 /src
parent129e70d0f557031c48dfb4ea0b8c5c0ea603a250 (diff)
downloadhackvr-cedfda9327b862a03fcf2090ee6763db6040eebb.tar.gz
hackvr-cedfda9327b862a03fcf2090ee6763db6040eebb.zip
moved the group_rotation based transformations into a function in math.c so I could reuse it for the new "flatten" command.
Diffstat (limited to 'src')
-rw-r--r--src/graphics_c3.c44
-rw-r--r--src/graphics_c3.h1
-rw-r--r--src/math.c61
3 files changed, 70 insertions, 36 deletions
diff --git a/src/graphics_c3.c b/src/graphics_c3.c
index 534863c..3240058 100644
--- a/src/graphics_c3.c
+++ b/src/graphics_c3.c
@@ -41,9 +41,6 @@ real distance2(c2_t p1,c2_t p2) {
return sqrt(( (p1.x-p2.x)*(p1.x-p2.x) )+( (p1.y-p2.y)*(p1.y-p2.y) ));
}
*/
-real distance3(c3_t p1,c3_t p2) {
- return sqrt(( (p1.x-p2.x)*(p1.x-p2.x) )+( (p1.y-p2.y)*(p1.y-p2.y) )+( (p1.z-p2.z)*(p1.z-p2.z) ));
-}
/* moved to math.c
int between_angles(degrees d,real lower,real upper) {
@@ -124,10 +121,6 @@ int get_2D_intersection_Y(x,y,d,x,z,d) {
}
*/
-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};
}
@@ -197,40 +190,17 @@ void draw_c3_shape(c3_s_t s) {//outlined. needs to be filled? //draw minimap shi
c3_s_t s2;//post rotation
c2_s_t s3;//post projection
radians r;
- s2.id=s.id;//it shouldn't disappear and we shouldn't need to make a copy.
- s2.len=s.len;
s3.id=s.id;
s3.len=s.len;
- c3_group_rot_t *gr=get_group_relative(s.id);
- if(s.len > 1) {
- for(i=0;i<s.len+(s.len==1);i++) {//apply the group's rotation and store in s2.
- if(!strcmp(s.id,global.user)) {//we need to rotate camera objects (an avatar maybe) only along the y axis, and in the opposite direction than everything else rotates
- s2.p[i]=c3_add(gr->p,rotate_c3_yr(s.p[i],(c3_t){0,0,0},d2r((degrees){0-(gr->r.y.d)})));
- } else {
- if(gr) {
- //s2.p[i]=c3_add(gr->p,rotate_c3_yr(s.p[i],gr->p,d2r(gr->r.y)));
- s2.p[i]=c3_add(gr->p,rotate_c3_xr(
- rotate_c3_yr(
- rotate_c3_zr(s.p[i],(c3_t){0,0,0},d2r(gr->r.z)
- ),(c3_t){0,0,0},d2r(gr->r.y)
- ),(c3_t){0,0,0},d2r(gr->r.x)
- )
- );
- } else {
- s2.p[i]=s.p[i];
- }
- }
- }
- }
- if(s.len == 1) {
- real dist=distance3(s.p[0],s.p[1]);
- s2.p[0]=s.p[0];
- s2.p[1]=c3_add(s.p[0],(c3_t){dist,0,0});
- }
+
+ //c3_group_rot_t gr=get_group_relative(s.id);//it doesn't matter if I get it here or not, I'm not looping the next call.
+ //this function will get the group relative by itself if the argument is NULL
+ s2=apply_group_relative(s,NULL);//math.c
+
//all s2 needs to bet set before this loop.
for(i=0;i<s.len+(s.len==1);i++) {//
r=points_to_angle((c2_t){global.camera.p.x,global.camera.p.z},(c2_t){s2.p[i].x,s2.p[i].z});
- if(between_angles(r2d(r),(360-global.camera.r.y.d-45+360+90)%360,(360-global.camera.r.y.d+45+360+90)%360)) {
+ if(between_angles(r2d(r),(360-global.camera.r.y.d-(gra_global.fieldofview/2)+360+90)%360,(360-global.camera.r.y.d+(gra_global.fieldofview/2)+360+90)%360)) {
drawthefucker=1;//damn it. somewhere in this shape needs to be drawn.
}
}
@@ -532,6 +502,8 @@ int graphics_init() {
gra_global.red_and_blue=RED_AND_BLUE;
gra_global.greyscale=1;
gra_global.zsort=1;
+ gra_global.fieldofview=FIELDOFVIEW;//config.h
+
if(gra_global.red_and_blue) {
gra_global.width=WIDTH;
} else {
diff --git a/src/graphics_c3.h b/src/graphics_c3.h
index b609721..56d85b7 100644
--- a/src/graphics_c3.h
+++ b/src/graphics_c3.h
@@ -26,6 +26,7 @@ struct gra_global {
c2_t dragstart[10];//mouse coordinates where a drag was started
c3_rot_t oldcamera;
int maxshapes;
+ int fieldofview;
};
typedef struct {
diff --git a/src/math.c b/src/math.c
index 5ab69af..d05789d 100644
--- a/src/math.c
+++ b/src/math.c
@@ -1,4 +1,6 @@
+#include <stdio.h>
#include <string.h>
+
#include "common.h"
#include "math.h"
@@ -122,3 +124,62 @@ int point_inside_concave_shape(c2_t p1,c2_s_t s) {//hrm...
}
return 1;
}
+
+void print_point(c3_t p) {
+ printf("%lF %lF %lF\n",p.x,p.y,p.z);
+}
+
+c3_s_t apply_group_relative(c3_s_t s,c3_group_rot_t *group_rot) {
+ c3_s_t s2;
+ c3_group_rot_t *gr;
+ int i;
+ s2.len=s.len;
+ s2.id=s.id;
+ if(group_rot) {
+ gr=group_rot;
+ } else {
+ gr=get_group_relative(s.id);
+ }
+ if(!gr) { //shit. we have a shape but not relatives for it. oh well.
+ //printf("# no group relative.\n");
+ return s;
+ }
+ if(s.len < 1) {//wtf is wrong with this shape?
+ //printf("# wtf?\n");
+ return s;
+ }
+ if(s.len == 1) {//we're a circle. we /really/ have two points stored though.
+ real dist=distance3(s.p[0],s.p[1]);
+ s2.p[0]=s.p[0];
+ s2.p[1]=c3_add(s.p[0],(c3_t){dist,0,0});
+ }
+ if(s.len > 1) {//we're a polygon.
+ for(i=0;i<s.len+(s.len==1);i++) {//apply the group's rotation and store in s2.
+ if(!strcmp(s.id,global.user)) {//we need to rotate camera objects (an avatar maybe) only along the y axis, and in the opposite direction than everything else rotates
+ s2.p[i]=c3_add(gr->p,rotate_c3_yr(s.p[i],(c3_t){0,0,0},d2r((degrees){0-(gr->r.y.d)})));
+ } else {
+ if(gr) {
+ //s2.p[i]=c3_add(gr->p,rotate_c3_yr(s.p[i],gr->p,d2r(gr->r.y)));
+ s2.p[i]=c3_add(gr->p,rotate_c3_xr(
+ rotate_c3_yr(
+ rotate_c3_zr(s.p[i],(c3_t){0,0,0},d2r(gr->r.z)
+ ),(c3_t){0,0,0},d2r(gr->r.y)
+ ),(c3_t){0,0,0},d2r(gr->r.x)
+ )
+ );
+ } else {
+ s2.p[i]=s.p[i];
+ }
+ }
+ }
+ }
+ return s2;
+}
+
+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};
+}
+
+real distance3(c3_t p1,c3_t p2) {
+ return sqrt(( (p1.x-p2.x)*(p1.x-p2.x) )+( (p1.y-p2.y)*(p1.y-p2.y) )+( (p1.z-p2.z)*(p1.z-p2.z) ));
+}