Software 3d engine maths
Hi,
I am writing a software 3d engine just as an excercise in programming. I have a basic triangle renderer working with gourad shading (so adding texturing wont take much longer, just another variable to intoplerate).
I have currently hardcoded the ''camera'' to be at 0, 0, -250 (and am then defining by test data at the origin. I want to use a view matrix and a world matrix to tansform data so i can properly move about.
Once I have a view matrix, and a world matrix, what exactly do I need to do with them? I presume I need to multiply them together, and then multiply verticies by the result to find their position? Is this correct? How do you multiply a vertex by a matrix?
Thanks for your time,
Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
void Rotate3d( float yaw,float pitch,float roll )
{
register int ii;
float px,py,pz;
float a,b,c,d,e,f,g,h,i;
float cosx,cosy,cosz,sinx,siny,sinz;
yaw *=__DEGTORAD;
pitch*=__DEGTORAD;
roll *=__DEGTORAD;
sinx=(float) sin( yaw );
siny=(float) sin( pitch );
sinz=(float) sin( roll );
cosx=(float) cos( yaw );
cosy=(float) cos( pitch );
cosz=(float) cos( roll );
a=cosy*cosz;
b=cosy*sinz;
c=-siny;
d=sinx*siny*cosz-cosx*sinz;
e=sinx*siny*sinz+cosx*cosz;
f=sinx*cosy;
g=cosx*siny*cosz+sinx*sinz;
h=cosx*siny*sinz-sinx*cosz;
i=cosx*cosy;
for ( ii=0; ii<(int)(items); ii+=stride)
{
px=array[ii ];
py=array[ii+1];
pz=array[ii+2];
array[ii ]=a*px+b*py+c*pz+tx;
array[ii+1]=d*px+e*py+f*pz+ty;
array[ii+2]=g*px+h*py+i*pz+tz;
}
}
assuming you store your vertex data in contiguous memory
if not just replace in the px=..... equation your x position
and do the same for y and z note that the object is centered in its local system at 0,0,0 , tx,ty,tz is the translated position
{
register int ii;
float px,py,pz;
float a,b,c,d,e,f,g,h,i;
float cosx,cosy,cosz,sinx,siny,sinz;
yaw *=__DEGTORAD;
pitch*=__DEGTORAD;
roll *=__DEGTORAD;
sinx=(float) sin( yaw );
siny=(float) sin( pitch );
sinz=(float) sin( roll );
cosx=(float) cos( yaw );
cosy=(float) cos( pitch );
cosz=(float) cos( roll );
a=cosy*cosz;
b=cosy*sinz;
c=-siny;
d=sinx*siny*cosz-cosx*sinz;
e=sinx*siny*sinz+cosx*cosz;
f=sinx*cosy;
g=cosx*siny*cosz+sinx*sinz;
h=cosx*siny*sinz-sinx*cosz;
i=cosx*cosy;
for ( ii=0; ii<(int)(items); ii+=stride)
{
px=array[ii ];
py=array[ii+1];
pz=array[ii+2];
array[ii ]=a*px+b*py+c*pz+tx;
array[ii+1]=d*px+e*py+f*pz+ty;
array[ii+2]=g*px+h*py+i*pz+tz;
}
}
assuming you store your vertex data in contiguous memory
if not just replace in the px=..... equation your x position
and do the same for y and z note that the object is centered in its local system at 0,0,0 , tx,ty,tz is the translated position
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement