2011-12-17 16:37:07 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2012-02-04 22:53:53 +00:00
|
|
|
int numpoints;
|
2012-02-08 01:56:30 +00:00
|
|
|
int type;
|
2011-12-17 16:37:07 +00:00
|
|
|
vector pos[64];
|
2012-02-08 01:56:30 +00:00
|
|
|
float totallength;
|
|
|
|
vector color;
|
|
|
|
int selected_point;
|
|
|
|
float position;
|
2011-12-17 16:37:07 +00:00
|
|
|
} spline_t;
|
2012-02-04 22:53:53 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
float starttime;
|
|
|
|
float endtime;
|
|
|
|
float startfov;
|
|
|
|
float endfov;
|
2012-02-08 01:56:30 +00:00
|
|
|
spline_t spline;
|
2012-02-04 22:53:53 +00:00
|
|
|
} cam_t;
|
2012-02-08 01:56:30 +00:00
|
|
|
|
2011-12-17 16:37:07 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2012-02-04 22:53:53 +00:00
|
|
|
int ver;
|
2012-02-08 01:56:30 +00:00
|
|
|
int position_count;
|
|
|
|
int position_selected;
|
|
|
|
int view_count;
|
|
|
|
int view_selected;
|
|
|
|
cam_t position[64];
|
|
|
|
cam_t view[64];
|
2012-02-04 22:53:53 +00:00
|
|
|
} camdata_t;
|
2012-02-08 01:56:30 +00:00
|
|
|
|
2012-02-04 22:53:53 +00:00
|
|
|
static camdata_t *camdata;
|
2011-12-17 16:37:07 +00:00
|
|
|
static var float splinefile = -1;
|
|
|
|
|
|
|
|
void() spline_init =
|
|
|
|
{
|
|
|
|
/*precache the shader*/
|
2012-02-04 22:53:53 +00:00
|
|
|
shaderforname("camsplineshader", "{\n{\nmap construction.tga\nblendfunc blend\nrgbgen vertex\nalphagen vertex\n}\n}\n");
|
2011-12-17 16:37:07 +00:00
|
|
|
|
2012-02-04 22:53:53 +00:00
|
|
|
splinefile = fopen("spline.dat", FILE_MMAP_RW, sizeof(camdata_t));
|
2011-12-17 16:37:07 +00:00
|
|
|
if (splinefile < 0)
|
|
|
|
{
|
|
|
|
/*too lazy to create a file, just use it as a malloc*/
|
2012-02-04 22:53:53 +00:00
|
|
|
splinefile = fopen("", FILE_MMAP_RW, sizeof(camdata_t));
|
2011-12-17 16:37:07 +00:00
|
|
|
}
|
|
|
|
|
2012-02-04 22:53:53 +00:00
|
|
|
camdata = (camdata_t*)(fgets(splinefile));
|
2011-12-17 16:37:07 +00:00
|
|
|
};
|
|
|
|
void() spline_shutdown =
|
|
|
|
{
|
|
|
|
fclose(splinefile);
|
|
|
|
splinefile = -1;
|
|
|
|
};
|
|
|
|
|
2012-02-04 22:53:53 +00:00
|
|
|
static void spline_calclength(spline_t *s)
|
2011-12-17 16:37:07 +00:00
|
|
|
{
|
2012-02-04 22:53:53 +00:00
|
|
|
int i;
|
|
|
|
s->totallength = 0;
|
|
|
|
for (i = 0; i < s->numpoints - 1; i++)
|
|
|
|
{
|
|
|
|
s->totallength = s->totallength + vlen(s->pos[i] - s->pos[i+1]);
|
|
|
|
}
|
|
|
|
};
|
2011-12-17 16:37:07 +00:00
|
|
|
|
2012-02-04 22:53:53 +00:00
|
|
|
static vector(spline_t *s, float frac) spline_pos =
|
|
|
|
{
|
|
|
|
vector v1, v2;
|
2012-02-08 01:56:30 +00:00
|
|
|
if (s->numpoints < 2)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-02-04 22:53:53 +00:00
|
|
|
frac *= s->numpoints;
|
|
|
|
if (frac < 0)
|
|
|
|
{
|
|
|
|
v1 = s->pos[0];
|
|
|
|
v2 = s->pos[1];
|
|
|
|
}
|
|
|
|
else if (frac >= s->numpoints)
|
2011-12-17 16:37:07 +00:00
|
|
|
{
|
2012-02-04 22:53:53 +00:00
|
|
|
v1 = s->pos[s->numpoints-2];
|
|
|
|
v2 = s->pos[s->numpoints-1];
|
|
|
|
frac -= s->numpoints;
|
2011-12-17 16:37:07 +00:00
|
|
|
}
|
2012-02-04 22:53:53 +00:00
|
|
|
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;
|
2011-12-17 16:37:07 +00:00
|
|
|
};
|
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
void(vector p1, vector p2, vector color) fakeline = {
|
|
|
|
R_BeginPolygon("camsplineshader");
|
|
|
|
R_PolygonVertex(p1+'0 0 1', '0 0', color,1);
|
|
|
|
R_PolygonVertex(p1-'0 0 1', '0 1', color,1);
|
|
|
|
R_PolygonVertex(p2-'0 0 1', '1 1', color,1);
|
|
|
|
R_PolygonVertex(p2+'0 0 1', '1 0', color,1);
|
|
|
|
R_PolygonVertex(p1-'0 0 1', '0 0', color,1);
|
|
|
|
R_PolygonVertex(p1+'0 0 1', '0 1', color,1);
|
|
|
|
R_PolygonVertex(p2+'0 0 1', '1 1', color,1);
|
|
|
|
R_PolygonVertex(p2-'0 0 1', '1 0', color,1);
|
|
|
|
|
|
|
|
R_EndPolygon();
|
|
|
|
};
|
|
|
|
|
|
|
|
void (vector pos, vector color) draw_point
|
|
|
|
{
|
|
|
|
local vector pos1, pos2;
|
|
|
|
//x
|
|
|
|
pos1 = pos - '10 0 0';
|
|
|
|
pos2 = pos + '10 0 0';
|
|
|
|
fakeline(pos1, pos2, color);
|
|
|
|
//y
|
|
|
|
pos1 = pos - '0 10 0';
|
|
|
|
pos2 = pos + '0 10 0';
|
|
|
|
fakeline(pos1, pos2, color);
|
|
|
|
//z -- this isnt drawing right for some reason
|
|
|
|
pos1 = pos - '0 0 10';
|
|
|
|
pos2 = pos + '0 0 10';
|
|
|
|
fakeline(pos1, pos2, color);
|
|
|
|
};
|
|
|
|
|
|
|
|
// time has to be between 0 and 1
|
|
|
|
vector(spline_t *s, float frac_time) spline_calculate_position =
|
|
|
|
{
|
|
|
|
local vector r, point1, point2, point3, point4;
|
|
|
|
local float t1, t2, t3, t4, t5, t_scaled;
|
|
|
|
local int i;
|
|
|
|
|
|
|
|
if (s->numpoints == 0)
|
|
|
|
{
|
|
|
|
return '0 0 0';
|
|
|
|
}
|
|
|
|
|
|
|
|
// point
|
|
|
|
if (s->numpoints == 1)
|
|
|
|
{
|
|
|
|
return s->pos[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// straight line
|
|
|
|
if (s->numpoints == 2)
|
|
|
|
{
|
|
|
|
r = s->pos[1] - s->pos[0];
|
|
|
|
r = r * frac_time;
|
|
|
|
r = r + s->pos[0];
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cubic spline
|
|
|
|
if (s->numpoints == 3)// || (s->numpoints > 3 && s->type == 1))
|
|
|
|
{
|
|
|
|
t1 = 1-frac_time;
|
|
|
|
t2 = pow(t1, s->numpoints - 1);
|
|
|
|
t3 = pow(frac_time, s->numpoints - 1);
|
|
|
|
|
|
|
|
for (i=0; i<s->numpoints; i++)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
r = s->pos[i] * t2;
|
|
|
|
}
|
|
|
|
else if (i == s->numpoints - 1)
|
|
|
|
{
|
|
|
|
r = r + s->pos[i] * t3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t4 = (s->numpoints-1) * pow(frac_time, i) * pow(t1, s->numpoints - 1 - i);
|
|
|
|
r = r + s->pos[i] * t4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// catmull rom
|
|
|
|
if (s->numpoints > 3)
|
|
|
|
{
|
|
|
|
// getting the start point -- might change if we add times to points
|
|
|
|
// first point is always an entry point last point also
|
|
|
|
t5 = 1 / (s->numpoints - 3);
|
|
|
|
for (i=1, t4=t5; t4<frac_time; t4 = t4 + t5)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
//print(sprintf("end: %i\n", i));
|
|
|
|
if (i > s->numpoints)
|
|
|
|
{
|
|
|
|
print(sprintf("something went wrong while getting the start point!\n"));
|
|
|
|
return s->pos[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
point1 = s->pos[i - 1i];
|
|
|
|
point2 = s->pos[i];
|
|
|
|
point3 = s->pos[i+1i];
|
|
|
|
point4 = s->pos[i+2i];
|
|
|
|
|
|
|
|
// scale the time so its 0 -> 1 between point1 and 2
|
|
|
|
/*
|
|
|
|
1 2 3 4 5 6
|
|
|
|
0 1
|
|
|
|
0 1
|
|
|
|
*/
|
|
|
|
|
|
|
|
t_scaled = (frac_time - (t4 - t5))/t5; // hope this works :P
|
|
|
|
|
|
|
|
// would be really nice if i could access vector components via [0] [1] ... here
|
|
|
|
// warning RETARDED!
|
|
|
|
t1 = point2_x;
|
|
|
|
t2 = -0.5 * point1_x + 0.5 * point3_x;
|
|
|
|
t3 = point1_x + (-2.5 * point2_x) + 2.0* point3_x +(-0.5 *point4_x);
|
|
|
|
t4 = -0.5 * point1_x + 1.5 * point2_x + (-1.5 * point3_x) + 0.5 * point4_x;
|
|
|
|
r_x = ((t4 * t_scaled + t3)*t_scaled + t2)*t_scaled + t1;
|
|
|
|
|
|
|
|
t1 = point2_y;
|
|
|
|
t2 = -0.5 * point1_y + 0.5 * point3_y;
|
|
|
|
t3 = point1_y + (-2.5 * point2_y) + 2.0* point3_y +(-0.5 *point4_y);
|
|
|
|
t4 = -0.5 * point1_y + 1.5 * point2_y + (-1.5 * point3_y) + 0.5 * point4_y;
|
|
|
|
r_y = ((t4 * t_scaled + t3)*t_scaled + t2)*t_scaled + t1;
|
|
|
|
|
|
|
|
t1 = point2_z;
|
|
|
|
t2 = -0.5 * point1_z + 0.5 * point3_z;
|
|
|
|
t3 = point1_z + (-2.5 * point2_z) + 2.0* point3_z +(-0.5 *point4_z);
|
|
|
|
t4 = -0.5 * point1_z + 1.5 * point2_z + (-1.5 * point3_z) + 0.5 * point4_z;
|
|
|
|
r_z = ((t4 * t_scaled + t3)*t_scaled + t2)*t_scaled + t1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s->pos[0];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-12-17 16:37:07 +00:00
|
|
|
static void(spline_t *s) spline_draw =
|
|
|
|
{
|
2012-02-04 22:53:53 +00:00
|
|
|
local float step, frac;
|
|
|
|
local vector pos, pos1, pos2, vpos;
|
|
|
|
local vector bdir;
|
2012-02-08 01:56:30 +00:00
|
|
|
local int i;
|
|
|
|
local vector color;
|
2012-02-04 22:53:53 +00:00
|
|
|
|
2011-12-17 16:37:07 +00:00
|
|
|
/*example of drawing convex polygons*/
|
|
|
|
R_BeginPolygon("camsplineshader");
|
|
|
|
|
2012-02-04 22:53:53 +00:00
|
|
|
vpos = getviewprop(VF_ORIGIN);
|
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
if (s->numpoints < 3)
|
|
|
|
{
|
|
|
|
step = 1; // should be fine
|
|
|
|
}
|
|
|
|
else
|
2012-02-04 22:53:53 +00:00
|
|
|
{
|
2012-02-08 01:56:30 +00:00
|
|
|
step = 0.01;
|
|
|
|
}
|
2012-02-04 22:53:53 +00:00
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
color = '1 0 1';
|
|
|
|
|
|
|
|
for (frac=0; frac<=1; frac = frac + step)
|
|
|
|
{
|
|
|
|
pos = spline_calculate_position(s, frac);
|
|
|
|
if (frac == 0)
|
|
|
|
{
|
|
|
|
pos2 = pos;
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-04 22:53:53 +00:00
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
fakeline(pos2, pos, color);
|
|
|
|
pos2 = pos;
|
|
|
|
}
|
2012-02-04 22:53:53 +00:00
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
//fakeline(pos2, s->pos[s->numpoints-1]);
|
2012-02-04 22:53:53 +00:00
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
// draw points
|
|
|
|
for (i=0; i<s->numpoints; i++)
|
|
|
|
{
|
|
|
|
color = '0.25 0.25 0.25';
|
|
|
|
if (i == s->selected_point)
|
|
|
|
color = '1 1 1';
|
|
|
|
draw_point(s->pos[i], color);
|
2012-02-04 22:53:53 +00:00
|
|
|
}
|
2012-02-08 01:56:30 +00:00
|
|
|
// draw position
|
|
|
|
pos = spline_calculate_position(s, s->position);
|
|
|
|
draw_point(pos, '1 0 0');
|
2012-02-04 22:53:53 +00:00
|
|
|
};
|
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
void(float attime) spline_overrides =
|
|
|
|
{
|
|
|
|
};
|
2012-02-04 22:53:53 +00:00
|
|
|
/*called to move the view to some simulation time*/
|
2012-02-08 01:56:30 +00:00
|
|
|
/*
|
2012-02-04 22:53:53 +00:00
|
|
|
void(float attime) spline_overrides =
|
|
|
|
{
|
|
|
|
local cam_t *cam;
|
|
|
|
local int i;
|
|
|
|
local vector src, dst;
|
|
|
|
local float frac;
|
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
//find correct spline based upon time
|
|
|
|
for (i = 0; i < camdata->count; i++)
|
2012-02-04 22:53:53 +00:00
|
|
|
{
|
|
|
|
cam = &camdata->cam[i];
|
|
|
|
if (cam->starttime <= attime && cam->endtime > attime)
|
|
|
|
break;
|
|
|
|
}
|
2012-02-08 01:56:30 +00:00
|
|
|
//give up if no matches
|
|
|
|
if (i == camdata->count)
|
2012-02-04 22:53:53 +00:00
|
|
|
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));
|
2011-12-17 16:37:07 +00:00
|
|
|
};
|
2012-02-08 01:56:30 +00:00
|
|
|
*/
|
2011-12-17 16:37:07 +00:00
|
|
|
|
|
|
|
void() editor_spline_add =
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (splinefile < 0)
|
|
|
|
spline_init();
|
|
|
|
|
|
|
|
/*add visible splines to the scene*/
|
2012-02-08 01:56:30 +00:00
|
|
|
for (i = 0; i < camdata->position_count; i+=1i)
|
|
|
|
spline_draw(&camdata->position[i].spline);
|
2011-12-17 16:37:07 +00:00
|
|
|
|
|
|
|
/*sort out the overrides*/
|
|
|
|
// spline_overrides(simtime);
|
|
|
|
};
|
2012-02-08 04:13:25 +00:00
|
|
|
float slidertestfloat1, slidertestfloat2;
|
|
|
|
static float *curslider;
|
|
|
|
void(string fieldname, vector pos, vector mousepos, float *value, float minv, float maxv, float key) sliderf_widgit =
|
|
|
|
{
|
|
|
|
local vector rpos, col;
|
|
|
|
local float f;
|
|
|
|
rpos = pos + '132 0 0';
|
|
|
|
/*if they're dragging us, update*/
|
|
|
|
if ((int)curslider == (int)value)
|
|
|
|
{
|
|
|
|
if (mousedown == 1)
|
|
|
|
{
|
|
|
|
*value = ((mousepos_x - 4 - rpos)/(9*8)*(maxv-minv)) + minv;
|
|
|
|
*value = bound(minv, *value, maxv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
curslider = (int*)__NULL__;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key == -1)
|
|
|
|
{
|
|
|
|
if (mousepos_y >= pos_y && mousepos_y < pos_y + 8)
|
|
|
|
{
|
|
|
|
col_x = (sin(time*3.14)+1) / 2;
|
|
|
|
col_y = col_x;
|
|
|
|
col_z = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
col = '1 1 1';
|
|
|
|
|
|
|
|
f = *value;
|
|
|
|
if (f < minv)
|
|
|
|
f = minv;
|
|
|
|
if (f > maxv)
|
|
|
|
f = maxv;
|
|
|
|
drawstring(pos, fieldname, '8 8 0', col, 1, 0);
|
|
|
|
pos = rpos;
|
|
|
|
rpos_x -= 4;
|
|
|
|
drawstring(rpos, "^Ue080^Ue081^Ue081^Ue081^Ue081^Ue081^Ue081^Ue081^Ue081^Ue081^Ue082", '8 8 0', '1 1 1', 1, 0);
|
|
|
|
drawstring(rpos + '88 0', ftos(f), '8 8 0', col, 1, 0);
|
|
|
|
rpos_x += 4;
|
|
|
|
rpos_x += 9*8*(f - minv) / (maxv - minv);
|
|
|
|
drawstring(rpos, "^Ue083", '8 8 0', '1 1 1', 1, 0);
|
|
|
|
}
|
|
|
|
else if (mousepos_y >= pos_y && mousepos_y < pos_y + 8)
|
|
|
|
{
|
|
|
|
if (key == 512)
|
|
|
|
curslider = value;
|
|
|
|
else if (key == 515)
|
|
|
|
*value = bound(minv, *value + (maxv - minv) / 10, maxv);
|
|
|
|
else if (key == 516)
|
|
|
|
*value = bound(minv, *value - (maxv - minv) / 10, maxv);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void(string fieldname, vector pos, vector mousepos, float *value, float key) checkboxf_widgit =
|
|
|
|
{
|
|
|
|
local vector rpos, col;
|
|
|
|
rpos = pos + '132 0 0';
|
|
|
|
|
|
|
|
if (key == -1)
|
|
|
|
{
|
|
|
|
if (mousepos_y >= pos_y && mousepos_y < pos_y + 8)
|
|
|
|
{
|
|
|
|
col_x = (sin(time*3.14)+1) / 2;
|
|
|
|
col_y = col_x;
|
|
|
|
col_z = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
col = '1 1 1';
|
|
|
|
|
|
|
|
drawstring(pos, fieldname, '8 8 0', col, 1, 0);
|
|
|
|
rpos_x -= 4;
|
|
|
|
drawstring(rpos, "^Ue080^Ue082", '8 8 0', '1 1 1', 1, 0);
|
|
|
|
drawstring(rpos + '88 0', ((*value) ?"TRUE":"FALSE"), '8 8 0', col, 1, 0);
|
|
|
|
rpos_x += 4;
|
|
|
|
if (*value)
|
|
|
|
drawstring(rpos, "^Ue083", '8 8 0', '1 1 1', 1, 0);
|
|
|
|
}
|
|
|
|
else if (mousepos_y >= pos_y && mousepos_y < pos_y + 8)
|
|
|
|
{
|
|
|
|
if (key == 512)
|
|
|
|
*value = !*value;
|
|
|
|
else if (key == 515)
|
|
|
|
*value = !*value;
|
|
|
|
else if (key == 516)
|
|
|
|
*value = !*value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void(vector curmousepos, float key) testmenu =
|
|
|
|
{
|
|
|
|
vector pos;
|
|
|
|
|
|
|
|
pos = '0 80';
|
|
|
|
sliderf_widgit ("test float a", pos, curmousepos, &slidertestfloat1, 100, 200, key);pos_y += 8;
|
|
|
|
sliderf_widgit ("test float b", pos, curmousepos, &slidertestfloat2, 0, 1, key);pos_y += 8;
|
|
|
|
|
|
|
|
checkboxf_widgit ("checkbox test", pos, curmousepos, &slidertestfloat2, key);pos_y += 8;
|
|
|
|
}
|
|
|
|
|
2011-12-17 16:37:07 +00:00
|
|
|
void(vector curmousepos) editor_spline_overlay =
|
|
|
|
{
|
2012-02-08 01:56:30 +00:00
|
|
|
local vector pos, v;
|
|
|
|
local spline_t *s;
|
|
|
|
|
2011-12-17 16:37:07 +00:00
|
|
|
if (splinefile < 0)
|
|
|
|
spline_init();
|
|
|
|
|
|
|
|
|
|
|
|
/*draw menu*/
|
|
|
|
/*dunno if the light editor has any convienient code*/
|
2012-02-08 01:56:30 +00:00
|
|
|
pos_y = 40;
|
|
|
|
drawrawstring(pos, sprintf("cam : %i / %i", camdata->position_selected + 1i , camdata->position_count), '8 8 0', '1 1 1', 1);
|
|
|
|
if (camdata->position_count)
|
|
|
|
{
|
|
|
|
pos_y += 8;
|
|
|
|
s = &camdata->position[camdata->position_selected].spline;
|
|
|
|
v = s->pos[s->selected_point];
|
|
|
|
drawrawstring(pos, sprintf(" point: %i / %i -- %f %f %f", s->selected_point + 1i, s->numpoints, v_x, v_y, v_z), '8 8 0', '1 1 1', 1);
|
|
|
|
}
|
|
|
|
pos_y += 8;
|
|
|
|
drawrawstring(pos, sprintf("view : %i / %i", camdata->view_selected + 1i, camdata->view_count), '8 8 0', '1 1 1', 1);
|
2012-02-08 04:13:25 +00:00
|
|
|
|
|
|
|
testmenu(curmousepos, -1);
|
2012-02-08 01:56:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int (spline_t *s, vector point) spline_add_point =
|
|
|
|
{
|
|
|
|
if (s->numpoints + 1 >= 64)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->pos[s->numpoints] = point;
|
|
|
|
s->selected_point = s->numpoints;
|
|
|
|
s->numpoints = s->numpoints + 1i; //oldskool!
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void (spline_t *s, vector point) spline_set_point =
|
|
|
|
{
|
|
|
|
s->pos[s->selected_point] = point;
|
2011-12-17 16:37:07 +00:00
|
|
|
};
|
2012-02-08 01:56:30 +00:00
|
|
|
|
|
|
|
void (int type) position_add_point =
|
|
|
|
{
|
|
|
|
vector v;
|
|
|
|
int i;
|
|
|
|
local cam_t *c;
|
|
|
|
local spline_t *s;
|
|
|
|
|
|
|
|
i = camdata->position_selected;
|
|
|
|
c = &camdata->position[i];
|
|
|
|
s = &c->spline;
|
|
|
|
v = getviewprop(VF_ORIGIN);
|
|
|
|
if (type == 0)
|
|
|
|
{
|
|
|
|
if (spline_add_point(s, v))
|
|
|
|
{
|
|
|
|
// print(sprintf("point could not be added.\n"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// print(sprintf("added point: %i %f %f %f\n", s->selected_point, v_x, v_y, v_z));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void(void) position_add
|
|
|
|
{
|
|
|
|
print(sprintf("test\n"));
|
|
|
|
if (camdata->position_count >= 64)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
print(sprintf("adding a position\n"));
|
|
|
|
|
|
|
|
camdata->position_selected = camdata->position_count;
|
|
|
|
camdata->position_count = camdata->position_count + 1i; //oldskool
|
|
|
|
}
|
|
|
|
|
|
|
|
void(void) view_add
|
|
|
|
{
|
|
|
|
if (camdata->view_count >= 64)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
camdata->view_selected = camdata->view_count;
|
|
|
|
camdata->view_count = camdata->view_count + 1i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void(spline_t *s, vector change) spline_change_point_position
|
|
|
|
{
|
|
|
|
if (s->numpoints == 0)
|
|
|
|
return;
|
|
|
|
s->pos[s->selected_point] = s->pos[s->selected_point] + change;
|
|
|
|
};
|
|
|
|
|
|
|
|
void (spline_t *s, float change) spline_change_position
|
|
|
|
{
|
|
|
|
s->position = s->position + change;
|
|
|
|
if (s->position < 0)
|
|
|
|
s->position = 0;
|
|
|
|
else if (s->position > 1)
|
|
|
|
s->position = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void(spline_t *s, int change) spline_change_selected_point
|
|
|
|
{
|
|
|
|
if (s->numpoints == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (change + s->selected_point < 0)
|
|
|
|
s->selected_point = s->numpoints -1;
|
|
|
|
else if (change + s->selected_point >= s->numpoints)
|
|
|
|
s->selected_point = 0;
|
|
|
|
else
|
|
|
|
s->selected_point = s->selected_point + change;
|
|
|
|
};
|
|
|
|
|
2011-12-17 16:37:07 +00:00
|
|
|
float(float keycode, float unicode, vector curmousepos) editor_spline_key
|
|
|
|
{
|
2012-02-08 01:56:30 +00:00
|
|
|
if (keycode == 'j')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
position_add();
|
|
|
|
position_add_point(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == 'k')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_selected_point(&camdata->position[camdata->position_selected].spline, -1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == 'l')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_selected_point(&camdata->position[camdata->position_selected].spline, 1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == '9')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_point_position(&camdata->position[camdata->position_selected].spline, '0 0 -1');
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == '0')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_point_position(&camdata->position[camdata->position_selected].spline, '0 0 1');
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == '7')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_point_position(&camdata->position[camdata->position_selected].spline, '0 -1 0');
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == '8')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_point_position(&camdata->position[camdata->position_selected].spline, '0 1 0');
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == '5')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_point_position(&camdata->position[camdata->position_selected].spline, '-1 0 0');
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == '6')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_point_position(&camdata->position[camdata->position_selected].spline, '1 0 0');
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == '-')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_position(&camdata->position[camdata->position_selected].spline, -0.01);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == '=')
|
|
|
|
{
|
|
|
|
if (camdata->position_count == 0)
|
|
|
|
return FALSE;
|
|
|
|
spline_change_position(&camdata->position[camdata->position_selected].spline, 0.01);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-08 04:13:25 +00:00
|
|
|
testmenu(curmousepos, keycode);
|
|
|
|
|
|
|
|
|
2012-02-08 01:56:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-17 16:37:07 +00:00
|
|
|
return FALSE;
|
|
|
|
};
|
|
|
|
|