CIwFMat Physics::GetMatrixFromWheelInfo( const btWheelInfo w, const btRigidBody* b )
{
	CIwFMat modelMatrix( CIwMat::g_Identity );

	const btTransform btTrans = w.m_worldTransform;
	const btVector3 pos = btTrans.getOrigin();

	const float posX = pos.getX();
	const float posY = pos.getY();
	const float posZ = pos.getZ();

	const CIwFVec3 position( posX, posY, posZ );

	const btQuaternion q = btTrans.getRotation();
	CIwFVec3 rot;
	QuaternionToEuler( q, rot );

	const btQuaternion qBody = b->getOrientation();
	CIwFVec3 rotBody;
	QuaternionToEuler( qBody, rotBody );
	
	CIwFMat mat = CIwFMat::g_Identity;
	mat.PostRotateX( rot.x );
	mat.PostRotateY( -rotBody.y );		// mat.PostRotateY( rot.y ); fix for rotating wheels by y axis, there are glitches after 360 degrees rotating
	mat.PostRotateZ( -rotBody.z );
	
	modelMatrix.CopyRot( mat );
	modelMatrix.SetTrans( position );

	return modelMatrix;
}
CIwFMat Physics::GetMatrixFromStaticdBody( const CIwFVec3 pos, const CIwFVec3 rot )
{
	CIwFMat modelMatrix;

	CIwFMat rotX, rotY, rotZ;
	rotX.SetRotX( rot.x );
	rotY.SetRotY( rot.y );
	rotZ.SetRotZ( rot.z );
	modelMatrix.CopyRot( rotZ * rotY * rotX );
	modelMatrix.SetTrans( pos );

	return modelMatrix;
}
Ejemplo n.º 3
0
void setupPlayer() {
	Player *player = getGameState()->getPlayer();

	if (!player->isReady()) {
		return;
	}

    // Set viewing position with the Y axis as upright.
    viewMatrix.SetIdentity();
    viewMatrix.LookAt(CIwFVec3(0,-11,0), CIwFVec3(0,0,100), CIwFVec3(0,-1,0));

    // Rotate according to compass heading
	viewMatrix.PostRotateY(rad(player->getHeading()));
    IwGxSetViewMatrix(&viewMatrix);
}
Ejemplo n.º 4
0
void CzPlatformRender::SetModelMatrix(CzMatrix4* mat)
{
	CIwFMat m;
	m.SetIdentity();
	m.m[0][0] = mat->m[0][0];
	m.m[1][0] = mat->m[1][0];
	m.m[2][0] = mat->m[2][0];
	m.m[0][1] = mat->m[0][1];
	m.m[1][1] = mat->m[1][1];
	m.m[2][1] = mat->m[2][1];
	m.m[0][2] = mat->m[0][2];
	m.m[1][2] = mat->m[1][2];
	m.m[2][2] = mat->m[2][2];
	m.t.x = mat->m[0][3];
	m.t.y = mat->m[1][3];
	m.t.z = mat->m[2][3];

	IwGxSetModelMatrix(&m);
}
CIwFMat Physics::GetMatrixFromRigidBody( const btRigidBody* b )
{
	CIwFMat modelMatrix;
	
	btMatrix3x3 mRot;
	btTransform btTrans = b->getWorldTransform();
	btVector3 pos = btTrans.getOrigin();
	mRot = btTrans.getBasis();

	modelMatrix.SetIdentity();

	for( int i = 0, j = 0; i < 3; ++i, j = 0 )
	{
		modelMatrix.m[i][j] = ( mRot.getRow( i ).x() );
		modelMatrix.m[i][++j] = ( mRot.getRow( i ).y() );
		modelMatrix.m[i][++j] = ( mRot.getRow( i ).z() );
	}
	
	modelMatrix.SetTrans( CIwFVec3( pos[0], pos[1], pos[2] ) );

	return modelMatrix;
}
Ejemplo n.º 6
0
void GhostCollision::RenderEctoplasmaBar(float ectoPercent, double ghostRotation)
{
	CIwFMat ectoMatrix = CIwFMat();
	ectoMatrix.CopyRot(*modelMatrix);
	ectoMatrix.CopyTrans(*modelMatrix);
	ectoMatrix.PostRotateY(PI-ghostRotation);

	IwGxSetModelMatrix(&ectoMatrix);
	IwGxSetScreenSpaceSlot(1);

	if (ghostW < 0 || ghostX < 0 || ghostY < 0) ResolveLocation();

	const int16 w = 180;
	const int16 border_x1 = ghostX+ghostW/2 - (float)w*ectobarScale;
	const int16 border_x2 = ghostX+ghostW/2 + (float)w*ectobarScale;

	const float border_y1 = ghostY+0x20;
	const float border_y2 = ghostY+0x20 + (float)0x10*ectobarScale;
	const int16 z = 0x6;

	{
		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);
		pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		pMat->SetTexture(borderTexture);

		int16 x1 = border_x1, x2 = border_x2; 
		float y1 = border_y1, y2 = border_y2;
		border_Verts[0] = CIwFVec3(x1, y2, -z);
		border_Verts[1] = CIwFVec3(x2, y2, -z);
		border_Verts[2] = CIwFVec3(x2, y1, -z);
		border_Verts[3] = CIwFVec3(x1, y1, -z);
		border_Verts[4] = CIwFVec3(x1, y2,  z);
		border_Verts[5] = CIwFVec3(x2, y2,  z);
		border_Verts[6] = CIwFVec3(x2, y1,  z);
		border_Verts[7] = CIwFVec3(x1, y1,  z);

		IwGxSetMaterial(pMat);
		IwGxSetVertStream(border_Verts, 8);
		//IwGxSetColStream(s_Cols, 8);
		IwGxSetUVStream(s_UVs);
		IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4);
	}

	float start_y1 = border_y1 + fabs((float)(border_y2 - border_y1)*0.200);
	float start_y2 = start_y1  + fabs((float)(border_y2 - border_y1)*0.720);
	float startWhScale = (float)((double)startTexture->GetWidth() / startTexture->GetHeight());
	int16 startW = (start_y2 - start_y1) * startWhScale;
	int16 start_x1 = border_x1 + abs((float)(border_x2 - border_x1)*0.0097);
	int16 start_x2 = start_x1 + startW;
	
	{
		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);
		pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		pMat->SetTexture(startTexture);

		int16 x1 = start_x1, x2 = start_x2;
		float y1 = start_y1, y2 = start_y2;
		start_Verts[0] = CIwFVec3(x1, y2, -z);
		start_Verts[1] = CIwFVec3(x2, y2, -z);
		start_Verts[2] = CIwFVec3(x2, y1, -z);
		start_Verts[3] = CIwFVec3(x1, y1, -z);
		start_Verts[4] = CIwFVec3(x1, y2,  z);
		start_Verts[5] = CIwFVec3(x2, y2,  z);
		start_Verts[6] = CIwFVec3(x2, y1,  z);
		start_Verts[7] = CIwFVec3(x1, y1,  z);

		IwGxSetMaterial(pMat);
		IwGxSetVertStream(start_Verts, 8);
		//IwGxSetColStream(s_Cols, 8);
		IwGxSetUVStream(s_UVs);
		IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4);
	}

	float end_y1 = start_y1;
	float end_y2 = start_y2;
	float endWhScale = (float)((double)endTexture->GetWidth() / endTexture->GetHeight());
	int16 endW = (end_y2 - end_y1) * endWhScale;

	int endMaxX = border_x2 - abs((float)(border_x2 - border_x1)*0.0097) - endW;
	int endMinX = start_x2;
	int16 end_x1 = (double)(endMaxX - endMinX)*ectoPercent + endMinX;
	int16 end_x2 = end_x1 + endW;
	
	{
		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);
		pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		pMat->SetTexture(endTexture);

		int16 x1 = end_x1, x2 = end_x2;
		float y1 = end_y1, y2 = end_y2;
		end_Verts[0] = CIwFVec3(x1, y2, -z);
		end_Verts[1] = CIwFVec3(x2, y2, -z);
		end_Verts[2] = CIwFVec3(x2, y1, -z);
		end_Verts[3] = CIwFVec3(x1, y1, -z);
		end_Verts[4] = CIwFVec3(x1, y2,  z);
		end_Verts[5] = CIwFVec3(x2, y2,  z);
		end_Verts[6] = CIwFVec3(x2, y1,  z);
		end_Verts[7] = CIwFVec3(x1, y1,  z);

		IwGxSetMaterial(pMat);
		IwGxSetVertStream(end_Verts, 8);
		//IwGxSetColStream(s_Cols, 8);
		IwGxSetUVStream(s_UVs);
		IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4);
	}
	
	float center_y1 = start_y1;
	float center_y2 = start_y2;
	int16 center_x1 = start_x2 - 1;
	int16 center_x2 = end_x1 + 1;
	
	{
		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);
		pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		pMat->SetTexture(centerTexture);

		int16 x1 = center_x1, x2 = center_x2; 
		float y1 = center_y1, y2 = center_y2;
		center_Verts[0] = CIwFVec3(x1, y2, -z);
		center_Verts[1] = CIwFVec3(x2, y2, -z);
		center_Verts[2] = CIwFVec3(x2, y1, -z);
		center_Verts[3] = CIwFVec3(x1, y1, -z);
		center_Verts[4] = CIwFVec3(x1, y2,  z);
		center_Verts[5] = CIwFVec3(x2, y2,  z);
		center_Verts[6] = CIwFVec3(x2, y1,  z);
		center_Verts[7] = CIwFVec3(x1, y1,  z);

		IwGxSetMaterial(pMat);
		IwGxSetVertStream(center_Verts, 8);
		//IwGxSetColStream(s_Cols, 8);
		IwGxSetUVStream(s_UVs);
		IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4);
	}
	
}