Ejemplo n.º 1
0
void Camera::rotateView(float angle, float x, float y, float z)
{
  Tuple3f newView,
  vView = focus;
  
  float cosTheta = fastCos(angle), sinTheta = fastSin(angle);
  
  vView -= position;
  
  // Find the new x position for the new rotated point
  newView.x = (cosTheta + (1 - cosTheta) * x * x)  * vView.x;
  newView.x += ((1 - cosTheta) * x * y - z * sinTheta) * vView.y;
  newView.x += ((1 - cosTheta) * x * z + y * sinTheta) * vView.z;
  
  // Find the new y position for the new rotated point
  newView.y = ((1 - cosTheta) * x * y + z * sinTheta) * vView.x;
  newView.y += (cosTheta + (1 - cosTheta) * y * y)  * vView.y;
  newView.y += ((1 - cosTheta) * y * z - x * sinTheta) * vView.z;
  
  // Find the new z position for the new rotated point
  newView.z = ((1 - cosTheta) * x * z - y * sinTheta) * vView.x;
  newView.z += ((1 - cosTheta) * y * z + x * sinTheta) * vView.y;
  newView.z += (cosTheta + (1 - cosTheta) * z * z)  * vView.z;
  
  // Now we just add the newly rotated vector to our position to set
  // our new rotated view of our camera.
  focus = position;
  focus += newView;
}
Ejemplo n.º 2
0
void DummyJumper::update(double elapsed_time)
{
	m_phase += 360 * m_speed * elapsed_time;
	if(m_phase > 360) {
		m_phase -= 360;
	}
	node()->move(m_amplitude*m_speed*elapsed_time*fastCos(m_phase)*Vector3f(0,1,0)); // Instable, integrale powered (yeah :D)
}
Ejemplo n.º 3
0
void Singleton::loadMatrix(char axis, int angle)
{
	if(axis=='x')
	{
	rotationMatrix->setElement(0,0,1);
	rotationMatrix->setElement(0,1,0);
	rotationMatrix->setElement(0,2,0);

	rotationMatrix->setElement(1,0,0);
	rotationMatrix->setElement(1,1,fastCos(angle));
	rotationMatrix->setElement(1,2,-fastSin(angle));

	rotationMatrix->setElement(2,0,0);
	rotationMatrix->setElement(2,1,fastSin(angle));
	rotationMatrix->setElement(2,2,fastCos(angle));
	}
	if(axis=='y')
	{
	rotationMatrix->setElement(0,0,fastCos(angle));
	rotationMatrix->setElement(0,1,0);
	rotationMatrix->setElement(0,2,fastSin(angle));

	rotationMatrix->setElement(1,0,0);
	rotationMatrix->setElement(1,1,1);
	rotationMatrix->setElement(1,2,0);

	rotationMatrix->setElement(2,0,-fastSin(angle));
	rotationMatrix->setElement(2,1,0);
	rotationMatrix->setElement(2,2,fastCos(angle));
	}
	if(axis=='z')
	{
		rotationMatrix->setElement(0,0,fastCos(angle));
	rotationMatrix->setElement(0,1,-fastSin(angle));
	rotationMatrix->setElement(0,2,0);

	rotationMatrix->setElement(1,0,fastSin(angle));
	rotationMatrix->setElement(1,1,fastCos(angle));
	rotationMatrix->setElement(1,2,0);

	rotationMatrix->setElement(2,0,0);
	rotationMatrix->setElement(2,1,0);
	rotationMatrix->setElement(2,2,1);
	}
}
Ejemplo n.º 4
0
void Light::drawDebug(const GLWidget* widget, const RenderManager::DebugGizmosFilter& filter) const
{
	if(filter.draw_lights)
	{
		widget->qglColor(Qt::yellow);
		glBegin(GL_LINE_LOOP);
		for(int i=0 ; i<360 ; i+=10) {
			float sin = fastSin(i)/10;
			float cos = fastCos(i)/10;
			glVertex3d(0,sin,cos);
		}
		glEnd();
		glBegin(GL_LINE_LOOP);
		for(int i=0 ; i<360 ; i+=10) {
			float sin = fastSin(i)/10;
			float cos = fastCos(i)/10;
			glVertex3d(sin,0,cos);
		}
		glEnd();
		glBegin(GL_LINE_LOOP);
		for(int i=0 ; i<360 ; i+=10) {
			float sin = fastSin(i)/10;
			float cos = fastCos(i)/10;
			glVertex3d(sin,cos,0);
		}
		glEnd();


		if(m_type == SPOT || m_type == SUN)
		{
			glPushMatrix();

			if(m_type == SUN)
			{
				glLoadIdentity();
				#ifndef MERGEFORSUN
					Viewpoint* targetVp = RENDER_MANAGER.getRenderPassInfo()->lod_viewpoint;
					targetVp->applyTransform(0);
				#endif
			}

			Matrix4d mat;
			if(m_type == SUN)
			{
				computePSSM(mat, 0);
			}
			else
			{
				computeLightFrustum(mat);
			}
			mat.invert();
			glMultMatrixd(mat.values);

			glBegin(GL_LINES);
				glVertex3d(-1,-1,-1);
				glVertex3d( 1,-1,-1);

				glVertex3d(-1,-1,-1);
				glVertex3d(-1, 1,-1);

				glVertex3d(-1,-1,-1);
				glVertex3d(-1,-1, 1);

				glVertex3d( 1,-1,-1);
				glVertex3d( 1, 1,-1);

				glVertex3d( 1,-1,-1);
				glVertex3d( 1,-1, 1);

				glVertex3d(-1, 1,-1);
				glVertex3d( 1, 1,-1);

				glVertex3d(-1, 1,-1);
				glVertex3d(-1, 1, 1);

		widget->qglColor(Qt::red);
				glVertex3d(-1,-1, 1);
				glVertex3d( 1,-1, 1);

				glVertex3d(-1,-1, 1);
				glVertex3d(-1, 1, 1);

				glVertex3d( 1, 1, 1);
				glVertex3d(-1, 1, 1);

				glVertex3d( 1, 1, 1);
				glVertex3d( 1,-1, 1);

		widget->qglColor(Qt::yellow);
				glVertex3d( 1, 1, 1);
				glVertex3d( 1, 1,-1);
			glEnd();

			glPopMatrix();
		}
	}
}
Ejemplo n.º 5
0
float Singleton::fastCos(float angle)
{
	return fastCos((int)angle);
}
Ejemplo n.º 6
0
PrimitiveMesh* PrimitiveMesh::buildSphere(int rings, int segments)
{
	PrimitiveMesh* ret = new PrimitiveMesh(QString("Sphere_")+QString().setNum(rings)+QString("_")+QString().setNum(segments));

	int nbVertex = (rings+1) * (segments+1);

	GLfloat* vertices = new GLfloat[3*nbVertex]();
	GLfloat* normals = new GLfloat[3*nbVertex]();
	GLfloat* tangents = new GLfloat[3*nbVertex]();
	GLfloat* bitangents = new GLfloat[3*nbVertex]();
	GLfloat* texcoords = new GLfloat[2*nbVertex]();

	// Vertex
	for(int r=0 ; r<rings+1 ; r++) {
		for(int s=0 ; s<segments+1 ; s++) {
			int index = (s + r * (segments+1));
			float phi = 360 * (float(s)/segments);
			float theta = 180 * (float(r)/rings);
			float x = fastSin(theta) * fastCos(phi);
			float y = fastCos(theta);
			float z = fastSin(theta) * fastSin(phi);
			float tx = fastSin(theta) * fastCos(phi + 90);
			float ty = fastCos(theta);
			float tz = fastSin(theta) * fastSin(phi + 90);
			float bx = fastSin(theta + 90) * fastCos(phi);
			float by = fastCos(theta + 90);
			float bz = fastSin(theta + 90) * fastSin(phi);
			// Vertex
			vertices[3*index + 0] = 0.5 *  x;
			vertices[3*index + 1] = 0.5 *  y;
			vertices[3*index + 2] = 0.5 *  z;

			// Normal
			normals[3*index + 0] = x;
			normals[3*index + 1] = y;
			normals[3*index + 2] = z;

			// Tangents
			tangents[3*index + 0] = tx;
			tangents[3*index + 1] = ty;
			tangents[3*index + 2] = tz;

			// Bitangents
			bitangents[3*index + 0] = bx;
			bitangents[3*index + 1] = by;
			bitangents[3*index + 2] = bz;

			// Texcoord
			texcoords[2*index + 0] = float(s)/segments;
			texcoords[2*index + 1] = float(r)/rings;
		}
	}

	ret->m_nbFaces = 2 * rings * segments;

	GLshort* indices = new GLshort[3* ret->m_nbFaces]();
	GLshort* ptrIndices = indices;

	for(int r=0 ; r<rings ; r++) {
		for(int s=0 ; s<segments ; s++) {

		*ptrIndices = s   +  r    * (segments+1); ptrIndices++;
		*ptrIndices = s+1 +  r    * (segments+1); ptrIndices++;
		*ptrIndices = s+1 + (r+1) * (segments+1); ptrIndices++;

		*ptrIndices = s   +  r    * (segments+1); ptrIndices++;
		*ptrIndices = s+1 + (r+1) * (segments+1); ptrIndices++;
		*ptrIndices = s   + (r+1) * (segments+1); ptrIndices++;

		}
	}

	// Set up Vertices VBO
	ret->m_vertices.create();
	ret->m_vertices.bind();
	ret->m_vertices.setUsagePattern(QGLBuffer::StaticDraw);
	ret->m_vertices.allocate(vertices, sizeof(GLfloat) * nbVertex * 3);

	// Set up Normals VBO
	ret->m_normals.create();
	ret->m_normals.bind();
	ret->m_normals.setUsagePattern(QGLBuffer::StaticDraw);
	ret->m_normals.allocate(normals, sizeof(GLfloat) * nbVertex * 3);

	// Set up Tangents VBO
	ret->m_tangents.create();
	ret->m_tangents.bind();
	ret->m_tangents.setUsagePattern(QGLBuffer::StaticDraw);
	ret->m_tangents.allocate(tangents, sizeof(GLfloat) * nbVertex * 3);

	// Set up Bitangents VBO
	ret->m_bitangents.create();
	ret->m_bitangents.bind();
	ret->m_bitangents.setUsagePattern(QGLBuffer::StaticDraw);
	ret->m_bitangents.allocate(bitangents, sizeof(GLfloat) * nbVertex * 3);

	// Set up Texture Coordinates VBO
	ret->m_texcoords.create();
	ret->m_texcoords.bind();
	ret->m_texcoords.setUsagePattern(QGLBuffer::StaticDraw);
	ret->m_texcoords.allocate(texcoords, sizeof(GLfloat) * nbVertex * 2);

	ret->m_indices.create();
	ret->m_indices.bind();
	ret->m_indices.setUsagePattern(QGLBuffer::StaticDraw);
	ret->m_indices.allocate(indices, sizeof(GLshort) * ret->m_nbFaces * 3);


	ret->m_indices.release();
	ret->m_texcoords.release();

	delete[] vertices;
	delete[] normals;
	delete[] texcoords;
	delete[] indices;

	ret->m_nbVertices = nbVertex;
	ret->m_boundingVolume = new BoundingSphere(Vector3f(0,0,0),0.5);

	ret->m_state = STATE_LOADED;

	debugGL("While build a sphere primitive");

	return ret;
}