コード例 #1
0
void TempController::update( float p_dt )
{
	// normalize input
	glm::normalize(m_moveThrustDir);
	//glm::normalize(m_moveAngularThrustDir);

	// apply damping
	m_velocity -= m_velocity*m_damping*p_dt;
	m_angularVelocity -= m_angularVelocity*m_angularDamping*p_dt;

	// apply "force" vector on rotation
	m_angularVelocity += m_moveAngularThrustDir*m_angularThrustPower*p_dt;
	

	// update rotation
	rotate(m_angularVelocity*p_dt);

	// calc new rotation
	calcRotationMatrix();
	calcViewProjMatrix(m_fovYAngle, m_aspect);

	// apply "force" vector on velocity
	m_velocity += glm::vec4(m_moveThrustDir*m_thrustPower*p_dt,0.0f)*m_rotationMat;

	// update position
	m_position += m_velocity*p_dt;

	// restore input
	m_moveThrustDir=glm::vec3();
	m_moveAngularThrustDir=glm::vec3();
}
コード例 #2
0
ファイル: Renderer.cpp プロジェクト: fluier/BallProject
	void Renderer::render(Entity& entity,GLSLProgram& shader)
	{
		mat4 rotMatrix;
		mat4 translationMatrix;
		mat4 transformMatrix;

		prepare();
		time += 0.0001f;
		entity.increaseRotation(0.0, 0.0, 0.0);
		entity.increasePosition(0, 0, 0);

		translationMatrix = calcTranslationMatrix(entity.getPosition().x, entity.getPosition().y, entity.getPosition().z);
		rotMatrix = calcRotationMatrix(entity.getRotX(), entity.getRotY(), entity.getRotZ());
		transformMatrix = rotMatrix * translationMatrix;
		
		
		shader.setUniformMatrix4fv("transformMatrix", transformMatrix);

		TexturedModel texturedModel = entity.getTexturedModel();
		RawModel model = texturedModel.getRawModel();
		glBindBuffer(GL_ARRAY_BUFFER, model.getVboID());
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,model.getIndices());
		glActiveTexture(GL_TEXTURE0);
		texturedModel.getModelTexture().bind();
		glEnableVertexAttribArray(0);
		glEnableVertexAttribArray(1);
		glEnableVertexAttribArray(2);
		glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(Vertex), (void*)offsetof(Vertex, position));
		glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex, color));
		glVertexAttribPointer(2, 2, GL_FLOAT, false, sizeof(Vertex), (void*)offsetof(Vertex, uv));
		//glDrawArrays(GL_TRIANGLES, 0, model.getVertexCount());
		//glDrawElements(GL_LINES, model.getVertexCount(), GL_UNSIGNED_INT, 0);
		glDrawElements(GL_TRIANGLES,model.getVertexCount(), GL_UNSIGNED_INT,0);
		glDisableVertexAttribArray(0);
		glDisableVertexAttribArray(1);
		glDisableVertexAttribArray(2);

		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
		texturedModel.getModelTexture().unbind();

	}