void NodeControlViewImpl::RotateDelta(float yaw, float pitch, float roll)
{
	collada::Property* pProp = m_transform;

	float3 coi = m_coi;

	float4x4 m;
	pProp->GetValue(m);
	MatrixTranspose(&m, &m);
	float4x4 w = m_node->GetWorld(NULL);
	float4x4 wI = m_node->GetWorldI(NULL);
	float4x4 mcoi(w);

	mcoi(3,0) = coi.x;
	mcoi(3,1) = coi.y;
	mcoi(3,2) = coi.z;

	float4x4 toCOI = mcoi*wI;
	float4x4 fromCOI;
	MatrixInverse(&fromCOI, 0, &toCOI);
	float4x4 ypr; 
	MatrixRotationYawPitchRoll(&ypr, yaw, pitch, roll);
	float4x4 result = fromCOI*ypr*toCOI;
	MatrixMultiply(&m, &result, &m);

	float4x4 m0 = m;
	MatrixTranspose(&m, &m);
	pProp->SetValue(m);

//	RemoveRoll(&coi);
}
void NodeControlViewImpl::RotateDeltaFP(float yaw, float pitch, float roll)
{
	collada::Property* pProp = m_transform;
	if( pProp )
	{
		assert(pProp->GetSize()==16);
		float4x4 m;
		pProp->GetValue(m);
		MatrixTranspose(&m, &m);
		float4x4 ypr; 
		MatrixRotationYawPitchRoll(&ypr, yaw, pitch, roll);
		MatrixTranspose(&m, &(ypr*m));
		pProp->SetValue(m);

//		RemoveRoll();
	}
}
예제 #3
0
void Camera::Render()
{
	VectorType up, position, lookAt;
	float yaw, pitch, roll;
	float rotationMatrix[9];


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

	// Setup the position of the camera in the world.
	position.position = m_position;

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

	// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
	pitch = m_rotation.x * RADIAN;
	yaw   = m_rotation.y * RADIAN;
	roll  = m_rotation.z * RADIAN;

	// Create the rotation matrix from the yaw, pitch, and roll values.
	MatrixRotationYawPitchRoll(rotationMatrix, yaw, pitch, roll);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	TransformCoord(lookAt, rotationMatrix);
	TransformCoord(up, rotationMatrix);
	
	// Translate the rotated camera position to the location of the viewer.
	lookAt.position.x = position.position.x + lookAt.position.x;
	lookAt.position.y = position.position.y + lookAt.position.y;
	lookAt.position.z = position.position.z + lookAt.position.z;

	// Finally create the view matrix from the three updated vectors.
	BuildViewMatrix(position, lookAt, up);
}
예제 #4
0
CameraInstance* CreateDefaultCamera(EditableScene *es, const char *camTag, const char *nodeTag, const char *instTag)
{
	Camera *pCamera = es->CreateCamera();
	pCamera->SetTag(camTag);
	Node *pNode = es->CreateNode(NULL);
	pNode->SetTag(nodeTag);
	CameraInstance *pCI = es->CreateCameraInstance(pNode, pCamera);
	pCI->SetTag(instTag);
	Property* pTransform = pNode->AppendTransform(Transform::MATRIX, Zero)->GetDelegate(NULL);

	AutoPtr<AccessProviderLocal> providerLocal;
	CreateAccessProviderLocal(&providerLocal);

	float3 aabb(es->GetSceneAABB(-1, 0, providerLocal));
	float3 center(es->GetSceneCenter(-1, 0, providerLocal));
	float4x4 ypr;
	MatrixRotationYawPitchRoll(&ypr, 3.141692f/4, -3.141692f/4, 0);

	float4x4 t0;
	MatrixTranslation(&t0, center.x, center.y, center.y);

	float4x4 t1;
	float bbD = Vec3Length(&aabb);
	MatrixTranslation(&t1, 0, 0, bbD*2);
	float4x4 up = es->GetUpAxis();
	float4x4 upI;
	MatrixInverse(&upI, 0, &up);
	float4x4 minusZ;
	MatrixScaling(&minusZ, 1,1,-1);
	float4x4 m = t1*ypr*t0*minusZ*upI;
	MatrixTranspose(&m, &m);
	pTransform->SetValue(m);
	pCamera->SetFar(10*bbD);

	return pCI;
}