コード例 #1
0
ファイル: freeCamera.cpp プロジェクト: rokuz/DemoScene
void FreeCamera::update(double elapsedTime, uint32_t screenWidth, uint32_t screenHeight)
{
	if (m_rotationMode)
	{
		m_updateTime += elapsedTime;
		if (m_updateTime >= 1.0f / 60.0f)
		{
			vector2 delta = m_currentMousePosition - m_lastMousePosition;
			if (fabs(delta.x) > 1e-5 || fabs(delta.y) > 1e-5)
			{
				float ang = this->m_camera.GetAngleOfView() * 0.5f;
				float w = this->m_camera.GetNearPlane() * n_tan(n_deg2rad(ang));
				float h = w / this->m_camera.GetAspectRatio();

				float ax = n_rad2deg(atan2(w * (2.0f * delta.x / screenWidth), this->m_camera.GetNearPlane()));
				float ay = n_rad2deg(atan2(h * (2.0f * delta.y / screenHeight), this->m_camera.GetNearPlane()));

				vector2 old_angles = m_angles;
				m_angles.x -= float(ax * 100.0 * m_updateTime);
				m_angles.y += float(ay * 100.0 * m_updateTime);
				if (m_angles.y > 89.9f) m_angles.y = 89.9f;
				if (m_angles.y < -89.9) m_angles.y = -89.9f;

				if (!old_angles.isequal(m_angles, 0.00001f))
				{
					quaternion q1;
					q1.set_rotate_axis_angle(vector3(0, 1, 0), n_deg2rad(m_angles.x));
					quaternion q2;
					q2.set_rotate_axis_angle(vector3(1, 0, 0), n_deg2rad(m_angles.y));
					m_orientation = q1 * q2;
				}

				m_lastMousePosition = m_currentMousePosition;
			}

			m_updateTime -= 1.0f / 60.0f;
		}
	}

	if (m_moveForward)
	{
		m_position += (m_orientation.z_direction() * m_speed * (float)elapsedTime);
	}

	if (m_moveBackward)
	{
		m_position -= (m_orientation.z_direction() * m_speed * (float)elapsedTime);
	}

	if (m_moveLeft)
	{
		m_position += (m_orientation.x_direction() * m_speed * (float)elapsedTime);
	}

	if (m_moveRight)
	{
		m_position -= (m_orientation.x_direction() * m_speed * (float)elapsedTime);
	}
}
コード例 #2
0
// Create the abstract composite for the character entity when the entity
// is "alive" (not in its ragdoll state).
void CCharEntity::CreateDefaultComposite()
{
	DefaultComposite = CComposite::Create();

	PRigidBody BaseBody = CRigidBody::Create();
	BaseBody->Name = "CharEntityBody";

	float CapsuleLength = Height - 2.0f * Radius - Hover;
	matrix44 UpRight;
	UpRight.rotate_x(n_deg2rad(90.0f));
	UpRight.translate(vector3(0.0f, Hover + Radius + CapsuleLength * 0.5f, 0.0f));
	PShape pShape = (CShape*)PhysicsSrv->CreateCapsuleShape(UpRight,
		CMaterialTable::StringToMaterialType("Character"), Radius, CapsuleLength);
	BaseBody->BeginShapes(1);
	BaseBody->AddShape(pShape);
	BaseBody->EndShapes();
	DefaultComposite->BeginBodies(1);
	DefaultComposite->AddBody(BaseBody);
	DefaultComposite->EndBodies();

	Ptr<CAMotor> AMotor = CAMotor::Create();
	AMotor->SetBodies(BaseBody, NULL);
	AMotor->SetNumAxes(2);
	AMotor->AxisParams[0].Axis = vector3(1.0f, 0.0f, 0.0f);
	AMotor->AxisParams[1].Axis = vector3(0.0f, 0.0f, 1.0f);
	AMotor->AxisParams[0].FMax = 100000.0f;
	AMotor->AxisParams[1].FMax = 100000.0f;
	DefaultComposite->BeginJoints(1);
	DefaultComposite->AddJoint(AMotor);
	DefaultComposite->EndJoints();
}
コード例 #3
0
ファイル: freeCamera.cpp プロジェクト: rokuz/DemoOpenGL
void FreeCamera::update(double elapsedTime)
{
	if (m_moveForward)
	{
		m_position += (m_orientation.z_direction() * m_speed * (float)elapsedTime);
	}

	if (m_moveBackward)
	{
		m_position -= (m_orientation.z_direction() * m_speed * (float)elapsedTime);
	}

	if (m_moveLeft)
	{
		m_position += (m_orientation.x_direction() * m_speed * (float)elapsedTime);
	}

	if (m_moveRight)
	{
		m_position -= (m_orientation.x_direction() * m_speed * (float)elapsedTime);
	}

	if (m_rotationMode)
	{
		vector2 delta = m_currentMousePosition - m_lastMousePosition;
		vector2 old_angles = m_angles;
		m_angles.x -= delta.x * 200.0f * (float)elapsedTime;
		m_angles.y += delta.y * 200.0f * (float)elapsedTime;
		if (m_angles.y > 89.9f) m_angles.y = 89.9f;
		if (m_angles.y < -89.9) m_angles.y = -89.9f;
		//Logger::toLogWithFormat("angles = (%.2f; %.2f)\n", m_angles.x, m_angles.y);

		if (!old_angles.isequal(m_angles, 0.001f))
		{
			quaternion q1;
			q1.set_rotate_axis_angle(vector3(0, 1, 0), n_deg2rad(m_angles.x));
			quaternion q2;
			q2.set_rotate_axis_angle(vector3(1, 0, 0), n_deg2rad(m_angles.y));
			m_orientation = q1 * q2;
		}

		m_lastMousePosition = m_currentMousePosition;
	}
}
コード例 #4
0
void CSensorVision::Init(const CParams& Desc)
{
	//CSensor::Init(Desc);
	FOV = cosf(n_deg2rad(Desc.Get<int>(CStrID("FOV"), 0)));
	Radius = Desc.Get<float>(CStrID("Radius"), 0.f);
}