Advertisement

Rotations and translations and all that good stuff

Started by May 26, 2000 12:26 AM
2 comments, last by INVERSED 24 years, 7 months ago
Hey all, I think I''m having a math issue here, Whenever I trnslate or rotate anything with my code, the world moves flat. I''m posting my matrix code and all that good stuff, maybe someone can help me with this. Thanx in advance

==========MATRIX STRUCT============================

struct _MATRIX
{
	//constructors for identity matrix and
       //operators for +, +=, -, -=, *, *= are in here
      //and conversion to float* for glLoadMatrix
	float x1, x2, x3, x4
	float y1, y2, y3, y4;
	float z1, z2, z3, z4;
	float tx, ty, tz, t0;

} typedef MATRIX, *LPMATRIX;


==============The camera''s rotation function==============
MATRIX rot_matx, rot_maty, rot_matz;

	//the trig tables are based on tenths so adjust for that
	x *= trig_percision;
	y *= trig_percision;
	z *= trig_percision;

	//set it for and x rot
	rot_matx.y2 = cos_t[ x ];
	rot_matx.z2 = -sin_t[ x ];
	rot_matx.y3 = sin_t[ x ];
	rot_matx.z3 = cos_t[ x ];

	//set it for and y rot
	rot_maty.x1 = cos_t[ y ];
	rot_maty.z1 = sin_t[ y ];
	rot_maty.x3 = -sin_t[ y ];
	rot_maty.z3 = cos_t[ y ];

	//set it for a z rotate
	rot_matz.x1 = cos_t[ z ];
	rot_matz.y1 = -sin_t[ z ];
	rot_matz.x2 = sin_t[ z ];
	rot_matz.y2 = cos_t[ z ];

	rot_matx *= rot_maty;
	rot_matx *= rot_matz;

	matrix *= rot_matx;

//by the way, the sin_t and cos_t are lut''s, x, y, and z are in degrees as are the lut''s.


==================The translate function==================

MATRIX mat;
	mat.tx = x;
	mat.ty = y;
	mat.tz = z;

	matrix *= mat;

=================Caluculating the view matrix===============

//create the perspective matrix
	float fovw = fov/2;
	fovw *= trig_percision;
	perspective.x1 = cot_t[ fovw ];

	float fovh = fov/ratio/2;
	fovh *= trig_percision;
	perspective.y2 = cot_t[ fovh ];

	float Q;
	Q = Far/ ( Far-Near );
	perspective.z3 = Q;

	perspective.z4 = 1;

	perspective.tz = -Q*Near;

//taken from the D3D docs, the perspective matrix for the 
//camera is caculated when the camera is made

==================The Render prep call======================
c_view *= Cameras[c_camera]->GetPerspective();
	Renderer->LoadMatrix( c_view );	

//This multiplies the camera''s current matrix (c_view) by
//the perspective matrix, then that matrix is shuffled of 
//to the renderer where it is glLoadMatrix()''ed.  Am I doing anything wronmg, why is my world flat?  Thank you to anyone who can help.
    
Dare To Think Outside The Box _____________________________ |____________________________| http://www.inversestudios.com
Write more poetry.http://www.Me-Zine.org
Does your MATRIX struct initialize the values to an identity matrix? Otherwise you may be corrupting the data when you multiply matrix by mat in your translation function.
Advertisement
Yup, that''s what the constructor of the matrix does. Even if it''s not a math problem, are there any other things that it might be? here, I''ll put up the exe so people can see what''s happening.

http://www.inversestudios.com/inverse/nervetest.zip

Dare To Think Outside The Box
_____________________________
|____________________________|
http://www.inversestudios.com
Write more poetry.http://www.Me-Zine.org
Ask witchlord. He''s like the gamedev matrixlord or mathlord.

This topic is closed to new replies.

Advertisement