示例#1
0
void DXCamera::MoveForward( float	speed, float y )
{
	D3DXVECTOR3 zVec( _view._13, _view._23 * y, _view._33 );
	D3DXVec3Normalize( &zVec, &zVec );

	_eyeVec += zVec * speed;
	_lookVec += zVec * speed;
}
示例#2
0
文件: BulletNode.cpp 项目: dovalec/3D
void BulletNode::ShootState()
{
	SetupTarget();

	mBulletStartingPos = mBulletPos = mShooterNode->GetWorldTranslation();
	
	if (mTargetNode)
		mTargetPos = mTargetNode->GetWorldTranslation();	


	PVRTVec3 dir =  mBulletPos - mTargetPos;
	mBulletPos -= dir * 0.1f;

	float rotAngle = atan2f(dir.z, dir.x) + PVRT_PI*0.5f;


	static int randIndex = 0;
	const static float randTable[RAND_TABLE_SIZE] = {1,-4,3,-2,5,-3,6,-5,2,-3,4,-2,4,-5,5,-3,4,-5,6,-3};
	if (mNoisy)
    {
        rotAngle = rotAngle + 0.25f * randTable[randIndex++ % RAND_TABLE_SIZE] * (0.017453292f);
	}

	PVRTQUATERNION shooterQuat;
	PVRTMatrixQuaternionRotationAxis(shooterQuat, PVRTVec3(0,1,0),rotAngle);

	PVRTMATRIX shooterRotaionMtx;
	PVRTMatrixRotationQuaternion(shooterRotaionMtx, shooterQuat);

	PVRTMat4 mat(shooterRotaionMtx.f);
	PVRTVec4 zVec(0, 0 , 1.0f, 1.0f);
	zVec = mat * zVec;


/*
	if (mAutoAim)
	{
		mDir = mBulletPos - mTargetNode->GetWorldTranslation();
		mDir.normalize();
	}
*/	
	mDir.x = zVec.x;
	mDir.y = zVec.y;
	mDir.z = zVec.z;

	//mDir.z = 0;
	//mDir.x = -1;

	mModelData->GetRoot()->SetRotation(shooterQuat);

	mState = state_fly;

}
示例#3
0
文件: BulletNode.cpp 项目: dovalec/3D
void BulletNode::SetupTarget()
{
			
	PVRTMATRIX weaponRotaionMtx = mDirectionNode->GetWorldMtx();
	
	PVRTMat4 mat(weaponRotaionMtx.f);
	PVRTVec4 zVec(0, 0 , mRange, 1.0f);
	zVec = mat * zVec;

	PVRTVec3 targetPos;
	
	
	targetPos.x = zVec.x;
	targetPos.y = zVec.y;
	targetPos.z = zVec.z;

	SetTargetPos(targetPos);
}
示例#4
0
////////////////////////////////////////
//		PUBLIC UTILITY FUNCTIONS
////////////////////////////////////////
void Camera::Render()
{
	D3DXVECTOR3 up, position, lookAt;
	float yaw, pitch, roll;
	D3DXMATRIX rotationMatrix;
	D3DXMatrixIdentity(&rotationMatrix);


	// Setup the vector that points upwards.
	up.x = 0.0f;
	up.y = 1.0f;
	up.z = 0.0f;

	// Setup the position of the camera in the world.
	position.x = m_positionX;
	position.y = m_positionY;
	position.z = m_positionZ;

	// Setup where the camera is looking by default.
	lookAt.x = 0.0f;
	lookAt.y = 0.0f;
	lookAt.z = 1.0f;

	// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
	pitch = m_rotationX * 0.0174532925f;
	yaw   = m_rotationY * 0.0174532925f;
	roll  = m_rotationZ * 0.0174532925f;
			
	// Create the rotation matrix from the yaw, pitch, and roll values.
	D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, roll);

	// Move position based on local X/Y/Z vectors
	D3DXVECTOR3 xVec(rotationMatrix._11,rotationMatrix._12,rotationMatrix._13);
	D3DXVECTOR3 yVec(rotationMatrix._21,rotationMatrix._22,rotationMatrix._23);
	D3DXVECTOR3 zVec(rotationMatrix._31,rotationMatrix._32,rotationMatrix._33);

	// Get amount to add to position
	D3DXVec3Scale(&xVec,&xVec,m_moveDelta.x);
	D3DXVec3Scale(&yVec,&yVec,m_moveDelta.y);
	D3DXVec3Scale(&zVec,&zVec,m_moveDelta.z);

	// Autobots: roll out!
	position += xVec + yVec + zVec;
	// Save new position
	m_positionX = position.x;
	m_positionY = position.y;
	m_positionZ = position.z;

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix);
	D3DXVec3TransformCoord(&up, &up, &rotationMatrix);

	


	// Translate the rotated camera position to the location of the viewer.
	lookAt = position + lookAt;

	// Finally create the view matrix from the three updated vectors.
    D3DXMatrixLookAtLH(&m_viewMatrix, &position, &lookAt, &up);

	return;
}