jogi wants to see the current status, this prolly won't compile, but nothing autobuilds any of this stuff anyway

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3973 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2012-02-04 22:53:53 +00:00
parent c3e1d104d5
commit a722205543

View file

@ -1,44 +1,42 @@
typedef struct
{
int maxpoints;
int something;
int numpoints;
vector pos[64];
float totallength;
} spline_t;
typedef struct
{
int numsplines;
spline_t spline[64];
} splinedata_t;
static splinedata_t *splinedata;
float starttime;
float endtime;
float startfov;
float endfov;
spline_t view;
spline_t focus;
} cam_t;
typedef struct
{
int numcams;
int selcam;
int ver;
cam_t cam[64];
} camdata_t;
static camdata_t *camdata;
static var float splinefile = -1;
void() spline_init =
{
/*precache the shader*/
shaderforname("camsplineshader", "{\n{\nmap splinetexture.tga\nblendfunc blend\nrgbgen vertex\nalphagen vertex\n}\n}\n");
shaderforname("camsplineshader", "{\n{\nmap construction.tga\nblendfunc blend\nrgbgen vertex\nalphagen vertex\n}\n}\n");
splinefile = fopen("spline.dat", FILE_MMAP_RW, sizeof(splinedata_t));
splinefile = fopen("spline.dat", FILE_MMAP_RW, sizeof(camdata_t));
if (splinefile < 0)
{
/*too lazy to create a file, just use it as a malloc*/
splinefile = fopen("", FILE_MMAP_RW, sizeof(splinedata_t));
splinefile = fopen("", FILE_MMAP_RW, sizeof(camdata_t));
}
splinedata = (splinedata_t*)(fgets(splinefile));
print("Temp test code\n");
splinedata->numsplines = 1;
splinedata->spline[0].maxpoints = 4;
splinedata->spline[0].pos[0] = '-1024 -1024';
splinedata->spline[0].pos[1] = '+1024 -1024';
splinedata->spline[0].pos[2] = '+1024 +1024';
splinedata->spline[0].pos[3] = '-1024 +1024';
splinedata->spline[0].pos[4] = '-1024 +1024';
splinedata->spline[0].pos[5] = '+1024 +1024';
splinedata->spline[0].pos[6] = '+1024 -1024';
splinedata->spline[0].pos[7] = '-1024 -1024';
camdata = (camdata_t*)(fgets(splinefile));
};
void() spline_shutdown =
{
@ -46,38 +44,125 @@ void() spline_shutdown =
splinefile = -1;
};
/*called each frame*/
void(float attime) spline_overrides =
static void spline_calclength(spline_t *s)
{
local spline_t *spline;
/*find correct spline based upon time global*/
if (spline->something)
int i;
s->totallength = 0;
for (i = 0; i < s->numpoints - 1; i++)
{
// setviewprop(VF_ORIGIN, somepos);
// setviewprop(VF_ANGLE, someangle);
// setviewprop(VF_AFOV, 90);
s->totallength = s->totallength + vlen(s->pos[i] - s->pos[i+1]);
}
};
static vector(spline_t *s, float frac) spline_pos =
{
vector v1, v2;
frac *= s->numpoints;
if (frac < 0)
{
v1 = s->pos[0];
v2 = s->pos[1];
}
else if (frac >= s->numpoints)
{
v1 = s->pos[s->numpoints-2];
v2 = s->pos[s->numpoints-1];
frac -= s->numpoints;
}
else
{
v1 = s->pos[s->numpoints];
v2 = s->pos[s->numpoints+1];
frac = frac - (float)(int)frac;
}
return v1 * (1-frac) + v2 * frac;
};
static vector(spline_t *s, float frac) spline_dir =
{
return normalize(spline_pos(s, frac+0.001) - spline_pos(s, frac-0.001));
};
static vector(vector pos, vector dir, vector view) beamdir =
{
vector result;
view = normalize(view - pos);
//crossproduct view+dir
result_x = dir_y*view_z - dir_z*view_y;
result_y = dir_z*view_x - dir_x*view_z;
result_z = dir_x*view_y - dir_y*view_x;
return result;
};
static void(spline_t *s) spline_draw =
{
local float step, frac;
local vector pos, pos1, pos2, vpos;
local vector bdir;
/*example of drawing convex polygons*/
R_BeginPolygon("camsplineshader");
R_PolygonVertex(s->pos[0], '0 0', '1 1 1', 1);
R_PolygonVertex(s->pos[1], '1 0', '1 1 1', 1);
R_PolygonVertex(s->pos[2], '1 1', '1 1 1', 1);
R_PolygonVertex(s->pos[3], '0 1', '1 1 1', 1);
R_EndPolygon();
vpos = getviewprop(VF_ORIGIN);
/*do another with the same shader*/
R_PolygonVertex(s->pos[4], '0 0', '1 1 1', 1);
R_PolygonVertex(s->pos[5], '1 0', '1 1 1', 1);
R_PolygonVertex(s->pos[6], '1 1', '1 1 1', 1);
R_PolygonVertex(s->pos[7], '0 1', '1 1 1', 1);
R_EndPolygon();
/*calc the initial beam positions*/
pos = spline_pos(s, 0);
bdir = beamdir(pos, spline_dir(s, 0), vpos)*8;
pos1 = pos + bdir;
pos2 = pos - bdir;
for (frac = 0; frac < 1; )
{
frac += step;
if (frac > 1)
frac = 1;
pos = spline_pos(s, frac);
/*emit prior verts*/
R_PolygonVertex(pos1, '0 0', '1 1 1', 1);
R_PolygonVertex(pos2, '1 0', '1 1 1', 1);
/*calc intersitial beam position*/
pos2 = spline_dir(s, frac);
bdir = beamdir(pos, spline_dir(s, frac), vpos)*8;
pos1 = pos + bdir;
pos2 = pos - bdir;
/*emit current verts*/
R_PolygonVertex(pos2, '1 1', '1 1 1', 1);
R_PolygonVertex(pos1, '0 1', '1 1 1', 1);
R_EndPolygon();
}
};
/*called to move the view to some simulation time*/
void(float attime) spline_overrides =
{
local cam_t *cam;
local int i;
local vector src, dst;
local float frac;
/*find correct spline based upon time*/
for (i = 0; i < camdata->numcams; i++)
{
cam = &camdata->cam[i];
if (cam->starttime <= attime && cam->endtime > attime)
break;
}
/*give up if no matches*/
if (i == camdata->numcams)
return;
frac = (attime - cam->starttime) / (cam->endtime - cam->starttime);
src = spline_pos(&cam->view, frac);
dst = spline_pos(&cam->focus, frac);
setviewprop(VF_ORIGIN, src);
setviewprop(VF_ANGLES, vectoangles(dst - src));
setviewprop(VF_AFOV, (cam->startfov * (1-frac)) + (cam->endfov * frac));
};
void() editor_spline_add =
@ -88,8 +173,8 @@ void() editor_spline_add =
spline_init();
/*add visible splines to the scene*/
for (i = 0; i < splinedata->numsplines; i+=1i)
spline_draw(&splinedata->spline[i]);
for (i = 0; i < camdata->numcams; i+=1i)
spline_draw(&camdata->cam[i].view);
/*sort out the overrides*/
// spline_overrides(simtime);
@ -102,7 +187,7 @@ void(vector curmousepos) editor_spline_overlay =
/*draw menu*/
/*dunno if the light editor has any convienient code*/
drawrawstring('0 32 0', "crappy not-implemented menu", '8 8 0', '1 1 1', 1);
drawrawstring('0 32 0', sprintf("spline %i / %i", camdata->selcam, camdata->numcams), '8 8 0', '1 1 1', 1);
};
float(float keycode, float unicode, vector curmousepos) editor_spline_key
{