remove obnoxious #defines for X, Y, Z, and W.

This commit is contained in:
David Rose 2008-09-12 18:31:49 +00:00
parent 904d6cb128
commit 601b0d45c8
7 changed files with 224 additions and 229 deletions

View File

@ -15,13 +15,13 @@ void gl_transform_to_viewport(GLContext *c,GLVertex *v)
float winv;
/* coordinates */
winv = 1.0f / v->pc.W;
v->zp.x= (int) ( v->pc.X * winv * c->viewport.scale.X
+ c->viewport.trans.X );
v->zp.y= (int) ( v->pc.Y * winv * c->viewport.scale.Y
+ c->viewport.trans.Y );
v->zp.z= (int) ( v->pc.Z * winv * c->viewport.scale.Z
+ c->viewport.trans.Z );
winv = 1.0f / v->pc.v[3];
v->zp.x= (int) ( v->pc.v[0] * winv * c->viewport.scale.v[0]
+ c->viewport.trans.v[0] );
v->zp.y= (int) ( v->pc.v[1] * winv * c->viewport.scale.v[1]
+ c->viewport.trans.v[1] );
v->zp.z= (int) ( v->pc.v[2] * winv * c->viewport.scale.v[2]
+ c->viewport.trans.v[2] );
/* color */
v->zp.r=(int)(v->color.v[0] * (ZB_POINT_RED_MAX - ZB_POINT_RED_MIN)
+ ZB_POINT_RED_MIN);
@ -34,8 +34,8 @@ void gl_transform_to_viewport(GLContext *c,GLVertex *v)
/* texture */
if (c->texture_2d_enabled) {
v->zp.s = (int)(v->tex_coord.X * c->current_texture->s_max);
v->zp.t = (int)(v->tex_coord.Y * c->current_texture->t_max);
v->zp.s = (int)(v->tex_coord.v[0] * c->current_texture->s_max);
v->zp.t = (int)(v->tex_coord.v[1] * c->current_texture->t_max);
}
}
@ -53,10 +53,10 @@ void gl_draw_point(GLContext *c,GLVertex *p0)
static inline void interpolate(GLVertex *q,GLVertex *p0,GLVertex *p1,float t)
{
q->pc.X=p0->pc.X+(p1->pc.X-p0->pc.X)*t;
q->pc.Y=p0->pc.Y+(p1->pc.Y-p0->pc.Y)*t;
q->pc.Z=p0->pc.Z+(p1->pc.Z-p0->pc.Z)*t;
q->pc.W=p0->pc.W+(p1->pc.W-p0->pc.W)*t;
q->pc.v[0]=p0->pc.v[0]+(p1->pc.v[0]-p0->pc.v[0])*t;
q->pc.v[1]=p0->pc.v[1]+(p1->pc.v[1]-p0->pc.v[1])*t;
q->pc.v[2]=p0->pc.v[2]+(p1->pc.v[2]-p0->pc.v[2])*t;
q->pc.v[3]=p0->pc.v[3]+(p1->pc.v[3]-p0->pc.v[3])*t;
q->color.v[0]=p0->color.v[0] + (p1->color.v[0]-p0->color.v[0])*t;
q->color.v[1]=p0->color.v[1] + (p1->color.v[1]-p0->color.v[1])*t;
@ -104,14 +104,14 @@ void gl_draw_line(GLContext *c,GLVertex *p1,GLVertex *p2)
} else if ( (cc1&cc2) != 0 ) {
return;
} else {
dx=p2->pc.X-p1->pc.X;
dy=p2->pc.Y-p1->pc.Y;
dz=p2->pc.Z-p1->pc.Z;
dw=p2->pc.W-p1->pc.W;
x1=p1->pc.X;
y1=p1->pc.Y;
z1=p1->pc.Z;
w1=p1->pc.W;
dx=p2->pc.v[0]-p1->pc.v[0];
dy=p2->pc.v[1]-p1->pc.v[1];
dz=p2->pc.v[2]-p1->pc.v[2];
dw=p2->pc.v[3]-p1->pc.v[3];
x1=p1->pc.v[0];
y1=p1->pc.v[1];
z1=p1->pc.v[2];
w1=p1->pc.v[3];
tmin=0;
tmax=1;
@ -147,36 +147,37 @@ void gl_draw_line(GLContext *c,GLVertex *p1,GLVertex *p2)
* of the intersection if x=a+t(b-a).
*/
#define clip_func(name,sign,dir,dir1,dir2) \
static float name(V4 *c,V4 *a,V4 *b) \
#define clip_func(name, sign, dir, dir1, dir2) \
static float name(V4 *c, V4 *a, V4 *b) \
{\
float t,dX,dY,dZ,dW,den;\
dX = (b->X - a->X);\
dY = (b->Y - a->Y);\
dZ = (b->Z - a->Z);\
dW = (b->W - a->W);\
den = -(sign d ## dir) + dW;\
float t,den;\
float d[4];\
d[0] = (b->v[0] - a->v[0]);\
d[1] = (b->v[1] - a->v[1]);\
d[2] = (b->v[2] - a->v[2]);\
d[3] = (b->v[3] - a->v[3]);\
den = -(sign d[dir]) + d[3];\
if (den == 0) t=0;\
else t = ( sign a->dir - a->W) / den;\
c->dir1 = a->dir1 + t * d ## dir1;\
c->dir2 = a->dir2 + t * d ## dir2;\
c->W = a->W + t * dW;\
c->dir = sign c->W;\
else t = ( sign a->v[dir] - a->v[3]) / den;\
c->v[dir1] = a->v[dir1] + t * d[dir1];\
c->v[dir2] = a->v[dir2] + t * d[dir2];\
c->v[3] = a->v[3] + t * d[3];\
c->v[dir] = sign c->v[3];\
return t;\
}
clip_func(clip_xmin,-,X,Y,Z)
clip_func(clip_xmin, -, 0, 1, 2)
clip_func(clip_xmax,+,X,Y,Z)
clip_func(clip_xmax, +, 0, 1, 2)
clip_func(clip_ymin,-,Y,X,Z)
clip_func(clip_ymin, -, 1, 0, 2)
clip_func(clip_ymax,+,Y,X,Z)
clip_func(clip_ymax, +, 1, 0, 2)
clip_func(clip_zmin,-,Z,X,Y)
clip_func(clip_zmin, -, 2, 0, 1)
clip_func(clip_zmax,+,Z,X,Y)
clip_func(clip_zmax, +, 2, 0, 1)
float (*clip_proc[6])(V4 *,V4 *,V4 *)= {
@ -201,11 +202,11 @@ static inline void updateTmp(GLContext *c,
}
if (c->texture_2d_enabled) {
q->tex_coord.X=p0->tex_coord.X + (p1->tex_coord.X-p0->tex_coord.X)*t;
q->tex_coord.Y=p0->tex_coord.Y + (p1->tex_coord.Y-p0->tex_coord.Y)*t;
q->tex_coord.v[0]=p0->tex_coord.v[0] + (p1->tex_coord.v[0]-p0->tex_coord.v[0])*t;
q->tex_coord.v[1]=p0->tex_coord.v[1] + (p1->tex_coord.v[1]-p0->tex_coord.v[1])*t;
}
q->clip_code=gl_clipcode(q->pc.X,q->pc.Y,q->pc.Z,q->pc.W);
q->clip_code=gl_clipcode(q->pc.v[0],q->pc.v[1],q->pc.v[2],q->pc.v[3]);
if (q->clip_code==0)
gl_transform_to_viewport(c,q);
}
@ -289,9 +290,9 @@ static void gl_draw_triangle_clip(GLContext *c,
if (clip_bit == 6) {
#if 0
printf("Error:\n");
printf("%f %f %f %f\n",p0->pc.X,p0->pc.Y,p0->pc.Z,p0->pc.W);
printf("%f %f %f %f\n",p1->pc.X,p1->pc.Y,p1->pc.Z,p1->pc.W);
printf("%f %f %f %f\n",p2->pc.X,p2->pc.Y,p2->pc.Z,p2->pc.W);
printf("%f %f %f %f\n",p0->pc.v[0],p0->pc.v[1],p0->pc.v[2],p0->pc.v[3]);
printf("%f %f %f %f\n",p1->pc.v[0],p1->pc.v[1],p1->pc.v[2],p1->pc.v[3]);
printf("%f %f %f %f\n",p2->pc.v[0],p2->pc.v[1],p2->pc.v[2],p2->pc.v[3]);
#endif
return;
}

View File

@ -37,20 +37,20 @@ void glInit(GLContext *c, ZBuffer *zbuffer)
}
/* default state */
c->current_color.X=1.0f;
c->current_color.Y=1.0f;
c->current_color.Z=1.0f;
c->current_color.W=1.0f;
c->current_color.v[0]=1.0f;
c->current_color.v[1]=1.0f;
c->current_color.v[2]=1.0f;
c->current_color.v[3]=1.0f;
c->current_normal.X=1.0f;
c->current_normal.Y=0.0f;
c->current_normal.Z=0.0f;
c->current_normal.W=0.0f;
c->current_normal.v[0]=1.0f;
c->current_normal.v[1]=0.0f;
c->current_normal.v[2]=0.0f;
c->current_normal.v[3]=0.0f;
c->current_tex_coord.X=0.0f;
c->current_tex_coord.Y=0.0f;
c->current_tex_coord.Z=0.0f;
c->current_tex_coord.W=1.0f;
c->current_tex_coord.v[0]=0.0f;
c->current_tex_coord.v[1]=0.0f;
c->current_tex_coord.v[2]=0.0f;
c->current_tex_coord.v[3]=1.0f;
c->cull_face_enabled=0;

View File

@ -21,9 +21,9 @@ void gl_shade_vertex(GLContext *c,GLVertex *v)
m=&c->materials[0];
n.X=v->normal.X;
n.Y=v->normal.Y;
n.Z=v->normal.Z;
n.v[0]=v->normal.v[0];
n.v[1]=v->normal.v[1];
n.v[2]=v->normal.v[2];
R=m->emission.v[0]+m->ambient.v[0]*c->ambient_light_model.v[0];
G=m->emission.v[1]+m->ambient.v[1]*c->ambient_light_model.v[1];
@ -40,26 +40,26 @@ void gl_shade_vertex(GLContext *c,GLVertex *v)
if (l->position.v[3] == 0) {
/* light at infinity */
d.X=l->position.v[0];
d.Y=l->position.v[1];
d.Z=l->position.v[2];
d.v[0]=l->position.v[0];
d.v[1]=l->position.v[1];
d.v[2]=l->position.v[2];
att=1;
} else {
/* distance attenuation */
d.X=l->position.v[0]-v->ec.v[0];
d.Y=l->position.v[1]-v->ec.v[1];
d.Z=l->position.v[2]-v->ec.v[2];
dist = sqrtf(d.X*d.X+d.Y*d.Y+d.Z*d.Z);
d.v[0]=l->position.v[0]-v->ec.v[0];
d.v[1]=l->position.v[1]-v->ec.v[1];
d.v[2]=l->position.v[2]-v->ec.v[2];
dist = sqrtf(d.v[0]*d.v[0]+d.v[1]*d.v[1]+d.v[2]*d.v[2]);
if (dist>1E-3) {
tmp=1/dist;
d.X*=tmp;
d.Y*=tmp;
d.Z*=tmp;
d.v[0]*=tmp;
d.v[1]*=tmp;
d.v[2]*=tmp;
}
att=1.0f/(l->attenuation[0]+dist*(l->attenuation[1]+
dist*l->attenuation[2]));
}
dot=d.X*n.X+d.Y*n.Y+d.Z*n.Z;
dot=d.v[0]*n.v[0]+d.v[1]*n.v[1]+d.v[2]*n.v[2];
if (twoside && dot < 0) dot = -dot;
if (dot>0) {
/* diffuse light */
@ -69,9 +69,9 @@ void gl_shade_vertex(GLContext *c,GLVertex *v)
/* spot light */
if (l->spot_cutoff != 180) {
dot_spot=-(d.X*l->norm_spot_direction.v[0]+
d.Y*l->norm_spot_direction.v[1]+
d.Z*l->norm_spot_direction.v[2]);
dot_spot=-(d.v[0]*l->norm_spot_direction.v[0]+
d.v[1]*l->norm_spot_direction.v[1]+
d.v[2]*l->norm_spot_direction.v[2]);
if (twoside && dot_spot < 0) dot_spot = -dot_spot;
if (dot_spot < l->cos_spot_cutoff) {
/* no contribution */
@ -88,24 +88,24 @@ void gl_shade_vertex(GLContext *c,GLVertex *v)
if (c->local_light_model) {
V3 vcoord;
vcoord.X=v->ec.X;
vcoord.Y=v->ec.Y;
vcoord.Z=v->ec.Z;
vcoord.v[0]=v->ec.v[0];
vcoord.v[1]=v->ec.v[1];
vcoord.v[2]=v->ec.v[2];
gl_V3_Norm(&vcoord);
s.X=d.X-vcoord.X;
s.Y=d.Y-vcoord.X;
s.Z=d.Z-vcoord.X;
s.v[0]=d.v[0]-vcoord.v[0];
s.v[1]=d.v[1]-vcoord.v[0];
s.v[2]=d.v[2]-vcoord.v[0];
} else {
s.X=d.X;
s.Y=d.Y;
s.Z=d.Z+1.0f;
s.v[0]=d.v[0];
s.v[1]=d.v[1];
s.v[2]=d.v[2]+1.0f;
}
dot_spec=n.X*s.X+n.Y*s.Y+n.Z*s.Z;
dot_spec=n.v[0]*s.v[0]+n.v[1]*s.v[1]+n.v[2]*s.v[2];
if (twoside && dot_spec < 0) dot_spec = -dot_spec;
if (dot_spec>0) {
GLSpecBuf *specbuf;
int idx;
tmp=sqrt(s.X*s.X+s.Y*s.Y+s.Z*s.Z);
tmp=sqrt(s.v[0]*s.v[0]+s.v[1]*s.v[1]+s.v[2]*s.v[2]);
if (tmp > 1E-3) {
dot_spec=dot_spec / tmp;
}

View File

@ -606,10 +606,10 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
if (!needs_color) {
const Colorf &d = _scene_graph_color;
const Colorf &s = _current_color_scale;
_c->current_color.X = d[0] * s[0];
_c->current_color.Y = d[1] * s[1];
_c->current_color.Z = d[2] * s[2];
_c->current_color.W = d[3] * s[3];
_c->current_color.v[0] = d[0] * s[0];
_c->current_color.v[1] = d[1] * s[1];
_c->current_color.v[2] = d[2] * s[2];
_c->current_color.v[3] = d[3] * s[3];
}
bool needs_normal = false;
@ -651,31 +651,31 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
GLVertex *v = &_vertices[i];
const LVecBase4f &d = rvertex.get_data4f();
v->coord.X = d[0];
v->coord.Y = d[1];
v->coord.Z = d[2];
v->coord.W = d[3];
v->coord.v[0] = d[0];
v->coord.v[1] = d[1];
v->coord.v[2] = d[2];
v->coord.v[3] = d[3];
if (needs_texmat) {
// Transform texcoords as a four-component vector for most generality.
LVecBase4f d = rtexcoord.get_data4f() * texmat;
v->tex_coord.X = d[0];
v->tex_coord.Y = d[1];
v->tex_coord.v[0] = d[0];
v->tex_coord.v[1] = d[1];
} else if (needs_texcoord) {
// No need to transform, so just extract as two-component.
const LVecBase2f &d = rtexcoord.get_data2f();
v->tex_coord.X = d[0];
v->tex_coord.Y = d[1];
v->tex_coord.v[0] = d[0];
v->tex_coord.v[1] = d[1];
}
if (needs_color) {
const Colorf &d = rcolor.get_data4f();
const Colorf &s = _current_color_scale;
_c->current_color.X = d[0] * s[0];
_c->current_color.Y = d[1] * s[1];
_c->current_color.Z = d[2] * s[2];
_c->current_color.W = d[3] * s[3];
_c->current_color.v[0] = d[0] * s[0];
_c->current_color.v[1] = d[1] * s[1];
_c->current_color.v[2] = d[2] * s[2];
_c->current_color.v[3] = d[3] * s[3];
if (_color_material_flags) {
if (_color_material_flags & CMF_ambient) {
@ -693,10 +693,10 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
if (lighting_enabled) {
const LVecBase3f &d = rnormal.get_data3f();
_c->current_normal.X = d[0];
_c->current_normal.Y = d[1];
_c->current_normal.Z = d[2];
_c->current_normal.W = 0.0f;
_c->current_normal.v[0] = d[0];
_c->current_normal.v[1] = d[1];
_c->current_normal.v[2] = d[2];
_c->current_normal.v[3] = 0.0f;
gl_vertex_transform(_c, v);
gl_shade_vertex(_c, v);
@ -794,10 +794,10 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
if (shade_model == ShadeModelAttrib::M_flat) {
_c->smooth_shade_model = false;
shade_model_state = 1; // flat
if (_c->current_color.X == 1.0f &&
_c->current_color.Y == 1.0f &&
_c->current_color.Z == 1.0f &&
_c->current_color.W == 1.0f) {
if (_c->current_color.v[0] == 1.0f &&
_c->current_color.v[1] == 1.0f &&
_c->current_color.v[2] == 1.0f &&
_c->current_color.v[3] == 1.0f) {
shade_model_state = 0; // white
}
}
@ -1604,10 +1604,10 @@ do_issue_light() {
_c->first_light = gl_light;
const Colorf &diffuse = light_obj->get_color();
gl_light->diffuse.X = diffuse[0];
gl_light->diffuse.Y = diffuse[1];
gl_light->diffuse.Z = diffuse[2];
gl_light->diffuse.W = diffuse[3];
gl_light->diffuse.v[0] = diffuse[0];
gl_light->diffuse.v[1] = diffuse[1];
gl_light->diffuse.v[2] = diffuse[2];
gl_light->diffuse.v[3] = diffuse[3];
light_obj->bind(this, light, num_enabled);
num_enabled++;
@ -1615,10 +1615,10 @@ do_issue_light() {
}
}
_c->ambient_light_model.X = cur_ambient_light[0];
_c->ambient_light_model.Y = cur_ambient_light[1];
_c->ambient_light_model.Z = cur_ambient_light[2];
_c->ambient_light_model.W = cur_ambient_light[3];
_c->ambient_light_model.v[0] = cur_ambient_light[0];
_c->ambient_light_model.v[1] = cur_ambient_light[1];
_c->ambient_light_model.v[2] = cur_ambient_light[2];
_c->ambient_light_model.v[3] = cur_ambient_light[3];
// Changing the lighting state means we need to reapply the
// transform in begin_draw_primitives().
@ -1639,10 +1639,10 @@ bind_light(PointLight *light_obj, const NodePath &light, int light_id) {
nassertv(gl_light != (GLLight *)NULL);
const Colorf &specular = light_obj->get_specular_color();
gl_light->specular.X = specular[0];
gl_light->specular.Y = specular[1];
gl_light->specular.Z = specular[2];
gl_light->specular.W = specular[3];
gl_light->specular.v[0] = specular[0];
gl_light->specular.v[1] = specular[1];
gl_light->specular.v[2] = specular[2];
gl_light->specular.v[3] = specular[3];
// Position needs to specify x, y, z, and w
// w == 1 implies non-infinite position
@ -1653,10 +1653,10 @@ bind_light(PointLight *light_obj, const NodePath &light, int light_id) {
CPT(TransformState) net_transform = render_transform->compose(transform);
LPoint3f pos = light_obj->get_point() * net_transform->get_mat();
gl_light->position.X = pos[0];
gl_light->position.Y = pos[1];
gl_light->position.Z = pos[2];
gl_light->position.W = 1.0f;
gl_light->position.v[0] = pos[0];
gl_light->position.v[1] = pos[1];
gl_light->position.v[2] = pos[2];
gl_light->position.v[3] = 1.0f;
// Exponent == 0 implies uniform light distribution
gl_light->spot_exponent = 0.0f;
@ -1684,10 +1684,10 @@ bind_light(DirectionalLight *light_obj, const NodePath &light, int light_id) {
nassertv(gl_light != (GLLight *)NULL);
const Colorf &specular = light_obj->get_specular_color();
gl_light->specular.X = specular[0];
gl_light->specular.Y = specular[1];
gl_light->specular.Z = specular[2];
gl_light->specular.W = specular[3];
gl_light->specular.v[0] = specular[0];
gl_light->specular.v[1] = specular[1];
gl_light->specular.v[2] = specular[2];
gl_light->specular.v[3] = specular[3];
// Position needs to specify x, y, z, and w
// w == 0 implies light is at infinity
@ -1699,14 +1699,14 @@ bind_light(DirectionalLight *light_obj, const NodePath &light, int light_id) {
LVector3f dir = light_obj->get_direction() * net_transform->get_mat();
dir.normalize();
gl_light->position.X = -dir[0];
gl_light->position.Y = -dir[1];
gl_light->position.Z = -dir[2];
gl_light->position.W = 0.0f;
gl_light->position.v[0] = -dir[0];
gl_light->position.v[1] = -dir[1];
gl_light->position.v[2] = -dir[2];
gl_light->position.v[3] = 0.0f;
gl_light->norm_position.X = -dir[0];
gl_light->norm_position.Y = -dir[1];
gl_light->norm_position.Z = -dir[2];
gl_light->norm_position.v[0] = -dir[0];
gl_light->norm_position.v[1] = -dir[1];
gl_light->norm_position.v[2] = -dir[2];
gl_V3_Norm(&gl_light->norm_position);
// Exponent == 0 implies uniform light distribution
@ -1736,10 +1736,10 @@ bind_light(Spotlight *light_obj, const NodePath &light, int light_id) {
nassertv(gl_light != (GLLight *)NULL);
const Colorf &specular = light_obj->get_specular_color();
gl_light->specular.X = specular[0];
gl_light->specular.Y = specular[1];
gl_light->specular.Z = specular[2];
gl_light->specular.W = specular[3];
gl_light->specular.v[0] = specular[0];
gl_light->specular.v[1] = specular[1];
gl_light->specular.v[2] = specular[2];
gl_light->specular.v[3] = specular[3];
Lens *lens = light_obj->get_lens();
nassertv(lens != (Lens *)NULL);
@ -1757,18 +1757,18 @@ bind_light(Spotlight *light_obj, const NodePath &light, int light_id) {
LVector3f dir = lens->get_view_vector() * light_mat;
dir.normalize();
gl_light->position.X = pos[0];
gl_light->position.Y = pos[1];
gl_light->position.Z = pos[2];
gl_light->position.W = 1.0f;
gl_light->position.v[0] = pos[0];
gl_light->position.v[1] = pos[1];
gl_light->position.v[2] = pos[2];
gl_light->position.v[3] = 1.0f;
gl_light->spot_direction.X = dir[0];
gl_light->spot_direction.Y = dir[1];
gl_light->spot_direction.Z = dir[2];
gl_light->spot_direction.v[0] = dir[0];
gl_light->spot_direction.v[1] = dir[1];
gl_light->spot_direction.v[2] = dir[2];
gl_light->norm_spot_direction.X = dir[0];
gl_light->norm_spot_direction.Y = dir[1];
gl_light->norm_spot_direction.Z = dir[2];
gl_light->norm_spot_direction.v[0] = dir[0];
gl_light->norm_spot_direction.v[1] = dir[1];
gl_light->norm_spot_direction.v[2] = dir[2];
gl_V3_Norm(&gl_light->norm_spot_direction);
gl_light->spot_exponent = light_obj->get_exponent();
@ -2596,16 +2596,16 @@ copy_rgba_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int lev
void TinyGraphicsStateGuardian::
setup_material(GLMaterial *gl_material, const Material *material) {
const Colorf &specular = material->get_specular();
gl_material->specular.X = specular[0];
gl_material->specular.Y = specular[1];
gl_material->specular.Z = specular[2];
gl_material->specular.W = specular[3];
gl_material->specular.v[0] = specular[0];
gl_material->specular.v[1] = specular[1];
gl_material->specular.v[2] = specular[2];
gl_material->specular.v[3] = specular[3];
const Colorf &emission = material->get_emission();
gl_material->emission.X = emission[0];
gl_material->emission.Y = emission[1];
gl_material->emission.Z = emission[2];
gl_material->emission.W = emission[3];
gl_material->emission.v[0] = emission[0];
gl_material->emission.v[1] = emission[1];
gl_material->emission.v[2] = emission[2];
gl_material->emission.v[3] = emission[3];
gl_material->shininess = material->get_shininess();
gl_material->shininess_i = (int)((material->get_shininess() / 128.0f) * SPECULAR_BUFFER_RESOLUTION);
@ -2614,20 +2614,20 @@ setup_material(GLMaterial *gl_material, const Material *material) {
if (material->has_ambient()) {
const Colorf &ambient = material->get_ambient();
gl_material->ambient.X = ambient[0];
gl_material->ambient.Y = ambient[1];
gl_material->ambient.Z = ambient[2];
gl_material->ambient.W = ambient[3];
gl_material->ambient.v[0] = ambient[0];
gl_material->ambient.v[1] = ambient[1];
gl_material->ambient.v[2] = ambient[2];
gl_material->ambient.v[3] = ambient[3];
_color_material_flags &= ~CMF_ambient;
}
if (material->has_diffuse()) {
const Colorf &diffuse = material->get_diffuse();
gl_material->diffuse.X = diffuse[0];
gl_material->diffuse.Y = diffuse[1];
gl_material->diffuse.Z = diffuse[2];
gl_material->diffuse.W = diffuse[3];
gl_material->diffuse.v[0] = diffuse[0];
gl_material->diffuse.v[1] = diffuse[1];
gl_material->diffuse.v[2] = diffuse[2];
gl_material->diffuse.v[3] = diffuse[3];
_color_material_flags &= ~CMF_diffuse;
}

View File

@ -11,13 +11,13 @@ void gl_eval_viewport(GLContext * c) {
float ymin = v->ymin + v->ysize * (1.0f - s->top);
float zsize = (1 << (ZB_Z_BITS + ZB_POINT_Z_FRAC_BITS));
v->trans.X = ((xsize - 0.5f) / 2.0f) + xmin;
v->trans.Y = ((ysize - 0.5f) / 2.0f) + ymin;
v->trans.Z = ((zsize - 0.5f) / 2.0f) + ((1 << ZB_POINT_Z_FRAC_BITS)) / 2;
v->trans.v[0] = ((xsize - 0.5f) / 2.0f) + xmin;
v->trans.v[1] = ((ysize - 0.5f) / 2.0f) + ymin;
v->trans.v[2] = ((zsize - 0.5f) / 2.0f) + ((1 << ZB_POINT_Z_FRAC_BITS)) / 2;
v->scale.X = (xsize - 0.5f) / 2.0f;
v->scale.Y = -(ysize - 0.5f) / 2.0f;
v->scale.Z = -((zsize - 0.5f) / 2.0f);
v->scale.v[0] = (xsize - 0.5f) / 2.0f;
v->scale.v[1] = -(ysize - 0.5f) / 2.0f;
v->scale.v[2] = -((zsize - 0.5f) / 2.0f);
}
/* coords, tranformation , clip code and projection */
@ -31,32 +31,32 @@ void gl_vertex_transform(GLContext * c, GLVertex * v)
/* eye coordinates needed for lighting */
m = &c->matrix_model_view.m[0][0];
v->ec.X = (v->coord.X * m[0] + v->coord.Y * m[1] +
v->coord.Z * m[2] + m[3]);
v->ec.Y = (v->coord.X * m[4] + v->coord.Y * m[5] +
v->coord.Z * m[6] + m[7]);
v->ec.Z = (v->coord.X * m[8] + v->coord.Y * m[9] +
v->coord.Z * m[10] + m[11]);
v->ec.W = (v->coord.X * m[12] + v->coord.Y * m[13] +
v->coord.Z * m[14] + m[15]);
v->ec.v[0] = (v->coord.v[0] * m[0] + v->coord.v[1] * m[1] +
v->coord.v[2] * m[2] + m[3]);
v->ec.v[1] = (v->coord.v[0] * m[4] + v->coord.v[1] * m[5] +
v->coord.v[2] * m[6] + m[7]);
v->ec.v[2] = (v->coord.v[0] * m[8] + v->coord.v[1] * m[9] +
v->coord.v[2] * m[10] + m[11]);
v->ec.v[3] = (v->coord.v[0] * m[12] + v->coord.v[1] * m[13] +
v->coord.v[2] * m[14] + m[15]);
/* projection coordinates */
m = &c->matrix_projection.m[0][0];
v->pc.X = (v->ec.X * m[0] + v->ec.Y * m[1] +
v->ec.Z * m[2] + v->ec.W * m[3]);
v->pc.Y = (v->ec.X * m[4] + v->ec.Y * m[5] +
v->ec.Z * m[6] + v->ec.W * m[7]);
v->pc.Z = (v->ec.X * m[8] + v->ec.Y * m[9] +
v->ec.Z * m[10] + v->ec.W * m[11]);
v->pc.W = (v->ec.X * m[12] + v->ec.Y * m[13] +
v->ec.Z * m[14] + v->ec.W * m[15]);
v->pc.v[0] = (v->ec.v[0] * m[0] + v->ec.v[1] * m[1] +
v->ec.v[2] * m[2] + v->ec.v[3] * m[3]);
v->pc.v[1] = (v->ec.v[0] * m[4] + v->ec.v[1] * m[5] +
v->ec.v[2] * m[6] + v->ec.v[3] * m[7]);
v->pc.v[2] = (v->ec.v[0] * m[8] + v->ec.v[1] * m[9] +
v->ec.v[2] * m[10] + v->ec.v[3] * m[11]);
v->pc.v[3] = (v->ec.v[0] * m[12] + v->ec.v[1] * m[13] +
v->ec.v[2] * m[14] + v->ec.v[3] * m[15]);
m = &c->matrix_model_view_inv.m[0][0];
n = &c->current_normal;
v->normal.X = (n->X * m[0] + n->Y * m[1] + n->Z * m[2]) * c->normal_scale;
v->normal.Y = (n->X * m[4] + n->Y * m[5] + n->Z * m[6]) * c->normal_scale;
v->normal.Z = (n->X * m[8] + n->Y * m[9] + n->Z * m[10]) * c->normal_scale;
v->normal.v[0] = (n->v[0] * m[0] + n->v[1] * m[1] + n->v[2] * m[2]) * c->normal_scale;
v->normal.v[1] = (n->v[0] * m[4] + n->v[1] * m[5] + n->v[2] * m[6]) * c->normal_scale;
v->normal.v[2] = (n->v[0] * m[8] + n->v[1] * m[9] + n->v[2] * m[10]) * c->normal_scale;
if (c->normalize_enabled) {
gl_V3_Norm(&v->normal);
@ -66,19 +66,19 @@ void gl_vertex_transform(GLContext * c, GLVertex * v)
/* NOTE: W = 1 is assumed */
m = &c->matrix_model_projection.m[0][0];
v->pc.X = (v->coord.X * m[0] + v->coord.Y * m[1] +
v->coord.Z * m[2] + m[3]);
v->pc.Y = (v->coord.X * m[4] + v->coord.Y * m[5] +
v->coord.Z * m[6] + m[7]);
v->pc.Z = (v->coord.X * m[8] + v->coord.Y * m[9] +
v->coord.Z * m[10] + m[11]);
v->pc.v[0] = (v->coord.v[0] * m[0] + v->coord.v[1] * m[1] +
v->coord.v[2] * m[2] + m[3]);
v->pc.v[1] = (v->coord.v[0] * m[4] + v->coord.v[1] * m[5] +
v->coord.v[2] * m[6] + m[7]);
v->pc.v[2] = (v->coord.v[0] * m[8] + v->coord.v[1] * m[9] +
v->coord.v[2] * m[10] + m[11]);
if (c->matrix_model_projection_no_w_transform) {
v->pc.W = m[15];
v->pc.v[3] = m[15];
} else {
v->pc.W = (v->coord.X * m[12] + v->coord.Y * m[13] +
v->coord.Z * m[14] + m[15]);
v->pc.v[3] = (v->coord.v[0] * m[12] + v->coord.v[1] * m[13] +
v->coord.v[2] * m[14] + m[15]);
}
}
v->clip_code = gl_clipcode(v->pc.X, v->pc.Y, v->pc.Z, v->pc.W);
v->clip_code = gl_clipcode(v->pc.v[0], v->pc.v[1], v->pc.v[2], v->pc.v[3]);
}

View File

@ -73,24 +73,24 @@ void gl_MoveV3(V3 *a,V3 *b)
void gl_MulM4V3(V3 *a,M4 *b,V3 *c)
{
a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z+b->m[0][3];
a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z+b->m[1][3];
a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z+b->m[2][3];
a->v[0]=b->m[0][0]*c->v[0]+b->m[0][1]*c->v[1]+b->m[0][2]*c->v[2]+b->m[0][3];
a->v[1]=b->m[1][0]*c->v[0]+b->m[1][1]*c->v[1]+b->m[1][2]*c->v[2]+b->m[1][3];
a->v[2]=b->m[2][0]*c->v[0]+b->m[2][1]*c->v[1]+b->m[2][2]*c->v[2]+b->m[2][3];
}
void gl_MulM3V3(V3 *a,M4 *b,V3 *c)
{
a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z;
a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z;
a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z;
a->v[0]=b->m[0][0]*c->v[0]+b->m[0][1]*c->v[1]+b->m[0][2]*c->v[2];
a->v[1]=b->m[1][0]*c->v[0]+b->m[1][1]*c->v[1]+b->m[1][2]*c->v[2];
a->v[2]=b->m[2][0]*c->v[0]+b->m[2][1]*c->v[1]+b->m[2][2]*c->v[2];
}
void gl_M4_MulV4(V4 *a,M4 *b,V4 *c)
{
a->X=b->m[0][0]*c->X+b->m[0][1]*c->Y+b->m[0][2]*c->Z+b->m[0][3]*c->W;
a->Y=b->m[1][0]*c->X+b->m[1][1]*c->Y+b->m[1][2]*c->Z+b->m[1][3]*c->W;
a->Z=b->m[2][0]*c->X+b->m[2][1]*c->Y+b->m[2][2]*c->Z+b->m[2][3]*c->W;
a->W=b->m[3][0]*c->X+b->m[3][1]*c->Y+b->m[3][2]*c->Z+b->m[3][3]*c->W;
a->v[0]=b->m[0][0]*c->v[0]+b->m[0][1]*c->v[1]+b->m[0][2]*c->v[2]+b->m[0][3]*c->v[3];
a->v[1]=b->m[1][0]*c->v[0]+b->m[1][1]*c->v[1]+b->m[1][2]*c->v[2]+b->m[1][3]*c->v[3];
a->v[2]=b->m[2][0]*c->v[0]+b->m[2][1]*c->v[1]+b->m[2][2]*c->v[2]+b->m[2][3]*c->v[3];
a->v[3]=b->m[3][0]*c->v[0]+b->m[3][1]*c->v[1]+b->m[3][2]*c->v[2]+b->m[3][3]*c->v[3];
}
/* transposition of a 4x4 matrix */
@ -245,30 +245,30 @@ void gl_M3_Inv(M3 *a,M3 *m)
int gl_V3_Norm(V3 *a)
{
float n;
n=sqrt(a->X*a->X+a->Y*a->Y+a->Z*a->Z);
n=sqrt(a->v[0]*a->v[0]+a->v[1]*a->v[1]+a->v[2]*a->v[2]);
if (n==0) return 1;
a->X/=n;
a->Y/=n;
a->Z/=n;
a->v[0]/=n;
a->v[1]/=n;
a->v[2]/=n;
return 0;
}
V3 gl_V3_New(float x,float y,float z)
{
V3 a;
a.X=x;
a.Y=y;
a.Z=z;
a.v[0]=x;
a.v[1]=y;
a.v[2]=z;
return a;
}
V4 gl_V4_New(float x,float y,float z,float w)
{
V4 a;
a.X=x;
a.Y=y;
a.Z=z;
a.W=w;
a.v[0]=x;
a.v[1]=y;
a.v[2]=z;
a.v[3]=w;
return a;
}

View File

@ -15,12 +15,6 @@ typedef struct {
float m[3][4];
} M34;
#define X v[0]
#define Y v[1]
#define Z v[2]
#define W v[3]
typedef struct {
float v[3];
} V3;