예제 #1
0
void Player::Update(inputState& a_state, float a_dt, float &a_rot, float &a_angle,Limbase part_list) {
	float tempfloat;

	//check alive
	if(alive) {
		//do if alive
		pos.x = prospectivePos.x;
		pos.y = prospectivePos.y;
		pos.z = prospectivePos.z;


		////////////////////////////////////////
		// Takes inputs, sets prospective pos //
		////////////////////////////////////////



		tempfloat = a_state.lX;
		velocityXZ.x = tempfloat*a_dt*speed;

		tempfloat = a_state.lY;
		velocityXZ.y = tempfloat*a_dt*speed;

		tempfloat = a_state.rX;
		a_rot += (tempfloat*a_dt)*turnspeedX;
		tempfloat = a_state.rY;
		a_angle -= (tempfloat*a_dt)*turnspeedY; // minus to uninvert it
		if(a_angle >= 90)
			a_angle = 89.9f;
		else if(a_angle <=-90)
			a_angle = -89.9f;

		velocityY -= 0.3f*a_dt;
		if(velocityY < -terminalVelocity)
			velocityY = -terminalVelocity;
		if(velocityY > terminalVelocity)
			velocityY = terminalVelocity;
		//if(pos.y <= 0 && velocityY <= 0)
		//	velocityY = 0;
		/////////////////////////////////////
		//////////PLAYER CONTROLS////////////
		/////////////////////////////////////

		// need to deal with object for bullet 
		/*if(a_state.buttons[binds::leftAttack]&&!a_state.buttonLast[binds::leftAttack]) { 
			D3DXVECTOR3 tempvec = getPos();
			tempvec.y += 1.5f;
			a_bulvec.ActivateABullet(tempvec,D3DXVECTOR3(0,0,-BulletSpeed),testCube4.primInfo,a_rot,a_angle,RangedDefaultLifeSpan, testDamage);
		}
		if(a_state.buttons[binds::rightAttack]&&!a_state.buttonLast[binds::rightAttack]) { 
			D3DXVECTOR3 tempvec = getPos();
			tempvec.y += 1.5f;
			a_bulvec.ActivateABullet(tempvec,D3DXVECTOR3(0,0,-BulletSpeed),testCube4.primInfo,a_rot,a_angle,MeleeDefaultLifeSpan, testDamage);
		}
*/
		if(a_state.buttons[binds::jump] && onGround) {
			velocityY = 0.2f;
			onGround = false;
		}
		if(a_state.buttons[binds::legPower]&&!a_state.buttonLast[binds::legPower]) {
			//get part !0 
			if (!Limbs.getLeg()==0){
				part_list.CaseAction(Limbs.getLeg(),*this,a_state);
				// find that part 
				// execute that function
			}
		}
		if(a_state.buttons[binds::use]) {
			//if item is coliding with character
			if(getcheckItem()){
				addLimb(ProsteticTestLimb);
			}
			// make bool switch here.
			//
			//bring menue up 
			// 
		}



		facing = D3DXToRadian(a_rot);

		//D3DXMATRIX matrixlovetemptest;
		//D3DXVECTOR2 tempveloc = velocityXZ;
		//float templength = D3DXVec2Length(&velocityXZ);
		//D3DXVec2Normalize(&velocityXZ,&velocityXZ);
		//D3DXMatrixTransformation2D(&matrixlovetemptest,NULL,NULL,NULL,&D3DXVECTOR2(pos.x,pos.z),facing,&velocityXZ);
		//D3DXVECTOR4 matrixtemplove4;
		//D3DXVec2Transform(&matrixtemplove4, &velocityXZ, &matrixlovetemptest);

		//velocityXZ.x = matrixtemplove4.x;
		//velocityXZ.y = matrixtemplove4.y;
		//D3DXVECTOR2 tempveloc = velocityXZ;
		//if(D3DXVec2Length(&velocityXZ) >= maxSpeed)
		//	velocityXZ = tempveloc;
		rotate2Dvector(&velocityXZ,-facing);

		prospectivePos.x += velocityXZ.x;
		prospectivePos.y += velocityY;
		prospectivePos.z += velocityXZ.y;


		//if() {
		//	onGround = true;
		//	velocityY = 0;
		//}
		//else {
		//	onGround = false;
		//}
		if(curHealth <= 0) {
			alive = false;
			timer = 3;
		}
	} else {
		//do if dead
		if(timer>=0) {
			timer -= a_dt;
		}
	}

}
예제 #2
0
파일: Camera.cpp 프로젝트: iceberry/flyffsf
void CBackCamera::Process( LPDIRECT3DDEVICE9 pd3dDevice ,float fFactor )
{
#ifdef __CLIENT
	CMover *pMover = CMover::GetActiveMover();
	// 여기서 카메라 세팅!!!!!
	if( pMover == NULL )	return;

	CWorld* pWorld = pMover->GetWorld();
	if( pWorld == NULL )
		return;
	D3DXMATRIX matView, mat;

	FLOAT fAngle = 0, fAngleY = 0;

	D3DXVECTOR3 vPos = pMover->GetPos();
	
	vPos.y += 0.9f;
#if __VER >= 13 // __HOUSING
	if(m_nCamMode == CM_MYROOM)
	{
		if(m_fZoom <= 0.5f) m_fZoom = 0.5f;
	//	if(m_fZoom >= 3.0f) m_fZoom = 3.0f;
	}
#endif // __HOUSING
	CMover* pMoverTarget = (CMover*)g_WorldMng.Get()->GetObjFocus() ;
	D3DXVECTOR3 vTarget,vTemp;
	if( pMoverTarget && pMover->m_pActMover->IsFly() && (pMover->m_dwFlag & MVRF_TRACKING) ) 
	{	// 날고 있는 경우 타겟이 있다면
		// 타겟쪽으로 카메라 방향을 수정한다.
		vTemp = vPos - pMoverTarget->GetPos();
		if( vTemp.z > 0 ) 
		{
			fAngle =- (float)( atan( vTemp.x / vTemp.z ) * 180 / 3.1415926f );
		}
		else 
		{
			fAngle =- (float)( atan( vTemp.x / vTemp.z ) * 180 / 3.1415926f ) + 180;
		}
		D3DXVECTOR3	vDistXZ = vTemp;
		vDistXZ.y = 0;
		float fDistSq = D3DXVec3Length( &vDistXZ );		// XZ평면에서의 길이
		fAngleY = atan2( fDistSq, vTemp.y/* * vTemp.y*/ );
		fAngleY = D3DXToDegree( fAngleY );

		float fReg1 = vTemp.y / 40.0f;
		if( fReg1 > 0 )
		{
			if( fReg1 >= 2.0f )	fReg1 = 2.0f;
		} else
		if( fReg1 < 0 )
		{
			if( fReg1 <= -2.0f )	fReg1 = -2.0f;
		}

		m_fCurRoty = m_fRoty + m_fZoom * fReg1;
		if( m_bLock )
			fAngle = 0;

	}
	else 
	{
		fAngle = pMover->GetAngle();
		if( m_bLock )
			fAngle = 0;
		fAngleY = 90.0f;

		m_fCurRoty = m_fRoty + m_fZoom * 4;
	}
	m_vLookAt = vPos;

#ifdef __Y_CAMERA_SLOW_8
	if( !g_WndMng.m_pWndWorld->m_bRButtonDown && ( !g_bKeyTable[ VK_LEFT ] && !g_bKeyTable[ VK_RIGHT ] ) )
	{
		static FLOAT fSpeed = 2.0f;
		BOOL  bLeft = FALSE;
		BOOL  bRight = FALSE;
		FLOAT fTemp = 0.0f;

		fTemp = m_fRotx;

		if( (GetAnglePie(fTemp) == 1 && GetAnglePie(m_fCurRotx) == 4) )
			bRight = TRUE;

		if( (GetAnglePie(fTemp) == 4 && GetAnglePie(m_fCurRotx) == 1) )
			bLeft = TRUE;

		if( bRight )
		{
			m_fCurRotx += m_fRotx;

			if( m_fCurRotx < fTemp )
			{
				m_fCurRotx += fSpeed;
			}

			m_fCurRotx -= m_fRotx;

			if( m_fCurRotx >= 0.0f )
			{
				m_fCurRotx = -360.0f;
			}
		}

		if( bLeft )
		{
			fTemp += -360.0f;
			
			if( m_fCurRotx > fTemp )
			{
				m_fCurRotx += -fSpeed;

				if( m_fCurRotx < -360.0f )
					m_fCurRotx = 0.0f;
			}

			fTemp -= -360.0f;
		}

		if( !bLeft && !bRight )
		{
			FLOAT fGoal = fabs(m_fCurRotx - fTemp);
			if( m_fCurRotx < fTemp )
			{
				if( fGoal > fSpeed )
					m_fCurRotx += fSpeed;
			}
			else
			{
				if( fGoal > fSpeed )
					m_fCurRotx -= fSpeed;
			}
		}
	}
	else
	{
		m_fCurRotx = m_fRotx;
	}

#else //__Y_CAMERA_SLOW_8
	m_fCurRotx = m_fRotx;
#endif //__Y_CAMERA_SLOW_8

#ifdef __XUZHU
	_g_fReg[0] = fAngleY;
#endif
	
	float fAdjAng = (1.0f - fAngleY / 90.0f) * 45.0f;
	m_fCurRoty += fAdjAng;
	m_fCurRoty += pMover->GetAngleX();
	
	if( pMover->m_pActMover->IsFly() )	// 비행할땐 조금 들어주자
		m_fCurRoty += 0.0f;
	if( m_fCurRoty > 80.0f ) 
		m_fCurRoty = 80.0f;

#if __VER >= 13 // __HOUSING
	if(m_nCamMode == CM_MYROOM)
	{
		if(m_fCurRoty <= 10.0f) 
		{
			m_fCurRoty = 10.0f;
			if(m_fRoty > 0.0f) m_fRoty = 0.0f;
			if(m_fRoty < -30.0f) m_fRoty = -30.0f;
		}
	}
#endif // __HOUSING

	fAngle = m_fCurRotx - fAngle + 180.0f;

	D3DXMATRIX matTemp;
	// zoom 상태에 따라 카메라 위치를 조정
	extern float fDiv;
	
	if( fDiv == 2.0f )
		//vTemp = D3DXVECTOR3( 0.0f, 0.0f, -0.0f - (m_fZoom / 2.0f) * 2.0f );
		vTemp = D3DXVECTOR3( 0.0f, 0.0f, -0.0f - 2.0f );
	else
	{
		if( g_pShip )
			vTemp = D3DXVECTOR3( 0.0f, 0.0f, -4.0f - m_fZoom * 16.0f );
		else
			//vTemp = D3DXVECTOR3( 0.0f, 0.0f, -50.0f );
			vTemp = D3DXVECTOR3( 0.0f, 0.0f, -4.0f - m_fZoom * 2.0f );
	}
	
	D3DXVECTOR3 vecOut;
	D3DXMatrixRotationX( &matTemp, D3DXToRadian( m_fCurRoty / 1.0f ) );
	D3DXVec3TransformCoord( &vTemp, &vTemp, &matTemp );
	D3DXMatrixRotationY( &matTemp, D3DXToRadian( fAngle ) );
	D3DXVec3TransformCoord( &m_vOffsetDest, &vTemp, &matTemp );

	D3DXVECTOR3 vecOffsetDelta = ( ( m_vOffsetDest - m_vOffset ) + m_vPosVal ) / fFactor;

	m_vOffset += vecOffsetDelta;

	m_vPosVal /= 2;

	m_vPos = vPos + m_vOffset;

	BOOL  bCrash;
	FLOAT fLength;
	static D3DXVECTOR3 m_vLimitPos;
	D3DXVECTOR3 m_vOutPos = m_vPos;

	m_vLookAt.y += 0.4f;
#if __VER >= 11 // __GUILD_COMBAT_1TO1
	if( g_pPlayer && g_GuildCombat1to1Mng.IsPossibleMover( g_pPlayer ) )
		bCrash = FALSE;
	else
		bCrash = pWorld->CheckBound( &m_vPos, &m_vLookAt, &m_vOutPos, &fLength );
#else //__GUILD_COMBAT_1TO1
	bCrash = pWorld->CheckBound( &m_vPos, &m_vLookAt, &m_vOutPos, &fLength );
#endif //__GUILD_COMBAT_1TO1

	// 충돌이있다면 마지막으로 충돌했던 거리를 저장
	if( bCrash )
		m_fLength2 = fLength;

	// 전프레임에 충돌, 현재는 충돌이 아닐때...즉, 서서히 뒤로 가게하는 시점..
	if( m_bOld && bCrash == FALSE )
	{
		m_fLength1 = fLength;
		m_bStart = TRUE;
	}

	if( m_bStart )
	{
		D3DXVECTOR3 vCPos = vPos + m_vOffset;
		D3DXVECTOR3 vDir  = vCPos - m_vLookAt;
		D3DXVec3Normalize(&vDir, &vDir);
#if __VER >= 12 // __CAM_FAST_RECOVER
		m_fLength2 += 0.37f;
#else
		m_fLength2 += 0.07f;
#endif
		if( m_fLength2 > fLength )
			m_bStart = FALSE;

		m_vOutPos = m_vLookAt + (vDir * m_fLength2);
	}
	else
	if( bCrash )
	{/*
		if( fLength < 5.0f )
		{
			D3DXVECTOR3 vCPos = vPos + m_vOffset;
			D3DXVECTOR3 vDir  = vCPos  - m_vLookAt;
			D3DXVec3Normalize(&vDir, &vDir);
			
			FLOAT fff = m_vOutPos.y;
			m_vOutPos = m_vLookAt + (vDir * 5.0f);
			m_vOutPos.y = fff;
		}
	 */
	}

	m_bOld = bCrash;

	g_ModelGlobal.SetCamera( m_vOutPos, m_vLookAt );

	m_vPos = m_vOutPos;
#endif // CLIENT
}
예제 #3
0
파일: WinMain.cpp 프로젝트: cam01589/3DProg
// this is the function used to render a single frame
void RenderFrame(void)
{
	int const bufferSizes = 2;
    CBUFFER cBuffer[bufferSizes];

    for( int i = 0; i < bufferSizes; i++ )
	{
		cBuffer[i].LightVector  = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 0.0f);
		cBuffer[i].LightColor   = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
		cBuffer[i].AmbientColor = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
	}

    D3DXMATRIX matRotateY[bufferSizes], matView, matRotateZ[bufferSizes], matProjection, matTranslate[5], matRotateX[5], D3DXMatrixScaling;
    D3DXMATRIX matFinal[5];

	for( int i = 0; i < bufferSizes; i++) // 0 - 3
	{
		matFinal[i] = matTranslate[i] * matRotateZ[i] * matRotateY[i];// * matView * matProjection;
	}

    static float Time = 0.0f; Time += 0.0003f;

   // create a world matrices
	for( int i = 0; i < bufferSizes; i ++ )
	{
		D3DXMatrixRotationY(&matRotateY[i], Time);
		
	}

	D3DXMatrixTranslation(&matTranslate[0], 0.5f, 0.5f, 0.0f );
	D3DXMatrixTranslation(&matTranslate[1], -1.0f, -1.0f, -0.0f );

    // create a view matrix
    D3DXMatrixLookAtLH(&matView,
                       &D3DXVECTOR3(0.0f, 3.0f, 5.0f),    // the camera position
                       &D3DXVECTOR3(0.0f, 0.0f, 0.0f),    // the look-at position
                       &D3DXVECTOR3(0.0f, 1.0f, 0.0f));   // the up direction

    // create a projection matrix
    D3DXMatrixPerspectiveFovLH(&matProjection,
                               (FLOAT)D3DXToRadian(45),                    // field of view
                               (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
                               1.0f,                                       // near view-plane
                               100.0f);                                    // far view-plane

    /// load the matrices into the constant buffer
    cBuffer[0].Final = matRotateY[0] * matTranslate[0] * matView * matProjection ;
    cBuffer[0].Rotation = matRotateY[0];


	// load the matrices into the constant buffer
    cBuffer[1].Final =  matRotateY[1] * matTranslate[1] * matView * matProjection;
    cBuffer[1].Rotation = matRotateY[1];

    // set the various states
    devcon->RSSetState(pRS);
    devcon->PSSetSamplers(0, 1, &pSS);
    devcon->OMSetBlendState(pBS, 0, 0xffffffff);

    // clear the back buffer to a deep blue
    devcon->ClearRenderTargetView(backbuffer,  D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f));//D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));

    // clear the depth buffer
    devcon->ClearDepthStencilView(zbuffer, D3D11_CLEAR_DEPTH, 1.0f, 0);

        // select which vertex buffer to display
        UINT stride = sizeof(VERTEX);
        UINT offset = 0;
        devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);
        devcon->IASetIndexBuffer(pIBuffer, DXGI_FORMAT_R32_UINT, 0);

        // select which primtive type we are using
        devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

       // draw the Hypercraft
        devcon->UpdateSubresource(pCBuffer, 0, 0, &cBuffer[0], 0, 0);
        devcon->PSSetShaderResources(0, 1, &pTexture);
        devcon->DrawIndexed(36, 0, 0);

		// draw the Hypercraft
        devcon->UpdateSubresource(pCBuffer, 0, 0, &cBuffer[1], 0, 0);
        devcon->PSSetShaderResources(0, 1, &pTexture);
        devcon->DrawIndexed(36, 0, 0);

    // switch the back buffer and the front buffer
    swapchain->Present(0, 0);
}
예제 #4
0
Point Tank::CalcBulletPos()
{
	const int dist = 100;
	return _Head->GetPosition() + Point(cos(D3DXToRadian(_DegreeAngle)) * dist, sin(D3DXToRadian(_DegreeAngle)) * dist);
}
예제 #5
0
//-----------------------------------------------------------
// Name: InputHandler()
// Desc: The input message handler
//-----------------------------------------------------------
void GameLoader::InputHandler(MSG msg)
{
	static POINT ptLastMousePosit;
	static POINT ptCurrentMousePosit;
	static bool bMousing;
	
	if (msg.message == WM_LBUTTONDOWN)
	{
		ptLastMousePosit.x = ptCurrentMousePosit.x = LOWORD (msg.lParam);
		ptLastMousePosit.y = ptCurrentMousePosit.y = HIWORD (msg.lParam);
		bMousing = true;
	}

	if (msg.message == WM_LBUTTONUP)
	{
		bMousing = false;
	}

	if (msg.message == WM_MOUSEMOVE)
	{
		ptCurrentMousePosit.x = LOWORD (msg.lParam);
		ptCurrentMousePosit.y = HIWORD (msg.lParam);

		if( bMousing )
		{
			tank->Rotate(D3DXToRadian((ptCurrentMousePosit.x - ptLastMousePosit.x)));
		}

		ptLastMousePosit.x = ptCurrentMousePosit.x;
		ptLastMousePosit.y = ptCurrentMousePosit.y;
	}

	// Tank Move
	if ((::GetAsyncKeyState('W') & 0x8000f) || (::GetAsyncKeyState(VK_UP) & 0x8000f))
	{
		tank->Move(0, 0, TANK_STEP_UNIT);
	}
	if ((::GetAsyncKeyState('S') & 0x8000f) || (::GetAsyncKeyState(VK_DOWN) & 0x8000f))
	{
		tank->Move(0, 0, -TANK_STEP_UNIT);
	}
	if ((::GetAsyncKeyState('A') & 0x8000f) || (::GetAsyncKeyState(VK_LEFT) & 0x8000f))
	{
		tank->Move(-TANK_STEP_UNIT, 0, 0);
	}
	if ((::GetAsyncKeyState('D') & 0x8000f) || (::GetAsyncKeyState(VK_RIGHT) & 0x8000f))
	{
		tank->Move(TANK_STEP_UNIT, 0, 0);
	}
	// Tank Shoot
	if (::GetAsyncKeyState('F'))
	{
		if (CheckPresskeyGapTime())
		{
			bulletList.push_back(tank->Shoot());
		}
	}
	// Create random enemy
	if (::GetAsyncKeyState(VK_SPACE))
	{
		if (CheckPresskeyGapTime())
		{
			enemyList.push_back(RandomEnemy());
		}
	}
	// Platform rotate
	if (PLATFORM_ROTATE_MODE)
	{
		platform->Rotate();
		tank->UpdateWorldMat();
	}
}
예제 #6
0
void CDofEditing::OnBnClickedYaw5p()
{
	m_Yaw+=D3DXToRadian(5);
	UpdateAngles();
}
예제 #7
0
void CDofEditing::OnBnClickedRoll5p()
{
	m_Roll+=D3DXToRadian(5);
	UpdateAngles();
}
예제 #8
0
NxActor* CreateCar(const NxVec3& pos)
{
	// Create body
	NxBodyDesc bodyDesc;
	NxBoxShapeDesc boxDesc;
	NxCapsuleShapeDesc capsuleDesc[4];
	NxActorDesc actorDesc;

	bodyDesc.mass = carMass;

	const NxReal height = 0.3;
	const NxReal width = 2;
	const NxReal length = 4;

	//boxDesc.dimensions.set(length*0.65, height*0.85, width*0.65);
	//actorDesc.shapes.pushBack(&boxDesc);

	{
		sObject* pObject = dbGetObject ( 5 );
	
		float fXPos	 = pObject->position.vecPosition.x;
		float fYPos	 = pObject->position.vecPosition.y;
		float fZPos	 = pObject->position.vecPosition.z;
		float fXSize = ( pObject->collision.vecMax.x - pObject->collision.vecMin.x ) * pObject->position.vecScale.x;
		float fYSize = ( pObject->collision.vecMax.y - pObject->collision.vecMin.y ) * pObject->position.vecScale.y;
		float fZSize = ( pObject->collision.vecMax.z - pObject->collision.vecMin.z ) * pObject->position.vecScale.z;

		boxDesc.dimensions.set ( fXSize / 2, fYSize / 2, fZSize / 2 );
		boxDesc.localPose.t = NxVec3 ( pObject->collision.vecCentre.x, pObject->collision.vecCentre.y, pObject->collision.vecCentre.z  );
		//boxDesc.localPose.
		actorDesc.shapes.pushBack ( &boxDesc );
	}

	capsuleDesc[0].radius = 0.1;
	capsuleDesc[0].height = 1;
	capsuleDesc[0].flags = NX_SWEPT_SHAPE;
	capsuleDesc[0].localPose.M.setColumn(1, NxVec3(0,-1, 0));
	capsuleDesc[0].localPose.M.setColumn(2, NxVec3(0, 0,-1));	//rotate 180 degrees around x axis to cast downward!
	capsuleDesc[0].localPose.t.set(length*0.5, -height, width*0.5);
	capsuleDesc[0].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[0].userData = &(wheelUserDatas[0]);
	actorDesc.shapes.pushBack(&capsuleDesc[0]);
	wheelUserDatas[0].frontWheel = true;

	capsuleDesc[1].radius = capsuleDesc[0].radius;
	capsuleDesc[1].height = capsuleDesc[0].height;
	capsuleDesc[1].flags = capsuleDesc[0].flags;
	capsuleDesc[1].localPose.M = capsuleDesc[0].localPose.M;	
	capsuleDesc[1].localPose.t.set(length*0.5, -height, -width*0.5);
	capsuleDesc[1].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[1].userData = &(wheelUserDatas[1]);
	actorDesc.shapes.pushBack(&capsuleDesc[1]);
	wheelUserDatas[1].frontWheel = true;

	capsuleDesc[2].radius = capsuleDesc[0].radius;
	capsuleDesc[2].height = capsuleDesc[0].height;
	capsuleDesc[2].flags = capsuleDesc[0].flags;
	capsuleDesc[2].localPose.M = capsuleDesc[0].localPose.M;
	capsuleDesc[2].localPose.t.set(-length*0.5, -height, -width*0.5);
	capsuleDesc[2].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[2].userData = &(wheelUserDatas[2]);
	actorDesc.shapes.pushBack(&capsuleDesc[2]);
	wheelUserDatas[2].frontWheel = false;

	capsuleDesc[3].radius = capsuleDesc[0].radius;
	capsuleDesc[3].height = capsuleDesc[0].height;
	capsuleDesc[3].flags = capsuleDesc[0].flags;
	capsuleDesc[3].localPose.M = capsuleDesc[0].localPose.M;
	capsuleDesc[3].localPose.t.set(-length*0.5, -height, width*0.5);
	capsuleDesc[3].materialIndex = raycastWheelMaterialIndex;
	capsuleDesc[3].userData = &(wheelUserDatas[3]);
	actorDesc.shapes.pushBack(&capsuleDesc[3]);
	wheelUserDatas[3].frontWheel = false;

	actorDesc.body			= &bodyDesc;
	actorDesc.globalPose.t  = pos;
	NxActor* a = gScene->createActor(actorDesc);

	//a->userData = &carData;		//so we can recoginze it in the contact stream

sPhysObject* pPhys = new sPhysObject;
pPhys->iID = 5;
a->userData = (void*)pPhys;

	//actorDesc.globalPose.t = NxVec3 ( fXPos, fYPos, fZPos );
NxMat33 mat;
mat.rotY ( D3DXToRadian ( 90 ) );
a->setGlobalOrientation ( mat );

	a->wakeUp(1e10);			//don't go to sleep.

	return a;
}
예제 #9
0
void InternalUpdate ( int iID )
{
	// apply any changes to the object e.g. position

	// update internal pointer
	if ( !UpdatePtr ( iID ) )
		return;

	// variable declarations
	D3DXMATRIX	matTranslation;										// translation ( position )
	D3DXMATRIX	matRotation, matRotateX, matRotateY, matRotateZ;	// rotation
	D3DXMATRIX	matScale;											// scale
	bool		bUpdate = false;									// used to update look, up and right vector

	// apply scaling to the object
	D3DXMatrixScaling ( &matScale, m_pPos->vecScale.x, m_pPos->vecScale.y, m_pPos->vecScale.z );
	
	// apply translation to the object
	D3DXMatrixTranslation ( &matTranslation, m_pPos->vecPosition.x, m_pPos->vecPosition.y, m_pPos->vecPosition.z );

	// setup rotation matrices
	if ( m_pPos->bFreeFlightRotation )
	{
// LEEFIX - 0941002 - Should be converted to radians 
//		D3DXMatrixRotationYawPitchRoll ( &matRotation, m_pPos->vecYawPitchRoll.x, m_pPos->vecYawPitchRoll.y, m_pPos->vecYawPitchRoll.z ); 
		D3DXMatrixRotationYawPitchRoll ( &matRotation,	D3DXToRadian ( m_pPos->vecYawPitchRoll.x ),
														D3DXToRadian ( m_pPos->vecYawPitchRoll.y ),
														D3DXToRadian ( m_pPos->vecYawPitchRoll.z ) ); 
	}
	else
	{
		D3DXMatrixRotationX ( &matRotateX, D3DXToRadian ( m_pPos->vecRotate.x ) );	// x rotation
		D3DXMatrixRotationY ( &matRotateY, D3DXToRadian ( m_pPos->vecRotate.y ) );	// y rotation
		D3DXMatrixRotationZ ( &matRotateZ, D3DXToRadian ( m_pPos->vecRotate.z ) );	// z rotation

		// build final rotation matrix
		matRotation = matRotateX * matRotateY * matRotateZ;
	}

	// Apply pivot if any
	if ( m_pPos->bApplyPivot )
	{
		D3DXMatrixRotationX ( &matRotateX, D3DXToRadian ( m_pPos->vecPivot.x ) );	// x rotation
		D3DXMatrixRotationY ( &matRotateY, D3DXToRadian ( m_pPos->vecPivot.y ) );	// y rotation
		D3DXMatrixRotationZ ( &matRotateZ, D3DXToRadian ( m_pPos->vecPivot.z ) );	// z rotation

		// build final rotation matrix
		D3DXMATRIX matPivotRotation = matRotateX * matRotateY * matRotateZ;

		// modify current rotation
		matRotation = matPivotRotation * matRotation;
	}

	// scale first, then rotation, then translation (notran is a quick way of stripping translation for colcenter calc)
	m_pPos->matObjectNoTran = matScale * matRotation;
	m_pPos->matObject = m_pPos->matObjectNoTran * matTranslation;

	
	// now we have to update the look, up and right vector, we do this because
	// when we want to move an object we move it using these vectors so we need
	// to update them to reflect any changes setup by the rotations

	// if any of the rotation values have changed then we must reset the look, up
	// and right vectors to their original states
	// LEEFIX - 171002 - Ensure free flight is seperate from euler
	if( m_pPos->bFreeFlightRotation==false )
	{
		if ( m_pPos->vecLast != m_pPos->vecRotate )
		{
			// save the current rotation vector
			m_pPos->vecLast = m_pPos->vecRotate;

			// regenerate the look, up and right vectors
			m_pPos->vecLook  = D3DXVECTOR3 ( 0, 0, 1 );		// look vector
			m_pPos->vecUp    = D3DXVECTOR3 ( 0, 1, 0 );		// up vector
			m_pPos->vecRight = D3DXVECTOR3 ( 1, 0, 0 );		// right vector
		
			// signal that we need to update the vectors
			bUpdate = true;
		}
	}
	else
	{
		// free flight always applies rotation
		bUpdate = true;
	}

	// only update if there has been a change in rotation
	if ( bUpdate )
	{
		if ( m_pPos->bFreeFlightRotation )
		{
			// free flight modifies lookupright directly (uses current rotation matrix)
			D3DXVec3TransformCoord ( &m_pPos->vecLook, &m_pPos->vecLook,		&matRotation );
			D3DXVec3TransformCoord ( &m_pPos->vecRight,   &m_pPos->vecRight,    &matRotation );
			D3DXVec3TransformCoord ( &m_pPos->vecUp,   &m_pPos->vecUp,			&matRotation );
		}
		else
		{
			// x rotation
			D3DXMatrixRotationAxis ( &matRotation, &m_pPos->vecRight, D3DXToRadian ( m_pPos->vecRotate.x ) );
			D3DXVec3TransformCoord ( &m_pPos->vecLook, &m_pPos->vecLook,  &matRotation );
			D3DXVec3TransformCoord ( &m_pPos->vecUp,   &m_pPos->vecUp,    &matRotation );

			D3DXMatrixRotationAxis ( &matRotation, &D3DXVECTOR3 ( 0.0f, 1.0f, 0.0f ), D3DXToRadian ( m_pPos->vecRotate.y ) );
			D3DXVec3TransformCoord ( &m_pPos->vecLook, &m_pPos->vecLook, &matRotation );
	// LEEFIX - 051002 - Y rotation changes right, not up which stays the same throughout a Y rotation
	//		D3DXVec3TransformCoord ( &m_pPos->vecUp,   &m_pPos->vecUp,   &matRotation );
			D3DXVec3TransformCoord ( &m_pPos->vecRight,   &m_pPos->vecRight,   &matRotation );

			D3DXMatrixRotationAxis ( &matRotation, &m_pPos->vecLook, D3DXToRadian ( m_pPos->vecRotate.z ) );
	// LEEFIX - 051002 - Z rotation changes right, not look which stays the same throughout a Z rotation
	//		D3DXVec3TransformCoord ( &m_pPos->vecLook, &m_pPos->vecLook, &matRotation );
			D3DXVec3TransformCoord ( &m_pPos->vecRight, &m_pPos->vecRight, &matRotation );
			D3DXVec3TransformCoord ( &m_pPos->vecUp,   &m_pPos->vecUp,   &matRotation );
		}
	}

	// May need to recalc colcenter if used later
	m_pPos->bColCenterUpdated=false;
}
예제 #10
0
void CModel::Render()
{	
	LPDIRECT3DDEVICE9 pDevice = rd::CRenderDevice::GetInstance()->GetRawDevice();
	DWORD delta = bc::ut::CTimer::GetInstance()->GetFrameTime();
	D3DXVECTOR3 vPosCamera = eg::CEngine::GetInstance()->GetActiveCamera()->GetPosition();
	D3DXVECTOR3 vView = eg::CEngine::GetInstance()->GetActiveCamera()->GetView();
	DWORD dwCurrentTime = bc::ut::CTimer::GetSystemTime();

	CTerrainMesh::SGrid & grid = CXFile::GetInstance()->GetTerrainMesh()->GetGrid(FIX_GRID);
							
	m_vCenter = grid.vCenter;
	
	switch ( m_eCenterType )
	{
	case ECT_CENTER:
	break;
	
	case ECT_CORNER:
		m_vCenter.x -= GRID_SPACE/2.0f;
		m_vCenter.z -= GRID_SPACE/2.0f;
	break;
		
	case ECT_XMIDWAY:
		m_vCenter.z -= GRID_SPACE/2.0f;
	break;

	case ECT_ZMIDWAY:
		m_vCenter.x -= GRID_SPACE/2.0f;
	break;
	}

	D3DXMatrixTranslation(&m_matWorldOff, m_vCenter.x + m_fShiftX, m_vCenter.y + m_fLift, m_vCenter.z + m_fShiftZ);
	m_mat = m_matSelfOff*m_matRotY*m_matWorldOff;
	
	////////////////////////////////////////////////////////////////////////
	
	//// for wire box
	//
	//if ( this->IsSubUnit() )
	//{
	//	D3DXVECTOR3 v = m_vOffset - m_vOffsetOverall;
	//	D3DXVec3TransformCoord(&v,&v,&m_matRotY);
	//	this->SetRelativePos(D3DXVECTOR3(m_matWorldOff._41 + v.x, m_matWorldOff._42 - m_vScale.y/2 + v.y, m_matWorldOff._43 + v.z));
	//}
	//else
	//{
	//	this->SetRelativePos(D3DXVECTOR3(m_matWorldOff._41, m_matWorldOff._42, m_matWorldOff._43));
	//}
	//
	//this->SetRelativeRotation(D3DXVECTOR3(0.0f,m_fRotation,0.0f));
	//this->UpdateAbsolute();
	
	////////////////////////////////////////////////////////////////////////
	
	ICoreGraphic * pCoreGraphic = CXFile::GetInstance()->GetOperator()->GetCoreGraphic();

	CXFile::GetInstance()->GetOperator()->GetGraphicModule()->ResetGraphicRenderStyle(CXFile::GetInstance()->GetOperator()->GetCoreGraphic());

	ICamera * pCamera;

	pCoreGraphic->GetCamera(&pCamera);

	D3DXVECTOR3 vecPos = eg::CEngine::GetInstance()->GetActiveCamera()->GetPosition();

	D3DXVECTOR3 vecView = eg::CEngine::GetInstance()->GetActiveCamera()->GetView();

	pCamera->SetCamera(CVector3f(vecPos.x,vecPos.y,vecPos.z),CVector3f(vecView.x,vecView.y,vecView.z));

	sc:CCamera * pMyCamera = eg::CEngine::GetInstance()->GetActiveCamera();
	
	pCamera->SetProject(D3DXToRadian(pMyCamera->GetFOVY()), pMyCamera->GetNearPlane(),pMyCamera->GetFarPlane());
	
	m_pModel->Render(*(CMatrix*)(&m_mat),dwCurrentTime,false);
	m_pModel->Render(*(CMatrix*)(&m_mat),dwCurrentTime,true);
	
	//int i = 0;
	
	//for ( std::vector<int>::iterator iter = m_vecBlockGrids.begin(); iter != m_vecBlockGrids.end(); ++iter, ++i )
	//{
	//	m_vecpWireBox[i]->Render();
	//}
	
	if ( sc::CXFile::GetInstance()->GetOperator()->GetSelectMode() )
	{
		if ( this->GetLocked() || this->GetSelected() )
		{
//			m_pWireBox->Render();
		}
		
		//D3DXMATRIX mat;
		//D3DXMatrixIdentity(&mat);
		//pDevice->SetTransform(D3DTS_WORLD,&mat);
		//DWORD color[4] = {0xffffff};
		//rd::CRenderDevice::GetInstance()->GetLayer3D()->DrawLineStrip(3, vCorners, color);
		//rd::CRenderDevice::GetInstance()->GetLayer3D()->DrawLineStrip(3, &vCorners[4], color);
	}
	
	ISceneNode::Render();
}
예제 #11
0
void CModel::UpdateRotationDiscrete()
{	
	m_fRotation += D3DXToRadian(90);
	m_nRotationCnt++;
	D3DXMATRIX matRotY;
	D3DXMatrixRotationY(&m_matRotY,m_fRotation);
	D3DXMatrixRotationY(&matRotY,D3DXToRadian(90));
	
	std::vector<int> vecBlockGrids = m_vecBlockGrids;
	m_vecBlockGrids.clear();
	
	if ( !this->IsSubUnit() )
	{		
		for ( std::vector<int>::iterator iter = vecBlockGrids.begin(); iter != vecBlockGrids.end(); iter++ )
		{
			int nX = (*iter) % CXFile::GetInstance()->GetTerrainMesh()->GetWidth();
			int nY = (*iter) / CXFile::GetInstance()->GetTerrainMesh()->GetWidth();
	
			int nCenterX = this->GetPhysicalCenterGridIndex() % CXFile::GetInstance()->GetTerrainMesh()->GetWidth();
			int nCenterY = this->GetPhysicalCenterGridIndex() / CXFile::GetInstance()->GetTerrainMesh()->GetWidth();
	
			int nNewX = nCenterX + nY - nCenterY;
			int nNewY = nCenterY + (nCenterX - nX);
			m_vecBlockGrids.push_back(nNewY*CXFile::GetInstance()->GetTerrainMesh()->GetWidth() + nNewX);
		}
	}
	else
	{
		D3DXVECTOR3 vOldCenter = m_vCenter;
		ECenter_Type eOldBlockType = m_eCenterType;
		
		switch ( m_eCenterType )
		{
		case ECT_CENTER:
		break;
		
		case ECT_CORNER:
		break;
			
		case ECT_XMIDWAY:
			m_eCenterType = ECT_ZMIDWAY;
			m_vCenter.z += GRID_SPACE/2.0f;
			m_vCenter.x -= GRID_SPACE/2.0f;
		break;
			
		case ECT_ZMIDWAY:
			m_eCenterType = ECT_XMIDWAY;
			m_vCenter.x += GRID_SPACE/2.0f;
			m_vCenter.z -= GRID_SPACE/2.0f;
		break;
		}
		
		D3DXMatrixTranslation(&m_matWorldOff, m_vCenter.x + m_fShiftX, m_vCenter.y + m_fLift, m_vCenter.z + m_fShiftZ);
		
		//////////////////////////////////////////////////////////////////////////
		
		for ( std::vector<int>::iterator iter = vecBlockGrids.begin(); iter != vecBlockGrids.end(); iter++ )
		{
			CTerrainMesh::SGrid & grid = CXFile::GetInstance()->GetTerrainMesh()->GetGrid(*iter);
			D3DXVECTOR3 vCenter = grid.vCenter - vOldCenter;
			D3DXVec3TransformCoord(&vCenter,&vCenter,&matRotY);
			
			vCenter = m_vCenter + vCenter;
		
			int nX = vCenter.x / GRID_SPACE;
			int nY = vCenter.z / GRID_SPACE;
			int nNewGridIndex = nX + nY * CXFile::GetInstance()->GetTerrainMesh()->GetWidth();
			m_vecBlockGrids.push_back(nNewGridIndex);
		}
	}	
	
	int nWidth = this->GetWidthInGrids();
	int nDepth = this->GetDepthInGrids();

	DWORD dwCnt = nWidth*nDepth;
	
	m_nLogicalCenterGridIndex = m_vecBlockGrids[dwCnt/2];
		
	this->UpdateBoundingBox();
}
void DirectXRender::setCamera3d(IND_Camera3d *pCamera3d) {
	D3DXMATRIX mTrans, mMatView, mMatProjection;
	D3DXMatrixIdentity(&mMatView);
	D3DXMatrixIdentity(&mMatProjection);

	// ----- View matrix -----

	pCamera3d->_up      = IND_Vector3 (0.0f, 1.0f, 0.0f);
	pCamera3d->_look    = IND_Vector3 (0.0f, 0.0f, 1.0f);
	pCamera3d->_right   = IND_Vector3 (1.0f, 0.0f, 0.0f);
    //Buffer D3DVec3 structs from our camera 3d vectors
    D3DXVECTOR3 d3dpos (pCamera3d->_pos._x,pCamera3d->_pos._y,pCamera3d->_pos._z);
    D3DXVECTOR3 d3dlook (pCamera3d->_look._x,pCamera3d->_look._y, pCamera3d->_look._z);
    D3DXVECTOR3 d3dup (pCamera3d->_up._x,pCamera3d->_up._y, pCamera3d->_up._z);
    D3DXVECTOR3 d3dright (pCamera3d->_right._x,pCamera3d->_right._y, pCamera3d->_right._z);

	// Yaw is rotation around the y axis (_up)
	// Create a matrix that can carry out this rotation
	D3DXMATRIX yawMatrix;
	D3DXMatrixRotationAxis(&yawMatrix, &d3dup, D3DXToRadian(pCamera3d->_yaw));
	// To apply yaw we rotate the _look & _right vectors about the _up vector (using our yaw matrix)
	D3DXVec3TransformCoord(&d3dlook, &d3dlook, &yawMatrix);
	D3DXVec3TransformCoord(&d3dright, &d3dright, &yawMatrix);

	// Pitch is rotation around the x axis (_right)
	// Create a matrix that can carry out this rotation
	D3DXMATRIX pitchMatrix;
	D3DXMatrixRotationAxis(&pitchMatrix, &d3dright, D3DXToRadian(pCamera3d->_pitch));
	// To apply pitch we rotate the _look and _up vectors about the _right vector (using our pitch matrix)
	D3DXVec3TransformCoord(&d3dlook, &d3dlook, &pitchMatrix);
	D3DXVec3TransformCoord(&d3dup, &d3dup, &pitchMatrix);

	// Roll is rotation around the z axis (_look)
	// Create a matrix that can carry out this rotation
	D3DXMATRIX rollMatrix;
	D3DXMatrixRotationAxis(&rollMatrix, &d3dlook, D3DXToRadian(pCamera3d->_roll));
	// To apply roll we rotate up and right about the look vector (using our roll matrix)
	// Note: roll only really applies for things like aircraft unless you are implementing lean
	D3DXVec3TransformCoord(&d3dright, &d3dright, &rollMatrix);
	D3DXVec3TransformCoord(&d3dup, &d3dup, &rollMatrix);

	// Build the view matrix from the transformed camera axis
	mMatView._11 = pCamera3d->_right._x;
	mMatView._12 = pCamera3d->_up._x;
	mMatView._13 = pCamera3d->_look._x;
	mMatView._21 = pCamera3d->_right._y;
	mMatView._22 = pCamera3d->_up._y;
	mMatView._23 = pCamera3d->_look._y;
	mMatView._31 = pCamera3d->_right._z;
	mMatView._32 = pCamera3d->_up._z;
	mMatView._33 = pCamera3d->_look._z;

	mMatView._41 = - D3DXVec3Dot(&d3dright, &d3dright);
	mMatView._42 = - D3DXVec3Dot(&d3dright, &d3dup);
	mMatView._43 = - D3DXVec3Dot(&d3dright, &d3dlook);

	// ---- Zoom ----

	D3DXMatrixScaling(&mTrans, pCamera3d->_zoom, pCamera3d->_zoom, pCamera3d->_zoom);
	D3DXMatrixMultiply(&mMatView, &mTrans, &mMatView);

	_info._device->SetTransform(D3DTS_VIEW, &mMatView);

	// ----- Projection matrix -----

	// Fov projection
	if (!pCamera3d->isOrthoProjection()) {
		D3DXMatrixPerspectiveFovLH(&mMatProjection,                         // output
		                           pCamera3d->_fov,                        // Fov vertical
		                           pCamera3d->_aspect,                     // Relación de aspecto del viewport
		                           pCamera3d->_nearClippingPlane,          // Near clipping plane z
		                           pCamera3d->_farClippingPlane);          // Far clipping  plane z
	}
	// Orthographic projection
	else {
		D3DXMatrixOrthoLH(&mMatProjection, pCamera3d->_orthoWidth, pCamera3d->_orthoHeight, pCamera3d->_nearClippingPlane, pCamera3d->_farClippingPlane);
	}

	_info._device->SetTransform(D3DTS_PROJECTION, &mMatProjection);
}
void DirectXRender::setTransform3d(float pX,
                                   float  pY,
                                   float  pZ,
                                   float pAngleX,
                                   float pAngleY,
                                   float pAngleZ,
                                   float pScaleX,
                                   float pScaleY,
                                   float pScaleZ,
                                   IND_Matrix *pMatrix)


