示例#1
0
void CTouchFreeCamera::Update(float dt)
{
	if(m_isDragging)
	{
		float deltaX = m_dragPosition.x - m_mousePosition.x;
		float deltaY = m_dragPosition.y - m_mousePosition.y;
		m_cameraHAngle = m_dragHAngle + deltaX * 0.015f;
		m_cameraVAngle = m_dragVAngle + deltaY * 0.015f;
		m_cameraVAngle = std::min<float>(m_cameraVAngle, M_PI / 2);
		m_cameraVAngle = std::max<float>(m_cameraVAngle, -M_PI / 2);
	}

	CMatrix4 yawMatrix(CMatrix4::MakeAxisYRotation(m_cameraHAngle));
	CMatrix4 pitchMatrix(CMatrix4::MakeAxisXRotation(m_cameraVAngle));
	CMatrix4 rotationMatrix = yawMatrix * pitchMatrix;

	if(m_isStrafingLeft || m_isStrafingRight)
	{
		CVector3 rightVector = CVector3(1, 0, 0) * rotationMatrix;
		float direction = m_isStrafingLeft ? (-1.0f) : (1.0f);
		m_cameraPosition += (rightVector * direction * MOVE_SPEED * dt);
	}
	if(m_isMovingForward || m_isMovingBackward)
	{
		CVector3 forwardVector = CVector3(0, 0, 1) * rotationMatrix;
		float direction = m_isMovingForward ? (-1.0f) : (1.0f);
		m_cameraPosition += (forwardVector * direction * MOVE_SPEED * dt);
	}

	CMatrix4 translationMatrix(CMatrix4::MakeTranslation(-m_cameraPosition.x, -m_cameraPosition.y, -m_cameraPosition.z));
	CMatrix4 totalMatrix = translationMatrix * rotationMatrix;

	SetViewMatrix(totalMatrix);
}
示例#2
0
void CActorViewer::Update(float dt)
{
	{
		if(m_commandMode == COMMAND_MODE_DRAG_CAMERA)
		{
			float deltaX = m_dragPosition.x - m_mousePosition.x;
			float deltaY = m_dragPosition.y - m_mousePosition.y;
			m_cameraHAngle = m_dragHAngle + deltaX * 0.015f;
			m_cameraVAngle = m_dragVAngle + deltaY * 0.015f;
			m_cameraVAngle = std::min<float>(m_cameraVAngle, M_PI / 2);
			m_cameraVAngle = std::max<float>(m_cameraVAngle, -M_PI / 2);
		}

		CMatrix4 yawMatrix(CMatrix4::MakeAxisYRotation(m_cameraHAngle));
		CMatrix4 pitchMatrix(CMatrix4::MakeAxisXRotation(m_cameraVAngle));

		CMatrix4 rotationMatrix = yawMatrix * pitchMatrix;
		if(m_actorRotationNode)
		{
			m_actorRotationNode->SetRotation(rotationMatrix);
		}
	}
	m_mainViewport->GetSceneRoot()->Update(dt);
	m_mainViewport->GetSceneRoot()->UpdateTransformations();

	if(m_debugOverlay)
	{
		m_debugOverlay->Update(dt);
	}

	m_elapsed += dt;

}
void Object::rotateInAxisX(GLfloat pitchAngle) 
{
    mat4 pitchMatrix(1.0f);
    vec3 origin_aux = origin;
    
    translate(-origin_aux);

    pitchMatrix = rotate(pitchMatrix, pitchAngle, axisX);   

    axisX = vec3(pitchMatrix * vec4(axisX, 1.0f));
    axisY = vec3(pitchMatrix * vec4(axisY, 1.0f));
    axisZ = vec3(pitchMatrix * vec4(axisZ, 1.0f));

    transformations = pitchMatrix * transformations;

    translate(origin_aux);
}
void dCustomBallAndSocket::Debug(dDebugDisplay* const debugDisplay) const
{
	dMatrix matrix0;
	dMatrix matrix1;

	dCustomJoint::Debug(debugDisplay);

	CalculateGlobalMatrix(matrix0, matrix1);

	const dVector& coneDir0 = matrix0.m_front;
	const dVector& coneDir1 = matrix1.m_front;
	dFloat cosAngleCos = coneDir0.DotProduct3(coneDir1);
	dMatrix coneRotation(dGetIdentityMatrix());
	if (cosAngleCos < 0.9999f) {
		dVector lateralDir(coneDir1.CrossProduct(coneDir0));
		dFloat mag2 = lateralDir.DotProduct3(lateralDir);
		//dAssert(mag2 > 1.0e-4f);
		if (mag2 > 1.0e-4f) {
			lateralDir = lateralDir.Scale(1.0f / dSqrt(mag2));
			coneRotation = dMatrix(dQuaternion(lateralDir, dAcos(dClamp(cosAngleCos, dFloat(-1.0f), dFloat(1.0f)))), matrix1.m_posit);
		} else {
			lateralDir = matrix0.m_up.Scale(-1.0f);
			coneRotation = dMatrix(dQuaternion(matrix0.m_up, 180 * dDegreeToRad), matrix1.m_posit);
		}
	} else if (cosAngleCos < -0.9999f) {
		coneRotation[0][0] = -1.0f;
		coneRotation[1][1] = -1.0f;
	}

	const int subdiv = 18;
	const dFloat radius = debugDisplay->m_debugScale;
	dVector arch[subdiv + 1];

	// show twist angle limits
	if (m_options.m_option0 && ((m_maxTwistAngle - m_minTwistAngle) > dFloat(1.0e-3f))) {
		dMatrix pitchMatrix(matrix1 * coneRotation);
		pitchMatrix.m_posit = matrix1.m_posit;

		dVector point(dFloat(0.0f), dFloat(radius), dFloat(0.0f), dFloat(0.0f));

		dFloat angleStep = dMin (m_maxTwistAngle - m_minTwistAngle, dFloat (2.0f * dPi)) / subdiv;
		dFloat angle0 = m_minTwistAngle;

		debugDisplay->SetColor(dVector(0.6f, 0.2f, 0.0f, 0.0f));
		for (int i = 0; i <= subdiv; i++) {
			arch[i] = pitchMatrix.TransformVector(dPitchMatrix(angle0).RotateVector(point));
			debugDisplay->DrawLine(pitchMatrix.m_posit, arch[i]);
			angle0 += angleStep;
		}

		for (int i = 0; i < subdiv; i++) {
			debugDisplay->DrawLine(arch[i], arch[i + 1]);
		}
	}

	// show cone angle limits
	if (m_options.m_option2) {
		dVector point(radius * dCos(m_maxConeAngle), radius * dSin(m_maxConeAngle), 0.0f, 0.0f);
		dFloat angleStep = dPi * 2.0f / subdiv;
		dFloat angle0 = 0.0f;
		debugDisplay->SetColor(dVector(0.3f, 0.8f, 0.0f, 0.0f));

		for (int i = 0; i <= subdiv; i++) {
			dVector conePoint(dPitchMatrix(angle0).RotateVector(point));
			dVector p(matrix1.TransformVector(conePoint));
			arch[i] = p;
			debugDisplay->DrawLine(matrix1.m_posit, p);
			angle0 += angleStep;
		}

		for (int i = 0; i < subdiv; i++) {
			debugDisplay->DrawLine(arch[i], arch[i + 1]);
		}
	}
}