Exemplo n.º 1
0
 void publishCamera()
 {
     const auto cameraSettings = _config.getFrameData().getCameraSettings();
     const Matrix4f& modelView = cameraSettings->getModelViewMatrix();
     const FloatVector matrix( modelView.begin(), modelView.end( ));
     _vwsPublisher->publish( ::zeq::hbp::serializeCamera( matrix ));
 }
Exemplo n.º 2
0
void Camera::headMovement(int usernum, double x, double y, double z)
{
	//mm to meters and cast to float

	calculateTranslationVector();
	getModelViewMatrix();

	vec4 originCentric = modelViewMatrix * vec4(x/250.0,y/250.0,z/250.0,1.0);
	if (originCentric.z != 0)
	{
		float ysin = originCentric.x/originCentric.z;
		float xcos = originCentric.y/originCentric.z;
		if (ysin > 1)
			ysin = 1;
		else if (ysin < -1)
			ysin = -1;
		if (xcos > 1)
			xcos = 1;
		else if (xcos < -1)
			xcos = -1;
		yHeadAngle = -atan(ysin);
		xHeadAngle = -atan(xcos);
	}

	moveCamera(xHead-(float)(x/250.0), yHead -(float)(y/250.0), zHead +(float)(z/250.0));
	xHead = (float)(x/250.0);
	yHead = (float)(y/250.0);
	zHead = -(float)(z/250.0);

//	printf("%d - (%6.2f, %6.2f, %6.2f) ==> (%6.2f,%6.2f,%6.2f), yaw=%f, pitch=%f\n", usernum,x,y,z,xHead, yHead, zHead, xHeadAngle, yHeadAngle);
}
Exemplo n.º 3
0
Vec2f Camera::worldToScreen( const Vec3f &worldCoord, float screenWidth, float screenHeight ) const
{
	Vec3f eyeCoord = getModelViewMatrix().transformPointAffine( worldCoord );
	Vec3f ndc = getProjectionMatrix().transformPoint( eyeCoord );
	
	return Vec2f( ( ndc.x + 1.0f ) / 2.0f * screenWidth, ( 1.0f - ( ndc.y + 1.0f ) / 2.0f ) * screenHeight );
}
const bool CCCameraBase::GluProject(CCRenderable *object, CCVector3 &result)
{
	return gluProject( object->positionPtr->x, object->positionPtr->y, object->positionPtr->z,
					   getModelViewMatrix().data(),
					   projectionMatrix.data(),
					   viewport,
					   &result.x, &result.y, &result.z );
}
Exemplo n.º 5
0
Vector3 GameObject::getWorldPosition() {
    if (parent == nullptr) {
        return position;
    }
    
    Vector4 pos = getModelViewMatrix(false) * Vector4(0, 0, 0, 1);
    return Vector3(pos.x, pos.y, pos.z);
}
Exemplo n.º 6
0
void SpawnParticles(Mat4f CameraTransforms)
{

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

}
Exemplo n.º 7
0
Mat3 GraphicsDevice::getCameraOrientation() {
	const Mat4 modl = getModelViewMatrix();
	Mat3 orientation;

	memcpy(orientation._m[0], modl._m[0], sizeof(real_t)*3);
	memcpy(orientation._m[1], modl._m[1], sizeof(real_t)*3);
	memcpy(orientation._m[2], modl._m[2], sizeof(real_t)*3);

	return orientation;
}
Exemplo n.º 8
0
//----------------------------------------
void ofCamera::begin(ofRectangle viewport) {
	if(!isActive) ofPushView();
	isActive = true;

	ofViewport(viewport.x,viewport.y,viewport.width,viewport.height);
	ofSetOrientation(ofGetOrientation(),vFlip);

	ofSetMatrixMode(OF_MATRIX_PROJECTION);
	ofLoadMatrix( getProjectionMatrix(viewport) );

	ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	ofLoadViewMatrix( getModelViewMatrix() );
}
Exemplo n.º 9
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();
	static GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
	Mat4f temp = getModelViewMatrix();

	// define the model

	ground(-0.2);
	
	if (true) {
		Ariou();
	} else {
		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
	    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);
		claw(1.0);
		SpawnParticles(temp);
	}

	//*** DON'T FORGET TO PUT THIS IN YOUR OWN CODE **/
	endDraw();
}
Exemplo n.º 10
0
uint32_t rSimpleMesh::getMatrix( rMat4f **_mat, rObjectBase::MATRIX_TYPES _type ) {
   switch ( _type ) {
      case SCALE: *_mat                 = getScaleMatrix(); return 0;
      case ROTATION: *_mat              = getRotationMatrix(); return 0;
      case TRANSLATION: *_mat           = getTranslationMatrix(); return 0;
      case CAMERA_MATRIX: *_mat         = getViewProjectionMatrix(); return 0;
      case MODEL_MATRIX: *_mat          = getModelMatrix(); return 0;
      case VIEW_MATRIX: *_mat           = getViewMatrix(); return 0;
      case PROJECTION_MATRIX: *_mat     = getProjectionMatrix(); return 0;
      case MODEL_VIEW_MATRIX: *_mat     = getModelViewMatrix(); return 0;
      case MODEL_VIEW_PROJECTION: *_mat = getModelViewProjectionMatrix(); return 0;
      case NORMAL_MATRIX: break;
   }

   return INDEX_OUT_OF_RANGE;
}
Exemplo n.º 11
0
void GameObject::draw() {
    if (scene == nullptr) {
        abortWithMessage("In GameObject::draw(): Scene for GameObject was never set");
    }
    
    mat4 mv = getModelViewMatrix();
    
    scene->middleman->updateModelViewMatrix(mv);
    glBindVertexArray(vao);
    glDrawArrays(GL_TRIANGLES, 0, getNumberOfVertices());
    
    std::vector<GameObject*>::iterator it = children.begin();
    while (it != children.end()) {
        (*it)->draw();
        it++;
    }
}
Exemplo n.º 12
0
	void GLMatrices::submitMatrices(ShaderProgram &program)
	{
		if(!matricesReady)
		{
			modelViewMatrix = getModelViewMatrix();
			Core::Mat44 n = modelViewMatrix.inverse().transpose();
			normalMatrix[0] = {n[0].x, n[0].y, n[0].z};
			normalMatrix[1] = {n[1].x, n[1].y, n[1].z};
			normalMatrix[2] = {n[2].x, n[2].y, n[2].z};
//			normalMatrix = normalMatrix;
			matricesReady = true;

			//base
			program.setUniform("modelMatrix", getModelMatrix());
			program.setUniform("viewMatrix", getViewMatrix());
			program.setUniform("projectionMatrix", getProjectionMatrix());
//			program.setUniform("normalMatrix", normalMatrix);
		}
	}