{
	// ----- World matrix initialization -----

	D3DXMATRIX mMatWorld, mMatZ, mMatX, mMatY, mMatTraslation, mMatScale;

	_info._device->SetTransform(D3DTS_WORLD, D3DXMatrixIdentity(&mMatWorld));

	// ----- Transformation matrix creation -----

	// Scaling
	if (pScaleX != 1.0f || pScaleY != 1.0f || pScaleZ != 1.0f) {
		D3DXMatrixScaling(&mMatScale, pScaleX, pScaleY, pScaleZ);
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatScale);
	}

	// Rotations
	if (pAngleX != 0.0f) {
		D3DXMatrixRotationX(&mMatX, D3DXToRadian(pAngleX));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatX);
	}
	if (pAngleY != 0.0f) {
		D3DXMatrixRotationY(&mMatY, D3DXToRadian(pAngleY));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatY);
	}
	if (pAngleZ != 0.0f) {
		D3DXMatrixRotationZ(&mMatZ, D3DXToRadian(pAngleZ));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatZ);
	}

	// Translation
	if (pX != 0 || pY != 0 || pZ != 0) {
		D3DXMatrixTranslation(&mMatTraslation, (float) pX, (float) pY, float(pZ));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
	}

	// ----- Return World Matrix (in IndieLib format) -----

	if (pMatrix) {
		pMatrix->_11 = mMatWorld._11;
		pMatrix->_12 = mMatWorld._12;
		pMatrix->_13 = mMatWorld._13;
		pMatrix->_14 = mMatWorld._14;

		pMatrix->_21 = mMatWorld._21;
		pMatrix->_22 = mMatWorld._22;
		pMatrix->_23 = mMatWorld._23;
		pMatrix->_24 = mMatWorld._24;

		pMatrix->_31 = mMatWorld._31;
		pMatrix->_32 = mMatWorld._32;
		pMatrix->_33 = mMatWorld._33;
		pMatrix->_34 = mMatWorld._34;

		pMatrix->_41 = mMatWorld._41;
		pMatrix->_42 = mMatWorld._42;
		pMatrix->_43 = mMatWorld._43;
		pMatrix->_44 = mMatWorld._44;
	}

	// ----- Applies the transformation -----

	_info._device->SetTransform(D3DTS_WORLD, &mMatWorld);
}
예제 #14
0
void DG_Rotatef(float angle, float x, float y, float z)
{
    D3DXVECTOR3 axis(x, y, z);
    matStack[msIndex]->RotateAxisLocal(&axis, D3DXToRadian(angle));
    UploadMatrix();
}
예제 #15
0
//カメラ2
void Camera_Far(D3DXVECTOR3 *position)
{
	camera.m_oldpt.x = 1920 / 2;
	camera.m_oldpt.y = 1080 / 2;
	camera.m_curpt.x = 0;
	camera.m_curpt.y = 0;
	GetCursorPos(&camera.m_curpt);
	camera.m_rolaX = 0.0f;
	camera.m_rolaY = 0.0f;

	camera.m_rolaY = (camera.m_curpt.x - camera.m_oldpt.x) / 300.f;
	camera.m_rolaX = (camera.m_curpt.y - camera.m_oldpt.y - 200) / 300.f;

	camera.m_pos = *position + D3DXVECTOR3(0.0f, 5.0f, 0.0f);
	camera.m_up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	camera.m_oldpt = camera.m_curpt;
	camera.m_vDelt = D3DXVECTOR3(0.0f, -15.0f, 22.0f);

	D3DXMatrixRotationYawPitchRoll(&camera.matRola, camera.m_rolaY, camera.m_rolaX, 0.0f);
	D3DXVec3TransformCoord(&camera.vdelt, &camera.m_vDelt, &camera.matRola);
	camera.m_lookat = camera.m_pos + camera.vdelt;
	D3DXMatrixLookAtLH(&camera.m_view, &camera.m_pos, &camera.m_lookat, &camera.m_up);
	lpD3DDev->SetTransform(D3DTS_VIEW, &camera.m_view);
	D3DXMatrixPerspectiveFovLH(&camera.m_proj, D3DXToRadian(10.0f), 16.0f / 9.0f, 0.1f, 1000.0f);
	lpD3DDev->SetTransform(D3DTS_PROJECTION, &camera.m_proj);

	if (count < 0)
	{
		switch (num_tank)
		{
		case 11:
			SetCursorPos2(camera.m_curpt, T44);
			break;
		case 12:
			SetCursorPos2(camera.m_curpt, IS1);
			break;
		case 13:
			SetCursorPos2(camera.m_curpt, T54);
			break;
		case 14:
			SetCursorPos2(camera.m_curpt, IS3);
			break;
		case 21:
			SetCursorPos2(camera.m_curpt, PantherG);
			break;
		case 22:
			SetCursorPos2(camera.m_curpt, Tiger);
			break;
		case 23:
			SetCursorPos2(camera.m_curpt, PantherII);
			break;
		case 24:
			SetCursorPos2(camera.m_curpt, TigerII);
			break;
		case 31:
			SetCursorPos2(camera.m_curpt, M26);
			break;
		case 32:
			SetCursorPos2(camera.m_curpt, T32);
			break;
		case 33:
			SetCursorPos2(camera.m_curpt, M46);
			break;
		case 34:
			SetCursorPos2(camera.m_curpt, M103);
			break;
		}
	}
}
예제 #16
0
파일: cPart.cpp 프로젝트: arkiny/Direct3D
void cPart::Setup(float fWidth, float fHeight, float fDepth, Cube_Part type){
	ST_PT_VERTEX v;
	D3DXMATRIXA16 matScale, matRotate, matTrans, matFinal;
	m_epart = type;

	float left = -0.5f;
	float top = 0.5f;
	float right = 0.5f;
	float bottom = -0.5f;
	float frontdepth = 0.5f;
	float backdepth = -0.5f;

	//front
	std::vector<ST_PT_VERTEX> plane;
	v.p = D3DXVECTOR3(left, top, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(right, top, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(left, bottom, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(left, bottom, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(right, top, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(right, bottom, 0);
	plane.push_back(v);

	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationY(&matRotate, D3DXToRadian(180.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.z = v.p.z + frontdepth;
		m_vecVertex.push_back(v);
	}

	// right
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationY(&matRotate, D3DXToRadian(270.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.x = v.p.x + right;
		m_vecVertex.push_back(v);
	}

	//back
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		//D3DXMatrixRotationY(&matRotate, D3DXToRadian(0.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		//D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.z = v.p.z + backdepth;
		m_vecVertex.push_back(v);
	}
	//left
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationY(&matRotate, D3DXToRadian(90.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.x = v.p.x + left;
		m_vecVertex.push_back(v);
	}

	//top
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationX(&matRotate, D3DXToRadian(90.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.y = v.p.y + top;
		m_vecVertex.push_back(v);
	}

	// bottom
	// lefttop righttop leftbottom leftbottom righttop rightbottom
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationX(&matRotate, D3DXToRadian(270.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.y = v.p.y + bottom;
		m_vecVertex.push_back(v);
	}

	D3DXMatrixScaling(&matScale, fWidth, fHeight, fDepth);
	for (UINT i = 0; i < m_vecVertex.size(); i++){
		D3DXVec3TransformCoord(&m_vecVertex[i].p, &m_vecVertex[i].p, &matScale);
	}

	if (type == PT_head){
		// right
		m_vecVertex[0].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(0.0f, 128.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(0.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(0.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(128.0f / 1024.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f);
	}
	else if (type == PT_body){
		//front
		m_vecVertex[0].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2(510.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(510.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(510.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2(448.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(560.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(448.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(448.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(560.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(560.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2(320.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, 320.0f / 512.0f);
	}
	else if (type == PT_arm_left){
		m_vecVertex[0].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);

		m_vecVertex[6].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);

		m_vecVertex[12].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f);

		m_vecVertex[18].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);

		m_vecVertex[24].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);

		m_vecVertex[30].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
	}
	else if (type == PT_arm_right || type == PT_fist){
		m_vecVertex[0].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
	}
	else if (type == PT_leg_left){
		m_vecVertex[0].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2(0 / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2(64.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
	}
	else if (type == PT_leg_right){
		m_vecVertex[0].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2(0 / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2(64.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
	}
}
예제 #17
0
//カメラ1
void SetupCamera(D3DXVECTOR3 *position)
{
	camera.m_oldpt.x = 1920 / 2;
	camera.m_oldpt.y = 1080 / 2;
	camera.m_curpt.x = 0;
	camera.m_curpt.y = 1080 - camera.m_curpt.y;
	GetCursorPos(&camera.m_curpt);	//マウス座標取得
	camera.m_rolaX = 0.0f;
	camera.m_rolaY = 0.0f;

	camera.m_rolaY = (camera.m_curpt.x - camera.m_oldpt.x) / 300.f;
	camera.m_rolaX = (camera.m_curpt.y - camera.m_oldpt.y) / 300.f;
	if (camera.key_E == false)	camera.m_vDelt = D3DXVECTOR3(0.0f, 0.0f, 20.0f);	//E離す
	if (camera.key_E)			camera.m_vDelt = D3DXVECTOR3(0.0f, 0.0f, 100.0f);	//E押す

	camera.m_lookat = *position + D3DXVECTOR3(0.f, 3.f, 0.f);
	camera.m_pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	camera.m_up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	camera.m_oldpt = camera.m_curpt;

	//座標変換
	D3DXMatrixRotationYawPitchRoll(&camera.matRola, camera.m_rolaY, camera.m_rolaX, 0.0f);
	D3DXVec3TransformCoord(&camera.vdelt, &camera.m_vDelt, &camera.matRola);
	camera.m_pos = camera.m_lookat - camera.vdelt;
	D3DXMatrixLookAtLH(&camera.m_view, &camera.m_pos, &camera.m_lookat, &camera.m_up);
	lpD3DDev->SetTransform(D3DTS_VIEW, &camera.m_view);
	D3DXMatrixPerspectiveFovLH(&camera.m_proj, D3DXToRadian(32.0f), 16.0f / 9.0f, 0.1f, 1000.0f);
	lpD3DDev->SetTransform(D3DTS_PROJECTION, &camera.m_proj);

	if (count < 0)
	{
		//タンク種類取得
		switch (num_tank)
		{
		case 11:
			SetCursorPos(camera.m_curpt, T44);
			break;
		case 12:
			SetCursorPos(camera.m_curpt, IS1);
			break;
		case 13:
			SetCursorPos(camera.m_curpt, T54);
			break;
		case 14:
			SetCursorPos(camera.m_curpt, IS3);
			break;
		case 21:
			SetCursorPos(camera.m_curpt, PantherG);
			break;
		case 22:
			SetCursorPos(camera.m_curpt, Tiger);
			break;
		case 23:
			SetCursorPos(camera.m_curpt, PantherII);
			break;
		case 24:
			SetCursorPos(camera.m_curpt, TigerII);
			break;
		case 31:
			SetCursorPos(camera.m_curpt, M26);
			break;
		case 32:
			SetCursorPos(camera.m_curpt, T32);
			break;
		case 33:
			SetCursorPos(camera.m_curpt, M46);
			break;
		case 34:
			SetCursorPos(camera.m_curpt, M103);
			break;
		}
	}
}
예제 #18
0
//-- RotateAxis ---------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void Renderer::RotateAxis( float angle, float x, float y, float z )
{
	D3DXVECTOR3 axis( x, y, z );
	g_matrixStack->RotateAxisLocal( &axis, D3DXToRadian( angle ) );

} // RotateAxis
예제 #19
0
void CDofEditing::OnBnClickedPitch5p()
{
	m_Pitch+=D3DXToRadian(5);
	UpdateAngles();
}
예제 #20
0
// CCamera 클래스의 GenerateProjectionMatrix() 멤버 함수
//투영 변환 행렬을 생성하는 함수이다.카메라 좌표계의 근평면 거리(카메라에서 볼 수 있는 가장 가까운 거리), 원평면 거리(카메라에서 볼 수 있는 가장 먼 거리), 화면의 종횡비(Aspect Ratio), 카메라 FOV 각도를  위치 벡터, 카메라가 바라보는 지점, 카메라의 Up 벡터(로컬 y - 축 벡터)를 파라메터로 사용하는 D3DXMatrixPerspectiveFovLH() 함수를 사용한다.
void CCamera::GenerateProjectionMatrix(float fNearPlaneDistance, float fFarPlaneDistance, float fAspectRatio, float fFOVAngle)
{
	D3DXMatrixPerspectiveFovLH(&m_d3dxmtxProjection, (float)D3DXToRadian(fFOVAngle), fAspectRatio, fNearPlaneDistance, fFarPlaneDistance);
}
예제 #21
0
// +--------------+
// | D3DStartup() |
// +--------------+----------------------------------+
// | Initialise Direct3D and perform once only tasks |
// +-------------------------------------------------+
HRESULT D3DStartup(HWND hWnd)
{
  BOOL                  bCompOk             = FALSE;   // Is composition enabled? 
  D3DPRESENT_PARAMETERS pp;                            // Presentation prefs
  DWORD                 msqAAQuality        = 0;       // Non-maskable quality
  D3DLIGHT9             ltDirectionalLight;            // Light description
  D3DVECTOR             vctLightDirection   = {-1.0f,  // X component
                                               -0.3f,  // Y component
                                               -1.0f}; // Z component
  D3DXMATRIX            mtxView;                       // View matrix
  D3DXMATRIX            mtxProjection;                 // Projection matrix

  // Make sure that DWM composition is enabled
  DwmIsCompositionEnabled(&bCompOk);
  if(!bCompOk) return E_FAIL;

  // Create a Direct3D object
  if(FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &g_pD3D))) return E_FAIL;

  // Setup presentation parameters
  ZeroMemory(&pp, sizeof(pp));
  pp.Windowed            = TRUE;
  pp.SwapEffect          = D3DSWAPEFFECT_DISCARD; // Required for multi sampling
  pp.BackBufferFormat    = D3DFMT_A8R8G8B8;       // Back buffer format with alpha channel

  // Set highest quality non-maskable AA available or none if not
  if(SUCCEEDED(g_pD3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,
                                                  D3DDEVTYPE_HAL,
                                                  D3DFMT_A8R8G8B8,
                                                  TRUE,
                                                  D3DMULTISAMPLE_NONMASKABLE,
                                                  &msqAAQuality
                                                  )))
  {
    // Set AA quality
   /* pp.MultiSampleType     = D3DMULTISAMPLE_NONMASKABLE;
    pp.MultiSampleQuality  = msqAAQuality - 1;*/
  }
  else
  {
    // No AA
    pp.MultiSampleType     = D3DMULTISAMPLE_NONE;
  }

  // Create a Direct3D device object
  if(FAILED(g_pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT,
                                   D3DDEVTYPE_HAL,
                                   hWnd,
                                   D3DCREATE_HARDWARE_VERTEXPROCESSING,
                                   &pp,
                                   NULL,
                                   &g_pD3DDevice
                                   ))) return E_FAIL;

  // Configure the device state
  g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);        // Enable 3D lighting
  g_pD3DDevice->SetRenderState(D3DRS_AMBIENT, ARGB_AMBIENT); // Set ambient lighting
  g_pD3DDevice->SetRenderState(D3DRS_SPECULARENABLE, FALSE); // Disable specular highlighting
  
  // Create a directional light
  ZeroMemory(&ltDirectionalLight, sizeof(ltDirectionalLight));
  ltDirectionalLight.Type       = D3DLIGHT_DIRECTIONAL;
  ltDirectionalLight.Diffuse.r  = 1.0f;
  ltDirectionalLight.Diffuse.g  = 1.0f;
  ltDirectionalLight.Diffuse.b  = 1.0f;
  ltDirectionalLight.Diffuse.a  = 1.0f;				
  ltDirectionalLight.Direction  = vctLightDirection;

  // Add as light 0
  g_pD3DDevice->SetLight(0, &ltDirectionalLight);
  g_pD3DDevice->LightEnable(0, TRUE);

  // Configure camera
  D3DXMatrixLookAtLH(&mtxView,
                     &D3DXVECTOR3 (0.0f, 0.0f, 25.0f), // Camera position
                     &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),  // Look-at target
                     &D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // Up direction
  g_pD3DDevice->SetTransform(D3DTS_VIEW, &mtxView);

  // Configure projection
  D3DXMatrixPerspectiveFovLH(&mtxProjection,
                             D3DXToRadian(45),                          // Horizontal field of view
                             (FLOAT)((FLOAT)g_iWidth/(FLOAT)g_iHeight),	// Aspect ratio
                             0.0f,										                  // Near view plane
                             100.0f);										                // Far view plane
  g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &mtxProjection);

  return S_OK;
}
예제 #22
0
// this is the function used to render a single frame
void DirectXHelper::renderFrame(void)
{
	D3DXMATRIX matWorld;
    // clear the window to a deep blue
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 115, 255), 100.0f, 0);
	//d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0, 0, 0), 100.0f, 0);
	d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    d3ddev->BeginScene();    // begins the 3D scene

	// select which vertex format we are using
	d3ddev->SetFVF(CUSTOMFVF);

	helper->IncreaseTimer();
	//textbox->SetString(helper->toString(helper->GetTime()));
	//get input and place the camera
	input->CheckForInput(cat2);
	camera->Update();
	d3ddev->SetTransform(D3DTS_VIEW, camera->GetViewMatrix());
	d3ddev->SetTransform(D3DTS_PROJECTION, camera->GetProjectionMatrix());

	textbox->Draw();
	
	// select the vertex buffer to display
    d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
    // do 3D rendering on the back buffer here
	// copy the vertex buffer to the back buffer
	//D3DXMATRIX matTranslate;
	//D3DXMATRIX matScale;

	//D3DXMatrixTranslation(&matTranslate, 0, 0, 0);
	//D3DXMatrixScaling(&matScale, 0.5f, 0.5f, 0.5f);

	//d3ddev->SetTransform(D3DTS_WORLD, &(matScale * matTranslate));
    //d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
	p->run_particles(d3ddev,0);

	d3ddev->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
    d3ddev->SetRenderState( D3DRS_ZWRITEENABLE, false );
	d3ddev->SetRenderState( D3DRS_LIGHTING, false );

	// Render the sky box
    d3ddev->SetFVF( CUSTOMFVFNONORMAL );
    d3ddev->SetStreamSource( 0, v_buffer, 0, sizeof(CUSTOMVERTEXNONORMAL));
    
	D3DXMATRIX rotate;

	// Set the world matrix to identity for the skybox
	D3DXMatrixTranslation(&matWorld, 0, 0, 0);
	D3DXMatrixRotationY(&rotate, D3DXToRadian(60));
	d3ddev->SetTransform( D3DTS_WORLD, &(rotate * matWorld) );

    // Render the 6 faces of the skybox
	// DrawPrimitive is used to draw polygons when the vertices are stored in a device resource 
	// called a vertex buffer. Vertex buffers are blocks of memory allocated by the device that
	// we use to store vertex data.
    for ( ULONG i = 0; i < 6; ++i )
    {
		// Set the texture for this primitive
        d3ddev->SetTexture( 0, skyTextures[i] );

		// Render the face (one strip per face from the vertex buffer)  There are 2 primitives per face.
        d3ddev->DrawPrimitive( D3DPT_TRIANGLESTRIP, i * 4, 2 );

    } // Next side

	d3ddev->SetRenderState( D3DRS_ZWRITEENABLE, true );
	d3ddev->SetRenderState( D3DRS_LIGHTING, true );
    

    // ADDED BY ZACK
    
	d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

	//alpha in material's diffuse component is for alpha
	d3ddev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
	d3ddev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

	//set blending factors so that alpha component determines transparancy
	d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

    window->Render(helper->GetTime(), 0);
	d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
	room->Render(helper->GetTime(), 0);
	d3ddev->SetRenderState( D3DRS_SPECULARENABLE, true );
	floor->Render(helper->GetTime(), 0);
	d3ddev->SetRenderState( D3DRS_SPECULARENABLE, false );

	stencil->RenderShadow(cat2, D3DXVECTOR3(0, -1, 0), lightDir, helper);

	d3ddev->SetRenderState( D3DRS_SPECULARENABLE, true );
    cat2->Render(helper->GetTime(), 1);
	stencil->RenderReflection(cat2, floor, helper);
	
	d3ddev->SetRenderState( D3DRS_SPECULARENABLE, false );

	
    // END ADDED BY ZACK

	

    d3ddev->EndScene();    // ends the 3D scene

    d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}
예제 #23
0
/**
 * Handles user input.
 */
void HandleInput()
{
	float timeDelta = (float)(GetSystemTimeMs() - gLastFrameTime) / 1000.0f;

	D3DXMATRIX tx;

	// handle camera rotation
	if (GetAsyncKeyState(VK_RBUTTON))
	{
		POINT last = gLastMousePos;
		GetCursorPos(&gLastMousePos);

		const float dampening = 10.0f;
		float dx = (gLastMousePos.x - last.x) / dampening;
		float dy = (gLastMousePos.y - last.y) / dampening;

		if (dx != 0)
		{
			D3DXMatrixRotationY(&tx, -D3DXToRadian(dx) * timeDelta * gCameraRotateSpeed);
			gViewMatrix = gViewMatrix * tx;
		}

		if (dy != 0)
		{
			D3DXMatrixRotationX(&tx, -D3DXToRadian(dy) * timeDelta * gCameraRotateSpeed);
			gViewMatrix = gViewMatrix * tx;
		}
	}

	// handle camera fly through
	FLOAT x = 0;
	FLOAT y = 0;
	FLOAT z = 0;
	if (GetAsyncKeyState('A'))
	{
		x += gCameraFlySpeed * timeDelta;
	}
	if (GetAsyncKeyState('D'))
	{
		x -= gCameraFlySpeed * timeDelta;
	}
	if (GetAsyncKeyState('E'))
	{
		y -= gCameraFlySpeed * timeDelta;
	}
	if (GetAsyncKeyState('Q'))
	{
		y += gCameraFlySpeed * timeDelta;
	}
	if (GetAsyncKeyState('W'))
	{
		z -= gCameraFlySpeed * timeDelta;
	}
	if (GetAsyncKeyState('S'))
	{
		z += gCameraFlySpeed * timeDelta;
	}

	D3DXMatrixTranslation(&tx, x, y, z);
	gViewMatrix = gViewMatrix * tx;

	// Reset the view
	if (GetAsyncKeyState('R'))
	{
		ResetView();
	}

	// Get the latest mouse position
	GetCursorPos(&gLastMousePos);
}
void Storm3D_SpotlightShared::updateMatrices(const float *cameraView, float bias)
{
	D3DXVECTOR3 lightPosition(position.x, position.y, position.z);
	D3DXVECTOR3 up(0, 1.f, 0);
	D3DXVECTOR3 lookAt = lightPosition;
	lookAt += D3DXVECTOR3(direction.x, direction.y, direction.z);

	D3DXMatrixPerspectiveFovLH(&lightProjection, D3DXToRadian(fov), 1.f, .2f, range);
	D3DXMATRIX cameraMatrix(cameraView);
	float det = D3DXMatrixDeterminant(&cameraMatrix);
	D3DXMatrixInverse(&cameraMatrix, &det, &cameraMatrix);

	unsigned int tweakRange = 1;

	float currentBias = bias;
	for(int i = 0; i < 2; ++i)
	{	
		D3DXMatrixLookAtLH(&lightView[i], &lightPosition, &lookAt, &up);
		//if(i == 1)
		//	currentBias = 0;
		if(i == 1)
			currentBias = 1.f;

		// Tweak matrix
		float soffsetX = 0.5f;
		float soffsetY = 0.5f;
		float scale = 0.5f;

		/*
		D3DXMATRIX shadowTweak( scale,    0.0f,     0.0f,				0.0f,
								0.0f,     -scale,   0.0f,				0.0f,
								0.0f,      0.0f,     float(tweakRange),	0.0f,
								soffsetX,  soffsetY, currentBias,		1.0f );
		*/
		D3DXMATRIX shadowTweak( scale,    0.0f,      0.0f,				0.0f,
								0.0f,     -scale,    0.0f,				0.0f,
								0.0f,      0.0f,	 currentBias,		0.0f,
								soffsetX,  soffsetY, 0.f,				1.0f );

		D3DXMatrixMultiply(&shadowProjection[i], &lightProjection, &shadowTweak);
		D3DXMatrixMultiply(&shadowProjection[i], &lightView[i], &shadowProjection[i]);
		D3DXMatrixMultiply(&lightViewProjection[i], &lightView[i], &lightProjection);

		shaderProjection[i] = shadowProjection[i];
		D3DXMatrixMultiply(&shadowProjection[i], &cameraMatrix, &shadowProjection[i]);
	}

	{
		float xf = (1.f / resolutionX * .5f);
		float yf = (1.f / resolutionY * .5f);
		float sX = soffsetX + (2 * targetPos.x * soffsetX) - xf;
		float sY = soffsetY + (2 * targetPos.y * soffsetY) - yf;

		/*
		D3DXMATRIX shadowTweak( scaleX,    0.0f,	0.0f,				0.0f,
								0.0f,    -scaleY,	0.0f,				0.0f,
								0.0f,     0.0f,     float(tweakRange),	0.0f,
								sX,       sY,		bias,				1.0f );
		*/

		D3DXMATRIX shadowTweak( scaleX,    0.0f,	0.0f,				0.0f,
								0.0f,    -scaleY,	0.0f,				0.0f,
								0.0f,     0.0f,     bias,				0.0f,
								sX,       sY,		0.f,				1.0f );

		D3DXMatrixMultiply(&targetProjection, &lightProjection, &shadowTweak);
		D3DXMatrixMultiply(&targetProjection, &lightView[0], &targetProjection);
	}
}
예제 #25
0
파일: myApp.cpp 프로젝트: egorbunov/cglabs
void myApp::init_graphics() {
    m_d3ddev = m_pD3D->getDevice();
    m_d3ddev->SetRenderState(D3DRS_ZENABLE, true);
    m_d3ddev->SetRenderState(D3DRS_LIGHTING, true);
    m_d3ddev->SetRenderState(D3DRS_SPECULARENABLE, true);
    m_d3ddev->SetRenderState(D3DRS_NORMALIZENORMALS, true);
    m_d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    m_d3ddev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);

    isWASDCameraActive = true;
    float initPos = 150.0f;
    wasdCamera.setPosition({ initPos, initPos, initPos });
    wasdCamera.setUpDirection({ 0.0f, 1.0f, 0.0f });
    wasdCamera.setLookAt(worldCenter);
    m_d3ddev->SetTransform(D3DTS_VIEW, wasdCamera.getViewMatrix());    // set the view transform to matView

    D3DXMatrixPerspectiveFovLH(&m_matProj,
                               D3DXToRadian(45),    // the horizontal field of view
                               (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
                               10.0f,    // the near view-plane
                               1000.0f);    // the far view-plane
    m_d3ddev->SetTransform(D3DTS_PROJECTION, &m_matProj);    // set the projection

    // one directed light and point light
    lights.push_back(new DirectedLight(
        D3DXVECTOR3(-1.0f, -1.0f, -1.0f),
        hexToColor(0),
        hexToColor(0x333300),
        hexToColor(0)));
    lights.push_back(new PointLight(
        D3DXVECTOR3(60.0f, 30.0f, -70.0f),
        100.0f,
        1.0f,
        0.000f,
        0.050f,
        0.001f,
        hexToColor(0xffffff),
        hexToColor(0xffffff),
        hexToColor(0xffffff)
        ));

    // headlights: A lot of magic numbers ;)
    D3DXCOLOR headlightColor = hexToColor(0xFFFF55);
    float headlightX = -12.5f;
    float headlightZ = -5.5f;
    float headlightY = -9.35f;
    lights.push_back(new SpotLight(
        D3DXVECTOR3(headlightX, headlightY, headlightZ),
        D3DXVECTOR3(-1.6f, 1.0f, 0.0f),
        D3DXToRadian(20.0f),
        D3DXToRadian(30.0f),
        70.0f,
        1.0f,
        0.0f,
        0.08f,
        0.0f,
        headlightColor,
        headlightColor,
        hexToColor(0)
        ));
    lights.push_back(new SpotLight(
        D3DXVECTOR3(headlightX, headlightY, headlightZ + 12.5f),
        D3DXVECTOR3(-1.6f, 1.0f, 0.0f),
        D3DXToRadian(20.0f),
        D3DXToRadian(30.0f),
        70.0f,
        1.0f,
        0.0f,
        0.08f,
        0.0f,
        headlightColor,
        headlightColor,
        hexToColor(0)
        ));


    car.setDevice(m_d3ddev);
    float carScaleFactor = 3;
    float radius = 25;
    car.loadModelFromFile("car00.x");
    car.translate(0, 0, radius);
    circleIterator = new CircleIterator(radius, 0.0f, 0.025f);

    car.addLight(lights[lights.size() - 1]);
    car.addLight(lights[lights.size() - 2]);

    car.rotateX(-D3DX_PI);
    car.rotateY(-D3DX_PI);

    car.scale(carScaleFactor, carScaleFactor, carScaleFactor);
    car.translate(0, 2.39f, 0);

    for (unsigned int i = 0; i < lights.size(); ++i) {
        lights[i]->create(m_d3ddev, i);
        lights[i]->switchOn();
    }

    ZeroMemory(&globalMaterial, sizeof(D3DMATERIAL9)); // clear out the struct for use
    globalMaterial.Diffuse = hexToColor(0);
    globalMaterial.Ambient = hexToColor(0xffffff);
    globalMaterial.Emissive = hexToColor(0x000010);
    globalMaterial.Specular = hexToColor(0);

    m_nClearColor = 0xFF111111;

    globalCoordSystem.scale(220.0f, 220.0f, 220.0f);
    globalCoordSystem.translate(-0.5, 0, -0.5);
    globalCoordSystem.create(m_d3ddev);

    plane.create(m_d3ddev);
}
bool Storm3D_SpotlightShared::setScissorRect(Storm3D_Camera &camera, const VC2I &screenSize)
{
	D3DXMATRIX light;
	D3DXVECTOR3 lightPosition(position.x, position.y, position.z);
	D3DXVECTOR3 up(0, 1.f, 0);
	D3DXVECTOR3 lookAt = lightPosition;
	lookAt += D3DXVECTOR3(direction.x, direction.y, direction.z);
	D3DXMatrixLookAtLH(&light, &lightPosition, &lookAt, &up);

	D3DXVECTOR3 v[5];
	v[0] = D3DXVECTOR3(0, 0, 0);
	v[1] = D3DXVECTOR3(0, 0, 1.f);
	v[2] = D3DXVECTOR3(0, 0, 1.f);
	v[3] = D3DXVECTOR3(0, 0, 1.f);
	v[4] = D3DXVECTOR3(0, 0, 1.f);

	int minX = screenSize.x;
	int minY = screenSize.y;
	int maxX = 0;
	int maxY = 0;

	float det = D3DXMatrixDeterminant(&light);
	D3DXMatrixInverse(&light, &det, &light);

	float angle = D3DXToRadian(fov) * .5f;
	for(int i = 0; i <= 4; ++i)
	{
		if(i > 0)
		{
			float z = v[i].z;
			if(i == 1 || i == 2)
			{
				v[i].x = z * sinf(angle);
				v[i].z = z * cosf(angle);
			}
			else
			{
				v[i].x = z * sinf(-angle);
				v[i].z = z * cosf(-angle);
			}

			if(i == 1 || i == 3)
				v[i].y = z * sinf(angle);
			else
				v[i].y = z * sinf(-angle);

			float scale = range / cosf(angle);
			v[i] *= scale;
		}

		D3DXVec3TransformCoord(&v[i], &v[i], &light);
	}

	const Frustum &frustum = camera.getFrustum();
	calculateLineToScissor(toVC3(v[0]), toVC3(v[1]), frustum, camera, screenSize, minX, minY, maxX, maxY);
	calculateLineToScissor(toVC3(v[0]), toVC3(v[2]), frustum, camera, screenSize, minX, minY, maxX, maxY);
	calculateLineToScissor(toVC3(v[0]), toVC3(v[3]), frustum, camera, screenSize, minX, minY, maxX, maxY);
	calculateLineToScissor(toVC3(v[0]), toVC3(v[4]), frustum, camera, screenSize, minX, minY, maxX, maxY);
	calculateLineToScissor(toVC3(v[1]), toVC3(v[2]), frustum, camera, screenSize, minX, minY, maxX, maxY);
	calculateLineToScissor(toVC3(v[2]), toVC3(v[3]), frustum, camera, screenSize, minX, minY, maxX, maxY);
	calculateLineToScissor(toVC3(v[3]), toVC3(v[4]), frustum, camera, screenSize, minX, minY, maxX, maxY);
	calculateLineToScissor(toVC3(v[4]), toVC3(v[1]), frustum, camera, screenSize, minX, minY, maxX, maxY);

	/*
	VC3 cameraPos = camera.GetPosition();
	VC3 cameraPosResult;
	float cameraRhw = 0, cameraRealZ = 0;
	bool cameraVisible = camera.GetTransformedToScreen(cameraPos, cameraPosResult, cameraRhw, cameraRealZ);

	for(i = 0; i <= 4; ++i)
	{
		VC3 source(v[i].x, v[i].y, v[i].z);
		VC3 result;
		float rhw = 0, realZ = 0;
		bool inFront = camera.GetTransformedToScreen(source, result, rhw, realZ);

		// HAX HAX!

		result.x = std::max(0.f, result.x);
		result.y = std::max(0.f, result.y);
		result.x = std::min(1.f, result.x);
		result.y = std::min(1.f, result.y);

		//if(fabsf(rhw) < 0.0001f)
		//	continue;

		bool flip = false;
		if(realZ < cameraRealZ)
			flip = true;

		if(flip)
		{
			result.x = 1.f - result.x;
			result.y = 1.f - result.y;

			//minX = 0;
			//minY = 0;
			//maxX = screenSize.x;
			//maxY = screenSize.y;
		}

		int x = int(result.x * screenSize.x);
		int y = int(result.y * screenSize.y);

		maxX = std::max(x, maxX);
		maxY = std::max(y, maxY);
		minX = std::min(x, minX);
		minY = std::min(y, minY);
	}
	*/

	if(maxX > screenSize.x)
		maxX = screenSize.x;
	if(maxY > screenSize.y)
		maxY = screenSize.y;
	if(minX < 0)
		minX = 0;
	if(minY < 0)
		minY = 0;

	RECT rc;
	rc.left = minX;
	rc.top = minY;
	rc.right = maxX;
	rc.bottom = maxY;

	if(rc.left < rc.right && rc.top < rc.bottom)
	{
		device.SetScissorRect(&rc);
		device.SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
	}
	else
	{
		RECT rc;
		rc.left = 0;
		rc.top = 0;
		rc.right = 1;
		rc.bottom = 1;

		device.SetScissorRect(&rc);
		device.SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);

		return false;
	}

	return true;
}
void DirectXRender::setTransform2d(int pX,
                                   int pY,
                                   float pAngleX,
                                   float pAngleY,
                                   float pAngleZ,
                                   float pScaleX,
                                   float pScaleY,
                                   int pAxisCalX,
                                   int pAxisCalY,
                                   bool pMirrorX,
                                   bool pMirrorY,
                                   int pWidth,
                                   int pHeight,
                                   IND_Matrix *pMatrix) {
	// ----- World matrix initialization -----

	D3DXMATRIX mMatWorld, mMatZ, mMatX, mMatY, mMatTraslation, mMatScale;
	//Initializes every object transform with pixel to point scale transform
	_info._device->SetTransform(D3DTS_WORLD, D3DXMatrixIdentity(&mMatWorld));

	// ----- Transformation matrix creation -----

	// Mirroring (180º rotations)
	if (pMirrorX || pMirrorY) {
		//A mirror is a rotation in desired axis (the actual mirror) and a repositioning because rotation
		//also moves 'out of place' the entity translation-wise
		if (pMirrorX) {
			//Rotate in y, to invert texture
			D3DXMatrixRotationY(&mMatY, D3DXToRadian(180));
			D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatY);

			//After rotation around origin, move back texture to correct place
			D3DXMatrixTranslation(&mMatTraslation, 
								  static_cast<float>(pWidth),
								  0.0f,
								  0);
			D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
		}

		//A mirror is a rotation in desired axis (the actual mirror) and a repositioning because rotation
		//also moves 'out of place' the entity translation-wise
		if (pMirrorY) {
			//Rotate in x, to invert texture
			D3DXMatrixRotationX(&mMatX, D3DXToRadian(180));
			D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatX);

			//After rotation around origin, move back texture to correct place
			D3DXMatrixTranslation(&mMatTraslation, 
								  0.0f, 
								  static_cast<float>(pHeight),
								  0);
			D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
		}
	}

	// Hotspot - Set hotspot to affect following transforms
	if (pAxisCalX != 0 || pAxisCalY != 0) {
		D3DXMatrixTranslation(&mMatTraslation, static_cast<float>( pAxisCalX), static_cast<float>( pAxisCalY), 0);
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
	}

	// Scaling
	if (pScaleX != 1.0f || pScaleY != 1.0f) {
		D3DXMatrixScaling(&mMatScale, pScaleX, pScaleY, 1.0f);
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatScale);
	}

	// Rotations
	if (pAngleX != 0.0f) {
		D3DXMatrixRotationX(&mMatX, D3DXToRadian(pAngleX));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatX);
	}
	if (pAngleY != 0.0f) {
		D3DXMatrixRotationY(&mMatY, D3DXToRadian(pAngleY));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatY);
	}
	if (pAngleZ != 0.0f) {
		D3DXMatrixRotationZ(&mMatZ, D3DXToRadian(pAngleZ));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatZ);
	}

	// Translations
	if (pX != 0 || pY != 0) {
		D3DXMatrixTranslation(&mMatTraslation, static_cast<float>(pX), static_cast<float>(pY), 0);
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
	}

	// ----- Return World Matrix (in IndieLib format) -----
	if (pMatrix) {
		pMatrix->readFromArray(&mMatWorld.m[0][0]);
	}

	// ----- Applies the transformation -----
	_info._device->SetTransform(D3DTS_WORLD, &mMatWorld);
}
bool Storm3D_SpotlightShared::setScissorRect(Storm3D_Camera &camera, const VC2I &screenSize, Storm3D_Scene *scene)
{
	D3DXMATRIX light;
	D3DXVECTOR3 lightPosition(position.x, position.y, position.z);
	D3DXVECTOR3 up(0, 1.f, 0);
	D3DXVECTOR3 lookAt = lightPosition;
	lookAt += D3DXVECTOR3(direction.x, direction.y, direction.z);
	D3DXMatrixLookAtLH(&light, &lightPosition, &lookAt, &up);

	// Create frustum vertices

	D3DXVECTOR3 v[5];
	v[0] = D3DXVECTOR3(0, 0, 0);
	v[1] = D3DXVECTOR3(0, 0, 1.f);
	v[2] = D3DXVECTOR3(0, 0, 1.f);
	v[3] = D3DXVECTOR3(0, 0, 1.f);
	v[4] = D3DXVECTOR3(0, 0, 1.f);

	float det = D3DXMatrixDeterminant(&light);
	D3DXMatrixInverse(&light, &det, &light);
	float angle = D3DXToRadian(fov) * .5f;
	for(int i = 0; i <= 4; ++i)
	{
		if(i > 0)
		{
			float z = v[i].z;
			if(i == 1 || i == 2)
			{
				v[i].x = z * sinf(angle);
				v[i].z = z * cosf(angle);
			}
			else
			{
				v[i].x = z * sinf(-angle);
				v[i].z = z * cosf(-angle);
			}

			if(i == 1 || i == 3)
				v[i].y = z * sinf(angle);
			else
				v[i].y = z * sinf(-angle);

			float scale = range / cosf(angle);
			v[i] *= scale;
		}

		D3DXVec3TransformCoord(&v[i], &v[i], &light);
	}

	// Create area

	const Frustum &frustum = camera.getFrustum();
	int foundVertexAmount = 0;
	int minX = screenSize.x;
	int minY = screenSize.y;
	int maxX = 0;
	int maxY = 0;

	for(int i = 0; i < 6; ++i)
	{
		VC3 v1;
		VC3 v2;
		VC3 v3;

		if(i == 0)
		{
			v1 = toVC3(v[0]);
			v2 = toVC3(v[1]);
			v3 = toVC3(v[2]);
		}
		else if(i == 1)
		{
			v1 = toVC3(v[0]);
			v2 = toVC3(v[2]);
			v3 = toVC3(v[4]);
		}
		else if(i == 2)
		{
			v1 = toVC3(v[0]);
			v2 = toVC3(v[3]);
			v3 = toVC3(v[4]);
		}
		else if(i == 3)
		{
			v1 = toVC3(v[0]);
			v2 = toVC3(v[1]);
			v3 = toVC3(v[3]);
		}
		else if(i == 4)
		{
			v1 = toVC3(v[1]);
			v2 = toVC3(v[2]);
			v3 = toVC3(v[3]);
		}
		else if(i == 5)
		{
			v1 = toVC3(v[4]);
			v2 = toVC3(v[2]);
			v3 = toVC3(v[3]);
		}

		const ClipPolygon &clipPolygon = clipTriangleToFrustum(v1, v2, v3, frustum);
		for(int j = 0; j < clipPolygon.vertexAmount; ++j)
		{
			VC3 result;
			float rhw = 0.f;
			float real_z = 0.f;
			camera.GetTransformedToScreen(clipPolygon.vertices[j], result, rhw, real_z);

			int x = int(result.x * screenSize.x);
			int y = int(result.y * screenSize.y);
			//if(x < -1 || x > screenSize.x)
			//	continue;
			//if(y < -1 || x > screenSize.y)
			//	continue;

			x = max(x, 0);
			y = max(y, 0);
			x = min(x, screenSize.x - 1);
			y = min(y, screenSize.y - 1);

			maxX = max(x, maxX);
			maxY = max(y, maxY);
			minX = min(x, minX);
			minY = min(y, minY);

			/*
			// Visualize clipped polygons
			if(scene)
			{
				VC3 p1 = clipPolygon.vertices[j];
				VC3 p2 = clipPolygon.vertices[(j + 1) % clipPolygon.vertexAmount];


				for(int k = 0; k < 5; ++k)
				{
					const VC3 &planeNormal = frustum.planeNormals[k];
					PLANE plane;

					if(k == 0)
						plane.MakeFromNormalAndPosition(planeNormal, frustum.position + planeNormal);
					else
						plane.MakeFromNormalAndPosition(planeNormal, frustum.position);
	
					float d1 = plane.GetPointRange(p1);
					float d2 = plane.GetPointRange(p2);

					if(d1 < .25f)
						p1 += planeNormal * (.25f - d1);
					if(d2 < .25f)
						p2 += planeNormal * (.25f - d2);
				}

				scene->AddLine(p1, p2, COL(1.f, 1.f, 1.f));
			}
			*/
		}
	}

	RECT rc;
	bool visible = false;

	if(maxX > minX && maxY > minY)
	{
		visible = true;
		rc.left = minX;
		rc.top = minY;
		rc.right = maxX;
		rc.bottom = maxY;
	}
	else
	{
		visible = false;
		rc.left = 0;
		rc.top = 0;
		rc.right = 1;
		rc.bottom = 1;
	}
/*
	// Visualize scissor area
	if(scene && visible)
	{
		static DWORD foo = GetTickCount();
		int dif = (GetTickCount() - foo) % 2000;
		if(dif < 1000)
			scene->Render2D_Picture(0, VC2(float(minX), float(minY)), VC2(float(maxX - minX), float(maxY - minY)), 0.5f, 0.f, 0, 0, 0, 0, false);
	}
*/
	device.SetScissorRect(&rc);
	device.SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);

	return visible;
}
예제 #29
0
void DXFrame::Render() {
	// If the device was not created successfully, return
	if(!m_pD3DDevice)
		return;
	//*************************************************************************
	RECT rect;
	GetWindowRect(m_hWnd, &rect);
	std::stringstream ss;
	D3DRECT winRect;
	winRect.x1 = rect.left;
	winRect.x2 = rect.right;
	winRect.y1 = rect.top;
	winRect.y2 = rect.bottom;

	rect.right -= rect.left;
	rect.left = 0;
	rect.bottom -= rect.top;
	rect.top = 0;

	if(D3D_OK==(m_pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR(1.0f, 0.0f, 0.0f, 0.0f), 1.0f, 0))) {
		if(SUCCEEDED(m_pD3DDevice->BeginScene())) {
			D3DXMATRIX TransMat;
			RenInfo* tempRen;
			PrimObj* tempPrim;
			SpriteObj* tempSprite;
			TextStruct* tempText;
			D3DXMATRIX scale,loc;
			//TODO: add render code
			for(int i = 0;i<=numViewPorts;++i) {
				if(m_bSplitScreen&&i!= 4)
					m_pD3DDevice->SetViewport(&viewPorts[i].viewPort);
				else
					m_pD3DDevice->SetViewport(&defaultView);
				//set cam
				D3DXMatrixLookAtLH(&TransMat,&viewPorts[i].camera.cam_pos,&viewPorts[i].camera.cam_look_pos,&viewPorts[i].camera.cam_up_vec);
				m_pD3DDevice->SetTransform(D3DTS_VIEW,&TransMat);
				D3DXMatrixPerspectiveFovLH(&TransMat,D3DXToRadian(viewPorts[i].camera.fov_deg),800/600,0.0f,viewPorts[i].camera.drawDist);
				m_pD3DDevice->SetTransform(D3DTS_PROJECTION,&TransMat);
				for(int z = 0;z < renVec.getSize();++z)
				{
					tempRen = renVec.get(z);
					if(tempRen->locCamNum==0 ||tempRen->locCamNum == i+1)
					switch(tempRen->type)
					{
					case primitive:
						tempPrim = (PrimObj*)tempRen->asset;
						m_pD3DDevice->SetTransform(D3DTS_WORLD,&tempPrim->matrix);
						m_pD3DDevice->SetStreamSource(0,tempPrim->primInfo->obj, 0, sizeof(Vertex));
						m_pD3DDevice->SetIndices(tempPrim->primInfo->objInd);
						m_pD3DDevice->SetVertexDeclaration(tempPrim->primInfo->objDec);
						//set texture
						m_pD3DDevice->SetTexture(0,tempPrim->Tex->objTex);
						m_pD3DDevice->SetMaterial(tempPrim->mat);
						//set trans
						m_pD3DDevice->SetTransform(D3DTS_WORLD, &tempPrim->matrix);
						//render
						m_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,tempPrim->primInfo->numVerts,0,tempPrim->primInfo->numPrim);
						break;
					case sprite:
						tempSprite = (SpriteObj*)tempRen->asset;
						m_pD3DSprite->Begin(NULL);
						D3DXMatrixScaling(&scale,tempSprite->scalX,tempSprite->scalY,1);
						D3DXMatrixTranslation(&loc,tempSprite->posX+viewPorts[i].viewPort.X,tempSprite->posY+viewPorts[i].viewPort.Y,1);
						loc = scale*loc;
						//set sprite trans
						m_pD3DSprite->SetTransform(&loc);
						//Draw sprite
						m_pD3DSprite->Draw(tempSprite->image->objTex,0,0,0,D3DCOLOR_ARGB(255,255,255,255));
						m_pD3DSprite->End();
						D3DXMatrixIdentity(&loc);
						D3DXMatrixIdentity(&scale);
						break;
					case text:
						tempText = (TextStruct*)tempRen->asset;
						m_pD3DFont->DrawText(0,tempText->text.c_str(),-1,&rect,DT_TOP|DT_CENTER|DT_NOCLIP,tempText->textColor);
						break;
					default:
						break;
					}
				}
			}
			//fps counter
			if(m_bSplitScreen)
				m_pD3DDevice->SetViewport(&defaultView);
			D3DXVECTOR2 lines[]  = {D3DXVECTOR2(viewPorts[0].viewPort.Width,0),D3DXVECTOR2(viewPorts[0].viewPort.Width,viewPorts[0].viewPort.Height)};
			D3DXVECTOR2 lines1[] = {D3DXVECTOR2(viewPorts[0].viewPort.Width,0),D3DXVECTOR2(viewPorts[0].viewPort.Width,defaultView.Height)};
			D3DXVECTOR2 lines2[] = {D3DXVECTOR2(0,viewPorts[0].viewPort.Height),D3DXVECTOR2(defaultView.Width,viewPorts[0].viewPort.Height)};
			switch(numViewPorts) {
			case 2:
				m_pD3DLine->Begin();
				m_pD3DLine->Draw(lines , 2, 0xFFFFFFFF);
				m_pD3DLine->End();
				break;
			case 4:
				m_pD3DLine->Begin();
				m_pD3DLine->Draw(lines1, 2, 0xFFFFFFFF);
				m_pD3DLine->Draw(lines2, 2, 0xFFFFFFFF);
				m_pD3DLine->End();
				break;
			}
			if(showFPS) 
			{
				ss<<" FPS: "<<fps;
				m_pD3DFont->DrawText(0, ss.str().c_str(), -1, &rect, DT_TOP | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));
			}
			m_pD3DDevice->EndScene();	
		}
		if(!SUCCEEDED(m_pD3DDevice->Present(NULL,NULL,NULL,NULL)))
			m_bLost = true;
	}
	//update fps counter
	cTime = GetTickCount();
	if(cTime-ltime >= 1000.0f)
	{
		fps = framCount;
		framCount = 0;
		ltime = cTime;
		++waitTime;
	}
	else
	{
		++framCount;
	}
}
예제 #30
0
void Player::testUpdate(float a_x, float a_z, float a_rot) {
	pos.x = a_x;
	pos.z = a_z;
	facing = D3DXToRadian(a_rot);
}