Beispiel #1
0
void rotation_base(float h) {
	setDiffuseColor( 0.85, 0.75, 0.25 );
	setAmbientColor( 0.95, 0.75, 0.25 );
	glPushMatrix();
		glPushMatrix();
			glScalef(4.0, h, 4.0);
			y_box(1.0f); // the rotation base
		glPopMatrix();
		setDiffuseColor( 0.15, 0.15, 0.65 );
		setAmbientColor( 0.15, 0.15, 0.65 );
		glPushMatrix();
			glTranslatef(-0.5, h, -0.6);
			glScalef(2.0, h, 1.6);
			y_box(1.0f); // the console
		glPopMatrix();
		setDiffuseColor( 0.65, 0.65, 0.65 );
		setAmbientColor( 0.65, 0.65, 0.65 );
		glPushMatrix();
			glTranslatef( 0.5, h, 0.6 );
			glRotatef( -90.0, 1.0, 0.0, 0.0 );
			Mat4f mvMatrix = glGetMatrix(GL_MODELVIEW_MATRIX);
			Mat4f matCamInverse = mvMatrix.inverse();
			Vec4f chimEmitPos = matCamInverse * mvMatrix * Vec4f(0.5, 2.5 * h, 0.6, 1.0);
			if (ps != NULL)
			{
				Vec3f chimPos = Vec3f(chimEmitPos[0], chimEmitPos[1], chimEmitPos[2]);
				ps->setEmitterPosition(chimPos, 0);
			}
			drawCylinder( h, 0.05, 0.05 ); // the pipe
		glPopMatrix();
	glPopMatrix();
}
Beispiel #2
0
			void setProjectionMatrix(const Mat4f &projmat)
			{
				this->projmat = projmat;
				Mat4f projmatinv = projmat.inverse();
				// Corners of the frustum in world space
				corners[0] = projmatinv.transformPoint(Vec3f(-1, 1, -1));
				corners[1] = projmatinv.transformPoint(Vec3f(1, 1, -1));
				corners[2] = projmatinv.transformPoint(Vec3f(1, -1, -1));
				corners[3] = projmatinv.transformPoint(Vec3f(-1, -1, -1));
				corners[4] = projmatinv.transformPoint(Vec3f(-1, 1, 1));
				corners[5] = projmatinv.transformPoint(Vec3f(1, 1, 1));
				corners[6] = projmatinv.transformPoint(Vec3f(1, -1, 1));
				corners[7] = projmatinv.transformPoint(Vec3f(-1, -1, 1));
				// Near plane
				planes[0] = Plane(corners[0], corners[1], corners[2]);
				// Left plane
				planes[1] = Plane(corners[0], corners[3], corners[4]);
				// Top plane
				planes[2] = Plane(corners[0], corners[1], corners[4]);
				// Right plane
				planes[3] = Plane(corners[1], corners[2], corners[5]);
				// Bottom plane
				planes[4] = Plane(corners[2], corners[3], corners[6]);
				// Far plane
				planes[5] = Plane(corners[4], corners[5], corners[6]);
				// TODO: Fix normal vectors to point inside!
			}
