#include "ps_object.hpp" void CDrawableObject::draw( GsOT& h) { ; } C3DObject::C3DObject( ) : CDrawableObject() { m_startVector.vx = 0; m_startVector.vy = 0; m_startVector.vz = ONE; } void C3DObject::ResetRotation( ) { // initialise rotation rotation.vx = rotation.vy = rotation.vz = 0 ; // Reset the coord system to the identity matrix gsObjectCoord.coord.m[0][0]=gsObjectCoord.coord.m[1][1]=gsObjectCoord.coord.m[2][2]=ONE; gsObjectCoord.coord.m[0][1]=gsObjectCoord.coord.m[0][2]=gsObjectCoord.coord.m[1][0]=0; gsObjectCoord.coord.m[1][2]=gsObjectCoord.coord.m[2][0]=gsObjectCoord.coord.m[2][1]=0; } void C3DObject::initCords( ) { // initialise the players coordinate system - set to be that of the world GsInitCoordinate2( WORLD, &gsObjectCoord ) ; // Assign the coordinates of the object model to the Object Handler //coord2 = (GsCOORDINATE2*)this;//&thePlayer->gsObjectCoord; gsObjectHandler.coord2 = &gsObjectCoord; //gsObjectHandler.attribute = 0x50; gsObjectHandler.attribute |= GsDIV1; } inline void C3DObject::invalidate( ) { // setting the gsObjectCoord.flg to 0 indicates it is to be // drawn gsObjectCoord.flg = 0; } /* inline const char* C3DObject::name( ) const { return m_pstrName ; } */ void C3DObject::Setposition(const long X,const long Y,const long Z ) { gsObjectCoord.coord.t[2] = Z ; gsObjectCoord.coord.t[1] = Y ; gsObjectCoord.coord.t[0] = X ; invalidate( ) ; } void C3DObject::position(const long X,const long Y,const long Z ) { gsObjectCoord.coord.t[2] += Z ; gsObjectCoord.coord.t[1] += Y ; gsObjectCoord.coord.t[0] += X ; invalidate( ) ; } void C3DObject::setY(const long Y) { gsObjectCoord.coord.t[1] = Y ; invalidate( ) ; } void C3DObject::position( const CCord& c ) { position( c.x( ) , c.y( ), c.z( ) ) ; } inline const u_long C3DObject::model( ) const { return m_lModel ; } /* void C3DObject::name( const char* cpstrName ) { m_pstrName = (char*)cpstrName ; // will change this when a CString class arrives } */ void C3DObject::model( const u_long lModelAddress ) { m_lModel = lModelAddress ; u_long* pModel = (u_long*) model( ) ; //increment the pointer to past the model id. (weird huh?) // map tmd data to its actual address GsMapModelingData( pModel + MODEL_MAP_OFFSET ) ; // increment pointer twice more - to point to top of model data (beats me!) // and link the model (tmd) with the players object handler GsLinkObject4( ( u_long ) ( pModel + MODEL_DATA_OFFSET ) , // this,//&thePlayer->gsObjectHandler, &gsObjectHandler, 0 ) ; } // This function deals with setting up matrices needed for rendering // and sends the object to the ordering table so it is drawn void C3DObject::draw( GsOT& header ) { MATRIX tmpls,tmplw; //GsDOBJ2* tmpPtr; // Set The Local World/Screen MATRIX GsGetLws(gsObjectHandler.coord2,&tmplw,&tmpls ) ; GsSetLightMatrix( &tmplw ) ; GsSetLsMatrix( &tmpls ) ; //tmpPtr = (GsDOBJ2*) this ; // Send Object To Ordering Table GsSortObject4(&gsObjectHandler,&header , 4,//14 - ORDERING_TABLE_LENGTH, ( u_long* ) getScratchAddr( 0 ) ) ; } void C3DObject::advance( int nSpeed ) { // Moves the model nD units in the direction of its rotation vector MATRIX matTmp; SVECTOR startVector; SVECTOR currentDirection; // if nD = 0 there is no movement and we need to avois the // main body of the function which will cause a divide by zero error if( nSpeed ) { // set up original vector, pointing down the positive z axis startVector = m_startVector ; // RotMatrix sets up the matrix coefficients for rotation //RotMatrix( (SVECTOR*)this ,//rotateVector, RotMatrix( &rotation,&matTmp ) ; // multiply startVector by mattmp and put the result in currentDirection // which is the vector defining the direction the player is pointing ApplyMatrixSV(&matTmp,&startVector,¤tDirection); // currentDirection components have a maximum value of 4096 so we // scale nD to 4096 /nD then when we add the amount of // translation we divide by nD. This ensures that we will translate // the number of units originally specified by nD // nD = 4096 /nD ; gsObjectCoord.coord.t[0] +=(currentDirection.vx * nSpeed ) / 4096; gsObjectCoord.coord.t[1] +=(currentDirection.vy * nSpeed ) / 4096; gsObjectCoord.coord.t[2] +=(currentDirection.vz * nSpeed ) / 4096; // Because It Has Changed, 0 Means that we will redraw it invalidate( ) ; } //if speed } void C3DObject::strafe( int nSpeed ) { // Moves the model nD units in the direction of its rotation vector MATRIX matTmp; SVECTOR startVector; SVECTOR currentDirection; // if nD = 0 there is no movement and we need to avois the // main body of the function which will cause a divide by zero error if( nSpeed ) { // set up original vector, pointing down the positive z axis startVector = m_startVector ; // RotMatrix sets up the matrix coefficients for rotation //RotMatrix( (SVECTOR*)this ,//rotateVector, RotMatrix( &rotation,&matTmp ) ; RotMatrixY(1024,&matTmp) ; // multiply startVector by mattmp and put the result in currentDirection // which is the vector defining the direction the player is pointing ApplyMatrixSV(&matTmp,&startVector,¤tDirection); // currentDirection components have a maximum value of 4096 so we // scale nD to 4096 /nD then when we add the amount of // translation we divide by nD. This ensures that we will translate // the number of units originally specified by nD // nD = 4096 /nD ; gsObjectCoord.coord.t[0] +=(currentDirection.vx * nSpeed ) / 4096; gsObjectCoord.coord.t[1] +=(currentDirection.vy * nSpeed ) / 4096; gsObjectCoord.coord.t[2] +=(currentDirection.vz * nSpeed ) / 4096; // Because It Has Changed, 0 Means that we will redraw it invalidate( ) ; } //if speed } void C3DObject::rotate( int x,int y,int z ) { MATRIX matTmp; // Reset the coord system to the identity matrix gsObjectCoord.coord.m[0][0]=gsObjectCoord.coord.m[1][1]=gsObjectCoord.coord.m[2][2]=ONE; gsObjectCoord.coord.m[0][1]=gsObjectCoord.coord.m[0][2]=gsObjectCoord.coord.m[1][0]=0; gsObjectCoord.coord.m[1][2]=gsObjectCoord.coord.m[2][0]=gsObjectCoord.coord.m[2][1]=0; // Add the new rotation factors into the players rotation vector // and then set them to the remainder of division by ONE (4096) rotation.vx = (rotation.vx+x)%ONE; rotation.vy = (rotation.vy+y)%ONE; rotation.vz = (rotation.vz+z)%ONE; // RotMatrix sets up the matrix coefficients for rotation RotMatrix( &rotation,&matTmp ) ; // Concatenate the existing objects matrix with the rotation matrix MulMatrix0( &gsObjectCoord.coord, &matTmp,&gsObjectCoord.coord ) ; // set the flag to redraw the object invalidate( ) ; }