예제 #1
0
//////////////////////////////////////////////////////////////////////////
// Position the body precisely
//////////////////////////////////////////////////////////////////////////
void DropDownBox(NewtonBody *body)
{
	float matrix[16];
	NewtonBodyGetMatrix(body, matrix);
	Matrix4 m = Matrix4(matrix);

	Vector3 pos = m.GetPosition();
	pos.y += 1.0f;
	m.SetPosition(pos);
	Vector3 p = pos;
	p.y -= 20;

	// cast collision shape within +20 -20 y range
	NewtonWorld *world = NewtonBodyGetWorld(body);
	NewtonCollision *collision = NewtonBodyGetCollision(body);

	float param;
	NewtonWorldConvexCastReturnInfo info[16];
	m.FlattenToArray(matrix);
	NewtonWorldConvexCast(world, matrix, &p[0], collision, &param, body, DropDownConvexCastCallback, info, 16, 0);

	m = Matrix4(matrix);
	pos = m.GetPosition();
	m.SetPosition(pos + Vector3(0, (p.y - pos.y) * param, 0) );

	m.FlattenToArray(matrix);
	NewtonBodySetMatrix(body, matrix);
}
예제 #2
0
void Riding::Draw(Renderer & renderer)
{
	Vector3 p = renderer.GetBonePosition(modelName, 35);

	Matrix4 wandMatrix;
	wandMatrix.SetPosition(p + Vector3(0,-1,0)).SetScale(0.01f,0.01f,0.01f);

	renderer.Draw3DModel("wand", wandMatrix);
}
예제 #3
0
NewtonBody* CPhysics::CreateBox(NewtonWorld *world, CObject3D *object, float x, float y, float z, float mass, Vector3 offset)
{
	Matrix4 offsetMat;
	offsetMat.SetPosition(offset);
	float m[16];
	offsetMat.FlattenToArray(m);

	NewtonCollision *collision = NewtonCreateBox(world, x, y, z, 0, m);
	return CreateRigidBody(world, object, collision, mass);	
}
예제 #4
0
  void StarSystemSimulation::Simulate(Entity *simulationParent, float deltaT) 
  {
    base::Simulate(simulationParent, deltaT);

    CheckNull(simulationParent);
    ObejctState *simulationState = simulationParent->GetSimulationState();
    CheckNull(simulationState);

    Matrix4 translateToPosition;
    translateToPosition.SetIdentityMatrix();
    translateToPosition.SetPosition(GGame->GetCamera()->GetPosition());

    simulationState->_frame = translateToPosition;
  }
예제 #5
0
	void ParticlePool::BuildVertexData()
	{
		Matrix4 transform = matViewInv;
		Matrix3 localRot = transform.GetRotationMatrix();

		// 计算顶点法线信息
		Vector3f normal = localRot * Vector3f(0.0f, 0.0f, 1.0f);

		// 每帧构造新的顶点缓冲,用于渲染
		std::vector<Particle>::iterator iter = m_Particles.begin();
		for (unsigned int i=0; i<m_ActiveParticleCount; i++, iter++)
		{
			// 更新顶点颜色
			float new_color[16];
			for (int j=0; j<4; j++)
				memcpy(&(new_color[j*4]), iter->m_Color.GetArray(), sizeof(float) * 4);

			m_VertexBuffer->ModifyVertexData(VFormat_Color, 16 * i/*iter->m_VertexOffset*/, sizeof(float) * 16, new_color);

			Vector3f points[4] = { Vector3f(-0.5f, 0.5f, 0.0f),
				Vector3f(0.5f, 0.5f, 0.0f),
				Vector3f(-0.5f, -0.5f, 0.0f),
				Vector3f(0.5f, -0.5f, 0.0f) };

			float new_pos[12];
			float new_normal[12];

			// 生成billboard顶点的方向
			transform.SetPosition(iter->m_Position);

			Matrix3 rotMat = Matrix3::BuildRollRotationMatrix(iter->spin);
			for (int j=0; j<4; j++)
			{
				// 根据缩放等属性计算顶点位置信息
				Vector3f point = rotMat * (points[j] * iter->scale);
				//point.z = iter->m_ZOffset;
				point.x *= iter->m_ScreenScaleX;
				point.y *= iter->m_ScreenScaleY;

				point = transform * point;

				//point += iter->m_Position;
				memcpy(&new_pos[j*3], point.GetArray(), sizeof(float) * 3);

				memcpy(&new_normal[j*3], normal.GetArray(), sizeof(float) * 3);
			}

			m_VertexBuffer->ModifyVertexData(VFormat_Position, 12 * i/*iter->m_VertexOffset*/, sizeof(float) * 12, new_pos);
			m_VertexBuffer->ModifyVertexData(VFormat_Normal, 12 * i, sizeof(float) * 12, new_normal);

			float uv[] = { 0.0f, 1.0f,
				1.0f, 1.0f,
				0.0f, 0.0f,
				1.0f, 0.0f };
			m_VertexBuffer->ModifyVertexData(VFormat_Texcoord0, 8 * i, sizeof(float) * 8, uv);

		}

		// 更新索引缓冲数据,处理有效粒子数目变化的情况
		m_IndexBuffer->SetIndexSize(m_ActiveParticleCount * 2);
		iter = m_Particles.begin();
		for (unsigned int i=0; i<m_ActiveParticleCount; i++, iter++)
		{
			//unsigned int offset = iter->m_IndexOffset;
			unsigned int index[6] = { i * 4, 2 + i * 4, 1 + i * 4,
				2 + i * 4, 3 + i * 4, 1 + i * 4 };
			m_IndexBuffer->ModifyIndexData(6 * i, sizeof(unsigned int) * 6, index);
		}
	}
예제 #6
0
void StageManager::Draw(Renderer & renderer)
{
	if (name == "None")return;
	Matrix4 matrix;
	renderer.Draw3DModel("stage", matrix.SetPosition(position).SetRotateY(180));
}