Beispiel #3
0
void SpawnParticles(Mat4f CameraTransforms)
{

	Mat4f ModelTransforms = CameraTransforms.inverse() * getModelViewMatrix();
	Vec4<float> WorldPoint = ModelTransforms * Vec4f(0, 0, 0, 1);
	AddParticleStartingAt(WorldPoint);
	return;

}
Beispiel #4
0
Vec3f GameTerrain::unproject(Vec3f win_pos, const Mat4f &modelview, const Mat4f &projection, const Rect &viewport)
{
	Mat4f matrix = projection;
	matrix = matrix * modelview;
	matrix.inverse();
	Vec4f v(
		2*(win_pos.x - (float)viewport.left)/(float)viewport.get_width() - 1,
		2*(win_pos.y - (float)(viewport.top))/(float)viewport.get_height() - 1,
		2*win_pos.z - 1,
		1.0f);
	Vec4f result = matrix * v;
	return Vec3f(result.x/result.w, result.y/result.w, result.z/result.w);
}
Beispiel #5
0
void m3dTest::orthonormalInverseTest()
{
	using namespace m3d;
	Vec3f dir(frand(), frand(), frand());
	Vec3f pos(frand(), frand(), frand());
	Mat4f matrix = Mat4f::gramSchmidt(dir, pos);

	Mat4f inverse = matrix.inverse();
	Mat4f orth_inverse = matrix.orthonormalInverse();

	for (int x = 0; x < 4; ++x) {
		for (int y = 0; y < 4; ++y) {
			// check if equal
			CPPUNIT_ASSERT(fabs(inverse[x][y] - orth_inverse[x][y]) < EPSILON);

			// check for NaN
			CPPUNIT_ASSERT(inverse[x][y] == inverse[x][y]);
			CPPUNIT_ASSERT(orth_inverse[x][y] == orth_inverse[x][y]);
		}
	}
}
Beispiel #6
0
// We are going to override (is that the right word?) the draw()
// method of ModelerView to draw out RobotArm
void RobotArm::draw()
{
	/* pick up the slider values */

	float theta = VAL( BASE_ROTATION );
	float phi = VAL( LOWER_TILT );
	float psi = VAL( UPPER_TILT );
	float cr = VAL( CLAW_ROTATION );
	float h1 = VAL( BASE_LENGTH );
	float h2 = VAL( LOWER_LENGTH );
	float h3 = VAL( UPPER_LENGTH );
	float pc = VAL( PARTICLE_COUNT );

    // This call takes care of a lot of the nasty projection 
    // matrix stuff
    ModelerView::draw();

    // Save the camera transform that was applied by
    // ModelerView::draw() above.
    // While we're at it, save an inverted copy of this matrix.  We'll
    // need it later.
    Mat4f matCam = glGetMatrix( GL_MODELVIEW_MATRIX );
    matCamInverse = matCam.inverse();



	static GLfloat lmodel_ambient[] = {0.4,0.4,0.4,1.0};

	// define the model

	ground(-0.2);

	base(0.8);

    glTranslatef( 0.0, 0.8, 0.0 );			// move to the top of the base
    glRotatef( theta, 0.0, 1.0, 0.0 );		// turn the whole assembly around the y-axis. 
	rotation_base(h1);						// draw the rotation base

    glTranslatef( 0.0, h1, 0.0 );			// move to the top of the base
	glPushMatrix();
			glTranslatef( 0.5, h1, 0.6 );	
	glPopMatrix();
    glRotatef( phi, 0.0, 0.0, 1.0 );		// rotate around the z-axis for the lower arm
	glTranslatef( -0.1, 0.0, 0.4 );
	lower_arm(h2);							// draw the lower arm

    glTranslatef( 0.0, h2, 0.0 );			// move to the top of the lower arm
    glRotatef( psi, 0.0, 0.0, 1.0 );		// rotate  around z-axis for the upper arm
	upper_arm(h3);							// draw the upper arm

	glTranslatef( 0.0, h3, 0.0 );
	glRotatef( cr, 0.0, 0.0, 1.0 );

	Mat4f mvMatrix = glGetMatrix(GL_MODELVIEW_MATRIX);
	Vec4f clawEmitPos = matCamInverse * mvMatrix * Vec4f(0.0, 0.0, 0.0, 1.0);
	if (ps != NULL)
	{
		Vec3f clawPos = Vec3f(clawEmitPos[0], clawEmitPos[1], clawEmitPos[2]);
		ps->setEmitterPosition(clawPos, 1);
	}
	claw(1.0);




	//*** DON'T FORGET TO PUT THIS IN YOUR OWN CODE **/
	endDraw();
}
void MyModel::SpawnParticles(Mat4f CameraTransforms)
{
	Mat4f WorldMatrix = CameraTransforms.inverse() * getModelViewMatrix();
	Vec3f WorldPoint = WorldMatrix * Vec4f(0, 0, 0, 1);
	particleSystem.addParticleAt(WorldPoint);
}