Exemplo n.º 13
0
void RenderPreview::drawPreview()
{
    if (_renderingInProgress) return; // avoid double-entering this method

    util::ScopedBoolLock lock(_renderingInProgress);

    glViewport(0, 0, _previewWidth, _previewHeight);

    // Set up the render and clear the drawing area in any case
    glDepthMask(GL_TRUE);
    glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Set up the camera
    Matrix4 projection = getProjectionMatrix(0.1f, 10000, PREVIEW_FOV, _previewWidth, _previewHeight);

    // Keep the modelview matrix in the volumetest class up to date
    _volumeTest.setModelView(getModelViewMatrix());
    _volumeTest.setProjection(projection);

    // Pre-Render event
    if (!onPreRender())
    {
        // a return value of false means to cancel rendering
        drawTime();
        return;
    }

    // Front-end render phase, collect OpenGLRenderable objects from the scene
    getScene()->foreachVisibleNodeInVolume(_volumeTest, _sceneWalker);

    RenderStateFlags flags = getRenderFlagsFill();

    // Launch the back end rendering
    _renderSystem->render(flags, _volumeTest.GetModelview(), projection);

    // Give subclasses an opportunity to render their own on-screen stuff
    onPostRender();

    // Draw the render time
    drawTime();
}
Exemplo n.º 14
0
// The SpawnParticles function is responsible for generating new 
// particles in your world.  You will call this function as you 
// you traverse your model's hierarchy.  When you reach a point
// in the hierarchy from where particles should be emitted, 
// call this function!
//
// SpawnParticles takes the camera transformation matrix as a 
// parameter.  More on this later.
void SampleModel::spawnParticles(Mat4<float> cameraTransform) {
	/****************************************************************
	**
	**	THIS FUNCTION WILL ADD A NEW PARTICLE TO OUR WORLD
	**
	**	Suppose we want particles to spawn from a the model's arm.
	**	We need to find the location of the model's arm in world
	**  coordinates so that we can set the initial position of new
	**  particles.	As discussed on the Animator project page,
	**  all particle positions should be in world coordinates.
	**
	**  At this point in execution, the MODELVIEW matrix contains the
	**  camera transforms multiplied by some model transforms.  In other words,
	**
	**  MODELVIEW = CameraTransforms * ModelTransforms
	**
	**	We are interested only in ModelTransforms, which is the
	**  transformation that will convert a point from the current, local
	**  coordinate system to the world coordinate system.
	**
	**	To do this, we're going to "undo" the camera transforms from the
	**  current MODELVIEW matrix.  The camera transform is passed in as
	**  a parameter to this function (remember when we saved it
	**  near the top of the model's draw method?).  We can "undo" the
	**  camera transforms by pre-multiplying the current MODELVIEW matrix
	**  with the inverse of the camera matrix.  In other words,
	**
	**  ModelTransforms = InverseCameraTransforms * MODELVIEW
	**
	********************************************************************/
	
	ParticleSystem *ps = ModelerApplication::Instance()->GetParticleSystem();
	
	//Get the current MODELVIEW matrix.
	//	... "Undo" the camera transforms from the MODELVIEW matrix
	//	... by multiplying Inverse(CameraTransforms) * CurrentModelViewMatrix.
	//	... Store the result of this in a local variable called WorldMatrix.
	//	...
	Mat4f ModelMatrix = getModelViewMatrix();
	Mat4f WorldMatrix = cameraTransform.inverse() * ModelMatrix;
	
	/*****************************************************************
	**
	**	At this point, we have the transformation that will convert a point
	**  in the local coordinate system to a point in the world coordinate
	**  system.
	**
	**  We need to find the actual point in world coordinates
	**  where particle should be spawned.  This is simply
	**  "the origin of the local coordinate system" transformed by
	**  the WorldMatrix.
	**
	******************************************************************/
	Vec4f Loc = WorldMatrix * Vec4f(0.0, 0.0, 0.0, 1.0);
	
	Vec4f VelL = WorldMatrix * Vec4f(0.0, 0.0, -0.5, 1.0);
	Vec4f Vel = VelL - Loc;
	Vec3f velocity(Vel[0], Vel[1], Vel[2]);

	velocity.normalize();

	/*****************************************************************
	**
	**	Now that we have the particle's initial position, we
	**  can finally add it to our system!
	**
	***************************************************************/
	ps->setParticleStart(Vec3f(Loc[0], Loc[1], Loc[2]), velocity);
}
Exemplo n.º 15
0
void Ariou() {
	Mat4f temp = getModelViewMatrix();
	ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_X, 3.1);
	//ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_Y, 2.5);

	ModelerApplication::Instance()->Swing(HEAD_ROTATE, 1);

	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_X, 1.1);
	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_Y, 4.5);

	ModelerApplication::Instance()->Swing(LEFT_LEG_ROTATE_X, 6.1);
	ModelerApplication::Instance()->Swing(RIGHT_LEG_ROTATE_X, 6.1);
	glPushMatrix();
		glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS));
		glScaled(VAL(XSCALE), VAL(YSCALE), VAL(ZSCALE));
		glRotated(VAL(ROTATE), 0, 1, 0);
		setDiffuseColor(COLOR_YELLOW);

		// Torus
		if (VAL(DETAIL_LEVEL) > 1) {
			glPushMatrix();
				glTranslated(.0f, 6, .0f);
				drawTorus(VAL(TORUS_R), VAL(TORUS_r));
			glPopMatrix();
		}
		
		//head
		glPushMatrix();
			glTranslated(0, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) + 0.05 + VAL(HEAD_SIZE), 0);
			glRotated(VAL(HEAD_ROTATE), 0.0, 1.0, 0.0);
			drawSphere(VAL(HEAD_SIZE));
			if (VAL(DETAIL_LEVEL) > 2) {

				// Nose
				drawRoundCylinder(VAL(HEAD_SIZE) * 1.1, 0.2, 0.2);

				// Ear
				glPushMatrix();
				glTranslated(0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(-20, 0, 0, 1);
				SpawnParticles(temp);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();

				glPushMatrix();
				glTranslated(-0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(20, 0, 0, 1);
				SpawnParticles(temp);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();
				
				// Eyes
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated(-0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated( 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
			}
		glPopMatrix();

		if (VAL(DETAIL_LEVEL) > 1) {
			//body
			// a.k.a. torso/trunk
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(0, 0.05 + VAL(LEG_LENGTH), 0);
			glRotated(-90, 1.0, 0.0, 0.0);
			drawRoundCylinder(VAL(HEIGHT), 0.7, 0.6);
			glPushMatrix();
			glTranslated(-0.8, 0, VAL(HEIGHT) - 0.4);
			glRotated(90, 0, 1, 0);
			// the shoulder
			if (VAL(DETAIL_LEVEL) > 2) {
				drawRoundCylinder(1.6, 0.2, 0.2);
			}
			glPopMatrix();

			// the waist
			if (VAL(DETAIL_LEVEL) > 3) {
				glPushMatrix();
				glTranslated(0, 0, 0.5);
				glRotated(90, 1, 0, 0);
				drawTorus(0.7, 0.08);
				glPopMatrix();
			}

			glPopMatrix();

			if (VAL(DETAIL_LEVEL) > 2) {
				//right arm
				glPushMatrix();
				glTranslated(-0.7 - 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(0.15, 0, 0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(-0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				// lower arm
				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPopMatrix();

				//left arm
				glPushMatrix();
				glTranslated(0.7 + 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(-0.15, 0, 0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				if (VAL(DETAIL_LEVEL) > 3) {
					glRotated(90, 0, 0, 1);
					drawCylinder(5, 0.02, 0.02);
					if (VAL(DETAIL_LEVEL) > 4) {
						glTranslated(0, 0, 4);

						glPushMatrix();
						setDiffuseColor(COLOR_GREEN);
						glTranslated(0, -0.5, 1);
						//SpawnParticles(temp);
						glPushMatrix();
						glRotated(90, 1.0, 0.0, 0.0);
						glPopMatrix();
						glPopMatrix();
					}
				}
				glPopMatrix();

				glPopMatrix();
			}

			//right leg
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(-0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(RIGHT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(RIGHT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();

			//left leg
			glPushMatrix();
			glTranslated(0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(LEFT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(LEFT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();
		}
	glPopMatrix();
}
Exemplo n.º 16
0
//----------------------------------------
ofMatrix4x4 ofCamera::getModelViewProjectionMatrix(ofRectangle viewport) const {
	return getModelViewMatrix() * getProjectionMatrix(viewport);
}
Exemplo n.º 17
0
Vector Camera::unproject(const Vector& point) const
{
	Vector result = MathHelper::Unproject(point, getModelViewMatrix(), getProjectionMatrix(), Viewport(0, 0, getWidth(), getHeight()));
	return result;
}
Exemplo n.º 18
0
void CCCameraBase::ExtractFrustum()
{
	float   *proj = projectionMatrix.data();
	float   *modv = getModelViewMatrix().data();
	float   clip[16];
	float   t;
	
	/* Get the current MODELVIEW matrix from OpenGL */
	//glGetFloatv( GL_MODELVIEW_MATRIX, modv );
	
	/* Combine the two matrices (multiply projection by modelview) */
	clip[ 0] = modv[ 0] * proj[ 0] + modv[ 1] * proj[ 4] + modv[ 2] * proj[ 8] + modv[ 3] * proj[12];
	clip[ 1] = modv[ 0] * proj[ 1] + modv[ 1] * proj[ 5] + modv[ 2] * proj[ 9] + modv[ 3] * proj[13];
	clip[ 2] = modv[ 0] * proj[ 2] + modv[ 1] * proj[ 6] + modv[ 2] * proj[10] + modv[ 3] * proj[14];
	clip[ 3] = modv[ 0] * proj[ 3] + modv[ 1] * proj[ 7] + modv[ 2] * proj[11] + modv[ 3] * proj[15];
	
	clip[ 4] = modv[ 4] * proj[ 0] + modv[ 5] * proj[ 4] + modv[ 6] * proj[ 8] + modv[ 7] * proj[12];
	clip[ 5] = modv[ 4] * proj[ 1] + modv[ 5] * proj[ 5] + modv[ 6] * proj[ 9] + modv[ 7] * proj[13];
	clip[ 6] = modv[ 4] * proj[ 2] + modv[ 5] * proj[ 6] + modv[ 6] * proj[10] + modv[ 7] * proj[14];
	clip[ 7] = modv[ 4] * proj[ 3] + modv[ 5] * proj[ 7] + modv[ 6] * proj[11] + modv[ 7] * proj[15];
	
	clip[ 8] = modv[ 8] * proj[ 0] + modv[ 9] * proj[ 4] + modv[10] * proj[ 8] + modv[11] * proj[12];
	clip[ 9] = modv[ 8] * proj[ 1] + modv[ 9] * proj[ 5] + modv[10] * proj[ 9] + modv[11] * proj[13];
	clip[10] = modv[ 8] * proj[ 2] + modv[ 9] * proj[ 6] + modv[10] * proj[10] + modv[11] * proj[14];
	clip[11] = modv[ 8] * proj[ 3] + modv[ 9] * proj[ 7] + modv[10] * proj[11] + modv[11] * proj[15];
	
	clip[12] = modv[12] * proj[ 0] + modv[13] * proj[ 4] + modv[14] * proj[ 8] + modv[15] * proj[12];
	clip[13] = modv[12] * proj[ 1] + modv[13] * proj[ 5] + modv[14] * proj[ 9] + modv[15] * proj[13];
	clip[14] = modv[12] * proj[ 2] + modv[13] * proj[ 6] + modv[14] * proj[10] + modv[15] * proj[14];
	clip[15] = modv[12] * proj[ 3] + modv[13] * proj[ 7] + modv[14] * proj[11] + modv[15] * proj[15];
	
	/* Extract the numbers for the RIGHT plane */
	frustum[frustum_right][0] = clip[ 3] - clip[ 0];
	frustum[frustum_right][1] = clip[ 7] - clip[ 4];
	frustum[frustum_right][2] = clip[11] - clip[ 8];
	frustum[frustum_right][3] = clip[15] - clip[12];
	
	/* Normalize the result */
	t = sqrtf( frustum[frustum_right][0] * frustum[frustum_right][0] + frustum[frustum_right][1] * frustum[frustum_right][1] + frustum[frustum_right][2] * frustum[frustum_right][2] );
	frustum[frustum_right][0] /= t;
	frustum[frustum_right][1] /= t;
	frustum[frustum_right][2] /= t;
	frustum[frustum_right][3] /= t;
	
	/* Extract the numbers for the LEFT plane */
	frustum[frustum_left][0] = clip[ 3] + clip[ 0];
	frustum[frustum_left][1] = clip[ 7] + clip[ 4];
	frustum[frustum_left][2] = clip[11] + clip[ 8];
	frustum[frustum_left][3] = clip[15] + clip[12];
	
	/* Normalize the result */
	t = sqrtf( frustum[frustum_left][0] * frustum[frustum_left][0] + frustum[frustum_left][1] * frustum[frustum_left][1] + frustum[frustum_left][2] * frustum[frustum_left][2] );
	frustum[frustum_left][0] /= t;
	frustum[frustum_left][1] /= t;
	frustum[frustum_left][2] /= t;
	frustum[frustum_left][3] /= t;
	
	/* Extract the BOTTOM plane */
	frustum[frustum_bottom][0] = clip[ 3] + clip[ 1];
	frustum[frustum_bottom][1] = clip[ 7] + clip[ 5];
	frustum[frustum_bottom][2] = clip[11] + clip[ 9];
	frustum[frustum_bottom][3] = clip[15] + clip[13];
	
	/* Normalize the result */
	t = sqrtf( frustum[frustum_bottom][0] * frustum[frustum_bottom][0] + frustum[frustum_bottom][1] * frustum[frustum_bottom][1] + frustum[frustum_bottom][2] * frustum[frustum_bottom][2] );
	frustum[frustum_bottom][0] /= t;
	frustum[frustum_bottom][1] /= t;
	frustum[frustum_bottom][2] /= t;
	frustum[frustum_bottom][3] /= t;
	
	/* Extract the TOP plane */
	frustum[frustum_top][0] = clip[ 3] - clip[ 1];
	frustum[frustum_top][1] = clip[ 7] - clip[ 5];
	frustum[frustum_top][2] = clip[11] - clip[ 9];
	frustum[frustum_top][3] = clip[15] - clip[13];
	
	/* Normalize the result */
	t = sqrtf( frustum[frustum_top][0] * frustum[frustum_top][0] + frustum[frustum_top][1] * frustum[frustum_top][1] + frustum[frustum_top][2] * frustum[frustum_top][2] );
	frustum[frustum_top][0] /= t;
	frustum[frustum_top][1] /= t;
	frustum[frustum_top][2] /= t;
	frustum[frustum_top][3] /= t;
	
	/* Extract the FAR plane */
	frustum[frustum_far][0] = clip[ 3] - clip[ 2];
	frustum[frustum_far][1] = clip[ 7] - clip[ 6];
	frustum[frustum_far][2] = clip[11] - clip[10];
	frustum[frustum_far][3] = clip[15] - clip[14];
	
	/* Normalize the result */
	t = sqrtf( frustum[frustum_far][0] * frustum[frustum_far][0] + frustum[frustum_far][1] * frustum[frustum_far][1] + frustum[frustum_far][2] * frustum[frustum_far][2] );
	frustum[frustum_far][0] /= t;
	frustum[frustum_far][1] /= t;
	frustum[frustum_far][2] /= t;
	frustum[frustum_far][3] /= t;
	
	/* Extract the NEAR plane */
	frustum[frustum_near][0] = clip[ 3] + clip[ 2];
	frustum[frustum_near][1] = clip[ 7] + clip[ 6];
	frustum[frustum_near][2] = clip[11] + clip[10];
	frustum[frustum_near][3] = clip[15] + clip[14];
	
	/* Normalize the result */
	t = sqrtf( frustum[frustum_near][0] * frustum[frustum_near][0] + frustum[frustum_near][1] * frustum[frustum_near][1] + frustum[frustum_near][2] * frustum[frustum_near][2] );
	frustum[frustum_near][0] /= t;
	frustum[frustum_near][1] /= t;
	frustum[frustum_near][2] /= t;
	frustum[frustum_near][3] /= t;
}
Exemplo n.º 19
0
bool CCCameraBase::GluUnProject(const float x, const float y, const float z, CCVector3 &result)
{
    return gluUnProject( x, y, z, getModelViewMatrix().data(), projectionMatrix.data(), viewport, &result.x, &result.y, &result.z );
}
Exemplo n.º 20
0
void Camera::getBillboardVectors( Vec3f *right, Vec3f *up ) const
{
	right->set( getModelViewMatrix().m[0], getModelViewMatrix().m[4], getModelViewMatrix().m[8] );
	up->set( getModelViewMatrix().m[1], getModelViewMatrix().m[5], getModelViewMatrix().m[9] );
}
Exemplo n.º 21
0
// We are going to override (is that the right word?) the draw()
// method of ModelerView to draw out SampleModel
void SampleModel::draw()
{
	// This call takes care of a lot of the nasty projection 
	// matrix stuff.  Unless you want to fudge directly with the 
	// projection matrix, don't bother with this ...
	ModelerView::draw();

	/*************************************************
	**
	**	NOW SAVE THE CURRENT MODELVIEW MATRIX
	**
	**	At this point in execution, the MODELVIEW matrix contains
	**  ONLY the camera transformation.  We need to save this camera
	**  transformation so that we can use it later (for reasons
	**  explained below).
	**
	*****************************************************/
	cameraMatrix = getModelViewMatrix();

	// draw the sample model
	setAmbientColor(.1f, .1f, .1f);

	//glPushMatrix();

	//glPopMatrix();

	glPushMatrix(); // push identity
	glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS)); // values set by the sliders

	if (VAL(NINJATURTLE))
		setDiffuseColor(COLOR_GREEN);
	else
		setDiffuseColor(.940f, .816f, .811f);

	if (animate)
		glRotated(animHeadAngle, 0.0, 1.0, 0.0);
	if (VAL(EYEBANDANA))
		drawEyeBandana();

	if (!VAL(NINJATURTLE))
		setDiffuseColor(.940f, .816f, .811f);
	drawHead();
	
	if (!VAL(NINJATURTLE)) {
		setDiffuseColor(0, 0, 0);
		drawFace();
		setDiffuseColor(.940f, .816f, .811f);
		drawNeck();
	}

	drawUpperTorso();
	drawLowerTorso();

	if (!VAL(NINJATURTLE))
		setDiffuseColor(.940f, .816f, .811f);
	drawRightHandJoint();
	glPushMatrix();
	if (animate)
		glRotated(animUpperArmAngle, 1.0, 0, 0);
	drawUpperRightHand();
	drawLowerRightHand();
	drawRightHand();
	glPopMatrix();


	drawLeftHandJoint();
	glPushMatrix();
	if (animate)
		glRotated(-animUpperArmAngle, 1.0, 0, 0);
	drawUpperLeftHand();
	drawLowerLeftHand();
	drawLeftHand();
	glPopMatrix();

	drawRightLegJoint();
	drawLeftLegJoint();

	drawUpperRightLeg();
	drawLowerRightLeg();
	drawRightFoot();

	drawUpperLeftLeg();
	drawLowerLeftLeg();
	drawLeftFoot();

	if (VAL(NINJATURTLE))
		drawShell();
	else
		drawTail(); // handle the positioning and hierachical modeling of the tail

	if (VAL(METABALLSKIN)) {
		MetaBalls mb;
		mb.setUpGrid();
		mb.setUpMetaballs();
		mb.evalScalarField();
		mb.draw();
	}

	glPopMatrix();

	/***********************************************
	**
	**	NOW WE WILL ACTUALLY BEGIN DRAWING THE MODEL
	**
	**	Draw your model up to the node where you would like
	**	particles to spawn from.
	**
	**  FYI:  As you call glRotate, glScale, or glTranslate,
	**  OpenGL is multiplying new transformations into the
	**  MODELVIEW matrix.
	**
	********************************************/
	// If particle system exists, draw it
	ParticleSystem *ps = ModelerApplication::Instance()->GetParticleSystem();
	if (ps != NULL) {
		ps->computeForcesAndUpdateParticles(t);
		ps->drawParticles(t, m_camera);
	}
	
	/*************************************************
	**
	**	NOW DO ANY CLOSING CODE
	**
	**	Don't forget that animator requires you to call
	**  endDraw().
	**	
	**************************************************/
	endDraw();
}