Beispiel #1
0
void Torch::draw2Self()
{
	if( world()->landscape()->drawingReflection() || world()->landscape()->drawingRefraction() )
		return;

	const unsigned char samplingPoints = 16;
	unsigned char visiblePoints;

	glPushMatrix();
	glTranslate( mFlarePosition );
	glScale( 0.3f );
	visiblePoints = mOcclusionTest.randomPointsOnUnitSphereVisible( samplingPoints );
	glPopMatrix();
	if( !visiblePoints )
		return;

	glPushAttrib( GL_VIEWPORT_BIT | GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT );
	glDepthMask( GL_FALSE );
	glDisable( GL_CULL_FACE );
	glDisable( GL_DEPTH_TEST );

	glDisable( GL_LIGHTING );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE );
	mMaterial->bind();
	glColor( ((float)visiblePoints/(float)samplingPoints)*mColor );

	sQuadVertexBuffer.bind();
	glClientActiveTexture( GL_TEXTURE0 );
	glEnableClientState( GL_VERTEX_ARRAY );
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );

	glVertexPointer( 3, GL_FLOAT, 5*sizeof(GLfloat), (void*)0 );
	glTexCoordPointer( 2, GL_FLOAT, 5*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)) );

	QMatrix4x4 flareCenter = modelViewMatrix();
	flareCenter.translate( mFlarePosition );
	Bilboard::begin( flareCenter );
	glScale( mFlareSize );
	glRotate( mFlareRotation, QVector3D(0,0,1) );
	glDrawArrays( GL_QUADS, 0, 4 );
	glRotate( -mFlareRotation*2.7f, QVector3D(0,0,1) );
	glDrawArrays( GL_QUADS, 0, 4 );
	Bilboard::end();

	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
	glDisableClientState( GL_VERTEX_ARRAY );
	sQuadVertexBuffer.release();

	mMaterial->release();
	glDisable( GL_BLEND );

	glPopAttrib();
}
Beispiel #2
0
void VruiDemo::display(GLContextData& contextData) const
	{
	/*********************************************************************
	This method is called once for every eye in every window on every
	frame. It must not change application or Vrui state, as it is called
	an unspecified number of times, and might be called from parallel
	background threads. It also must not clear the screen or initialize
	the OpenGL transformation matrices. When this method is called, Vrui
	will already have rendered its own state (menus etc.) and have set up
	the transformation matrices so that all rendering in this method
	happens in navigation (i.e., model) coordinates.
	*********************************************************************/
	
	/* Get the OpenGL-dependent application data from the GLContextData object: */
	DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this);
	
	/* Save OpenGL state: */
	glPushAttrib(GL_ENABLE_BIT);
	
	/* Insert generic OpenGL code here... */
	// ...
	
	/* Enable texturing and use the texture uploaded in the initDisplay() method: */
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectId);
	
	/* Render some textured objects here... */
	// ...
	
	/* Disable texture mapping and protect the texture object (important!): */
	glBindTexture(GL_TEXTURE_2D,0);
	glDisable(GL_TEXTURE_2D);
	
	/* Set up the animation transformation: */
	glPushMatrix();
	
	/* Rotate around X, then Y, then Z: */
	glRotate(modelAngles[0],Vrui::Vector(1,0,0));
	glRotate(modelAngles[1],Vrui::Vector(0,1,0));
	glRotate(modelAngles[2],Vrui::Vector(0,0,1));
	
	/* Call the display list created in the initDisplay() method: */
	glCallList(dataItem->displayListId);
	
	/* Go back to navigation coordinates: */
	glPopMatrix();
	
	/* Restore OpenGL state: */
	glPopAttrib();
	}
void BiovisionDisplay::draw(const KinematicModel<BiovisionJoint> &model, const Vector3D &colour, bool drawAxis)
{
    for(int i = 0; i < model.njoints(); i++)
    {
        const BiovisionJoint &joint = model.joints(i);

        if(drawAxis)
        {
            glPushMatrix();
                glTranslate(joint.global_position());
                glRotate(joint.global_orientation());

                glBegin(GL_LINES);
                    glColor3f(1.0, 0.0, 0.0);
                    glVertex3f(0.0, 0.0, 0.0);
                    glVertex3f(20.0, 0., 0.0);

                    glColor3f(0.0, 1.0, 0.0);
                    glVertex3f(0.0, 0.0, 0.0);
                    glVertex3f(0.0, 20.0, 0.0);

                    glColor3f(0.0, 0.0, 1.0);
                    glVertex3f(0.0, 0.0, 0.0);
                    glVertex3f(0.0, 0.0, 20.0);
                glEnd();
            glPopMatrix();
        }

        if(joint.parent() >= 0)
        {
            glBegin(GL_LINES);
                glVertex(joint.global_position());
                glVertex(model.getParent(joint).global_position());
            glEnd();

            Vector3D global_direction = (joint.global_position()-model.getParent(joint).global_position()).direction();
            double length = joint.local_position().length();

            glColor(colour);
            glPushMatrix();
                glTranslate(joint.global_position());
                glTranslate(-global_direction*length*0.5);

                //align bone
                Vector3D zAxis = Vector3D(0.0, 0.0, 1.0);
                Vector3D newAxis = zAxis ^ global_direction;
                double newAngle = acos(zAxis *global_direction);
                glRotateRad(newAngle, newAxis);

                //draw bone
                GLUquadricObj *qobj = gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_FILL);
                gluQuadricNormals(qobj, GLU_SMOOTH);
                glScalef(0.25, 0.25, 1.0);
                gluSphere(qobj, length*0.5, 20, 20);
                gluDeleteQuadric(qobj);
            glPopMatrix();
        }
    }
}
Beispiel #4
0
void GlyphRenderer::renderGlyph(const Glyph& glyph,const OGTransform& transformation,const GlyphRenderer::DataItem* contextDataItem) const
	{
	/* Check if the glyph is enabled: */
	if(glyph.enabled)
		{
		if(glyph.glyphType==Glyph::CURSOR)
			{
			/****************************
			Render a texture-based glyph:
			****************************/
			
			/* Align the glyph texture with the current window's current screen: */
			const DisplayState& ds=getDisplayState(contextDataItem->contextData);
			glPushMatrix();
			glTranslate(transformation.getTranslation());
			glRotate(ds.screen->getScreenTransformation().getRotation());
			
			/* Draw the glyph texture: */
			glCallList(contextDataItem->glyphDisplayLists+glyph.glyphType);
			
			glPopMatrix();
			}
		else
			{
			/* Render a 3D glyph: */
			glPushMatrix();
			glMultMatrix(transformation);
			glMaterial(GLMaterialEnums::FRONT,glyph.glyphMaterial);
			glCallList(contextDataItem->glyphDisplayLists+glyph.glyphType);
			glPopMatrix();
			}
		}
	}
METHODPREFIX
void
glMultMatrix(
	const Geometry::RotationTransformation<ScalarParam,3>& t)
	{
	glRotate(Math::deg(t.getRotation().getAngle()),t.getRotation().getAxis().getComponents());
	}
void glLoadMatrix(const Geometry::OrthogonalTransformation<ScalarParam,3>& t)
{
    glLoadIdentity();
    glTranslate(t.getTranslation());
    glRotate(t.getRotation());
    glScale(t.getScaling(),t.getScaling(),t.getScaling());
}
Beispiel #7
0
void DefaultIcon::display ( GLContextData& contextData ) const
{
	glMaterial ( GLMaterialEnums::FRONT_AND_BACK, GLMaterial ( Vrui::getUiBgColor ( ) ) ) ;
	glPushMatrix ( ) ;
	glTranslate ( 0.0f, 0.0f, 0.0f ) ;
	glRotate ( Vrui::Scalar ( 50.0 ), Vrui::Vector ( -1.0, -1.0, 1.0 ) ) ;
	glDrawCone ( 0.75, 1.5, 10 ) ;
	glPopMatrix ( ) ;
}
METHODPREFIX
void
glMultMatrix(
	const Geometry::OrthogonalTransformation<ScalarParam,3>& t)
	{
	glTranslate(t.getTranslation().getComponents());
	glRotate(Math::deg(t.getRotation().getAngle()),t.getRotation().getAxis().getComponents());
	glScale(t.getScaling());
	}
METHODPREFIX
void
glLoadMatrix(
	const Geometry::OrthonormalTransformation<ScalarParam,3>& t)
	{
	glLoadIdentity();
	glTranslate(t.getTranslation().getComponents());
	glRotate(Math::deg(t.getRotation().getAngle()),t.getRotation().getAxis().getComponents());
	}
void FiberApplication::drawArrow(const Vrui::Point& to, Vrui::Scalar radius) const
{
        Vrui::Scalar tipHeight=radius*Vrui::Scalar(6.0);
        Vrui::Scalar shaftLength=Geometry::dist(Vrui::Point::origin,to)-tipHeight;

        glPushMatrix();
        glTranslate(Vrui::Point::origin-Vrui::Point::origin);
        glRotate(Vrui::Rotation::rotateFromTo(Vrui::Vector(0,0,1),to-Vrui::Point::origin));
        glTranslate(Vrui::Vector(0,0,Math::div2(shaftLength)));
        glDrawCylinder(radius,shaftLength,24);
        glTranslate(Vrui::Vector(0,0,Math::div2(shaftLength)+tipHeight*Vrui::Scalar(0.25)));
        glDrawCone(radius*Vrui::Scalar(2),tipHeight,24);
        glPopMatrix();
}
Beispiel #11
0
void Triangle::glRenderAction(GLContextData& contextData) const
	{
	/* Retrieve data item from GL context: */
	TriangleRenderer::DataItem* dataItem=contextData.retrieveDataItem<TriangleRenderer::DataItem>(unitRenderer);
	
	/* Move model coordinate system to triangle's position and orientation: */
	glPushMatrix();
	glTranslate(position.getComponents());
	glRotate(orientation);
	
	/* Render triangle: */
	glCallList(dataItem->displayListId);
	
	/* Reset model coordinates: */
	glPopMatrix();
	}
void SplatterSystem::draw( const QMatrix4x4 & modelView )
{
	mParticleMaterial->bind();
	mParticleSystem->draw( modelView );
	mParticleMaterial->release();

	mSplatterMaterial->bind();
	glEnable( GL_BLEND );
	glBlendFunc( GL_DST_COLOR, GL_ZERO );
	glMatrixMode( GL_TEXTURE );
	for( int i = 0; i < mSplatters.size(); ++i )
	{
		if( mSplatters[i].fade <= 0.0f )
			continue;

		QVector4D c = Interpolation::linear( QVector4D(1.0f,1.0f,1.0f,1.0f), mSplatterMaterial->constData()->emission(), sqrtf(mSplatters[i].fade) );
		mSplatterMaterial->overrideEmission( c );

		glPushMatrix();
		QRectF mapRect = mTerrain->toMapF( mSplatters[i].rect );

		// rotate around center of texture in 90 deg. steps
		glTranslate( 0.5f, 0.5f, 0.0f );
		glRotate( mSplatters[i].rotation*90.0f, 0.0f, 0.0f, 1.0f );
		glTranslate( -0.5f, -0.5f, 0.0f );

		// transform texture coordinates to terrain patch
		float sizeFactor = powf( mSplatters[i].fade, mSplatterDriftFactor );
		QSizeF border = ( sizeFactor * mapRect.size() ) / 2.0f;
		glScale( 1.0/(mapRect.size().width()*(1.0f-sizeFactor)), 1.0/(mapRect.size().height()*(1.0f-sizeFactor)), 1.0 );
		glTranslate( -mapRect.x()-border.width(), -mapRect.y()-border.height(), 0.0 );

		float fX( mapRect.x()-(int)mapRect.x() );
		float fY( mapRect.y()-(int)mapRect.y() );
		QRect drawRect
		(
			floorf(mapRect.x()), floorf(mapRect.y()),
			ceilf(mapRect.width()+fX), ceilf(mapRect.height()+fY)
		);
		mTerrain->drawPatchMap( drawRect );
		glPopMatrix();
	}
	glMatrixMode( GL_MODELVIEW);
	glDisable( GL_BLEND );
	mSplatterMaterial->release();
}
Beispiel #13
0
 virtual void transform( Type _progress )
 {
   glRotate(_progress,x_,y_,z_);
 }
Beispiel #14
0
void
PlanetographicGrid::render(Renderer* renderer,
                           const Point3f& pos,
                           float discSizeInPixels,
                           double tdb) const
{
    Quatd q = Quatd::yrotation(PI) * body.getEclipticToBodyFixed(tdb);
    Quatf qf((float) q.w, (float) q.x, (float) q.y, (float) q.z);

    // The grid can't be rendered exactly on the planet sphere, or
    // there will be z-fighting problems. Render it at a height above the
    // planet that will place it about one pixel away from the planet.
    float scale = (discSizeInPixels + 1) / discSizeInPixels;
    scale = max(scale, 1.001f);
    float offset = scale - 1.0f;

    Vec3f semiAxes = body.getSemiAxes();

    Vec3d posd(pos.x, pos.y, pos.z);
    Vec3d viewRayOrigin = Vec3d(-pos.x, -pos.y, -pos.z)  * (~q).toMatrix3();
    
    // Calculate the view normal; this is used for placement of the long/lat
    // label text.
    Vec3f vn  = Vec3f(0.0f, 0.0f, -1.0f) * renderer->getCameraOrientation().toMatrix3();
    Vec3d viewNormal(vn.x, vn.y, vn.z);

    // Enable depth buffering
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDisable(GL_BLEND);

    glDisable(GL_TEXTURE_2D);

    glPushMatrix();
    glRotate(~qf);
    glScale(scale * semiAxes);

    glEnableClientState(GL_VERTEX_ARRAY);

    glVertexPointer(3, GL_FLOAT, 0, xzCircle);

    // Only show the coordinate labels if the body is sufficiently large on screen
    bool showCoordinateLabels = false;
    if (discSizeInPixels > 50)
        showCoordinateLabels = true;

    float latitudeStep = minLatitudeStep;
    float longitudeStep = minLongitudeStep;
    if (discSizeInPixels < 200)
    {
        latitudeStep = 30.0f;
        longitudeStep = 30.0f;
    }
    
    for (float latitude = -90.0f + latitudeStep; latitude < 90.0f; latitude += latitudeStep)
    {
        float phi = degToRad(latitude);
        float r = (float) cos(phi);

        if (latitude == 0.0f)
        {
            glColor(Renderer::PlanetEquatorColor);
            glLineWidth(2.0f);
        }
        else
        {
            glColor(Renderer::PlanetographicGridColor);
        }
        glPushMatrix();
        glTranslatef(0.0f, (float) sin(phi), 0.0f);
        glScalef(r, r, r);
        glDrawArrays(GL_LINE_LOOP, 0, circleSubdivisions);
        glPopMatrix();
        glLineWidth(1.0f);
        
        if (showCoordinateLabels)
        {
            if (latitude != 0.0f && abs(latitude) < 90.0f)
            {
                char buf[64];

                char ns;
                if (latitude < 0.0f)
                    ns = northDirection == NorthNormal ? 'S' : 'N';
                else
                    ns = northDirection == NorthNormal ? 'N' : 'S';
                sprintf(buf, "%d%c", (int) fabs((double) latitude), ns);
                longLatLabel(buf, 0.0, latitude, viewRayOrigin, viewNormal, posd, q, semiAxes, offset, renderer);
                longLatLabel(buf, 180.0, latitude, viewRayOrigin, viewNormal, posd, q, semiAxes, offset, renderer);
            }
        }
    }

    glVertexPointer(3, GL_FLOAT, 0, xyCircle);

    for (float longitude = 0.0f; longitude <= 180.0f; longitude += longitudeStep)
    {
        glColor(Renderer::PlanetographicGridColor);
        glPushMatrix();
        glRotatef(longitude, 0.0f, 1.0f, 0.0f);
        glDrawArrays(GL_LINE_LOOP, 0, circleSubdivisions);
        glPopMatrix();

        if (showCoordinateLabels)
        {
            int showLongitude = 0;
            char ew = 'E';

            switch (longitudeConvention)
            {
            case EastWest:
                ew = 'E';
                showLongitude = (int) longitude;
                break;
            case Eastward:
                if (longitude > 0.0f)
                    showLongitude = 360 - (int) longitude;
                ew = 'E';
                break;
            case Westward:
                if (longitude > 0.0f)
                    showLongitude = 360 - (int) longitude;
                ew = 'W';
                break;
            }

            char buf[64];
            sprintf(buf, "%d%c", (int) showLongitude, ew);
            longLatLabel(buf, longitude, 0.0, viewRayOrigin, viewNormal, posd, q, semiAxes, offset, renderer);
            if (longitude > 0.0f && longitude < 180.0f)
            {
                showLongitude = (int) longitude;
                switch (longitudeConvention)
                {
                case EastWest:
                    ew = 'W';
                    showLongitude = (int) longitude;
                    break;
                case Eastward:
                    showLongitude = (int) longitude;
                    ew = 'E';
                    break;
                case Westward:
                    showLongitude = (int) longitude;
                    ew = 'W';
                    break;
                }

                sprintf(buf, "%d%c", showLongitude, ew);       
                longLatLabel(buf, -longitude, 0.0, viewRayOrigin, viewNormal, posd, q, semiAxes, offset, renderer);
            }
        }
    }

    glDisableClientState(GL_VERTEX_ARRAY);

    glPopMatrix();

    glDisable(GL_LIGHTING);

    glDisable(GL_DEPTH_TEST);
    glDepthMask(GL_FALSE);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
void HelicopterNavigationTool::display(GLContextData& contextData) const
{
    if(isActive())
    {
        /* Get the data item: */
        DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this);

        glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT);
        glDisable(GL_LIGHTING);
        glLineWidth(1.0f);
        glColor3f(0.0f,1.0f,0.0f);

        float y=float(getFrontplaneDist())*1.25f;

        glPushMatrix();
        glMultMatrix(pre);
        glRotate(valuators[4]*Math::deg(factory->viewAngleFactors[0]),Vector(0,0,1));
        glRotate(valuators[5]*Math::deg(factory->viewAngleFactors[1]),Vector(1,0,0));

        glBegin(GL_LINES);
        glVertex3f(-y*0.02f,y,   0.00f);
        glVertex3f(-y*0.01f,y,   0.00f);
        glVertex3f( y*0.01f,y,   0.00f);
        glVertex3f( y*0.02f,y,   0.00f);
        glVertex3f(   0.00f,y,-y*0.02f);
        glVertex3f(   0.00f,y,-y*0.01f);
        glVertex3f(   0.00f,y, y*0.01f);
        glVertex3f(   0.00f,y, y*0.02f);
        glEnd();

        /* Draw the flight path marker: */
        Vector vel=currentOrientation.transform(currentVelocity);
        if(vel[1]>Scalar(0))
        {
            vel*=y/vel[1];
            Scalar maxVel=Misc::max(Math::abs(vel[0]),Math::abs(vel[2]));
            if(maxVel>=Scalar(y*0.5f))
            {
                vel[0]*=Scalar(y*0.5f)/maxVel;
                vel[2]*=Scalar(y*0.5f)/maxVel;
                glColor3f(1.0f,0.0f,0.0f);
            }
            else
                glColor3f(0.0f,1.0f,0.0f);

            glBegin(GL_LINE_LOOP);
            glVertex3f(vel[0]-y*0.005f,vel[1],vel[2]+  0.000f);
            glVertex3f(vel[0]+  0.000f,vel[1],vel[2]-y*0.005f);
            glVertex3f(vel[0]+y*0.005f,vel[1],vel[2]+  0.000f);
            glVertex3f(vel[0]+  0.000f,vel[1],vel[2]+y*0.005f);
            glEnd();
        }

        /* Draw the artificial horizon ribbon: */
        glRotate(currentOrientation);
        Vector yAxis=currentOrientation.inverseTransform(Vector(0,1,0));
        Scalar yAngle=Math::deg(Math::atan2(yAxis[0],yAxis[1]));
        glRotate(-yAngle,Vector(0,0,1));
        glCallList(dataItem->displayListBase+10);

        glPopMatrix();
        glPopAttrib();
    }
}
Beispiel #16
0
LRESULT CLX3DViewer::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CPoint point;
	point.x = (short)LOWORD(lParam);
	point.y = (short)HIWORD(lParam);

	if (m_dragging == 1)
	{
		m_slider.OnMouseMove(point);
		UpdateWindow();

		double position = m_slider.GetPos();

		CComQIPtr<ILMediaSeeking> seeking = m_filterGraph;
		seeking->Seek(position);
	}

#if 0
	if (m_dragging)
	{
		CPoint offset = point - m_startpoint;

		if (m_dragging == 1)	// change XY position
		{
			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			double moveY = (double)-offset.y/20;
			double moveX = (double)offset.x/20;

			gmMatrix4 repos = gmMatrix4::identity();

			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
			repos *= gmMatrix4::translate(moveX, moveY, 0);
			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

			position->m_value = repos.transform(m_initialPosition);

			FireViewChange();
		}
		else if (m_dragging == 2) // change XZ position
		{
			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			double moveX = (double)offset.x/20;
			double moveZ = (double)offset.y/20;

			gmMatrix4 repos = gmMatrix4::identity();

			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
			repos *= gmMatrix4::translate(moveX, 0, moveZ);
			repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

			position->m_value = repos.transform(m_initialPosition);

			FireViewChange();
		}
		else if (m_dragging == 3)
		{
			double r = 600;	// 360

			double rotateY = (double)offset.x*360/r;
			double rotateX = (double)offset.y*360/r;

			CLViewpoint* pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);

			CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
			CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);

			// Orientation
			if (rotateY != 0 || rotateX != 0)
			{
				/*
				float x = m_initialOrientation.m_v[0];
				float y = m_initialOrientation.m_v[1];
				float z = m_initialOrientation.m_v[2];
				float angle = m_initialOrientation.m_a;
				*/

				Quat4d q = m_initialOrientation.AxisAngleToQuaternion(/*x, y, z, angle*/);

				q.CombineQuaternion(/*x, y, z, angle,*/ 0, gmRadians(rotateY), gmRadians(rotateX));

				orientation->m_value = q.QuaternionToAxisAngle();//Quat4d(x, y, z, angle));

				/*
				orientation->m_value.m_v[0] = x;
				orientation->m_value.m_v[1] = y;
				orientation->m_value.m_v[2] = z;
				orientation->m_value.m_a = angle;
				*/

				orientation->m_value.m_v.normalize();
			}

			// Position
			{
				// Rotate position around centerOfRotation
				gmMatrix4 repos = gmMatrix4::identity();

				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
				repos *= gmMatrix4::rotate(rotateY, gmVector3(0,1,0));
				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

				position->m_value = repos.transform(m_initialPosition);
			}

			// Position
			{
				// Rotate position around centerOfRotation
				gmMatrix4 repos = gmMatrix4::identity();

				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v);
				repos *= gmMatrix4::rotate(rotateX, gmVector3(1,0,0));
				repos *= gmMatrix4::rotate(rotateY, gmVector3(0,1,0));
				repos *= gmMatrix4::rotate(gmDegrees(orientation->m_value.m_a), -orientation->m_value.m_v).inverse();

				position->m_value = repos.transform(m_initialPosition);
			}

			FireViewChange();
		}
	}
	else
	{
		CRect client;
		GetClientRect(&client);
		int w = client.right;
		int h = client.bottom;
	//	wglMakeCurrent(hdc, m_hrc);

		double winx = point.x;
		double winy = client.bottom-point.y-1;

		GLint viewport[4] = { 0, 0, w, h };

		GLuint selectBuf[512];

		glSelectBuffer(512, selectBuf);
		glRenderMode(GL_SELECT);
		glInitNames();
		glPushName(0);

		{
			CLViewpoint* pViewpoint = NULL;

			if (m_viewpointStack.GetSize() > 0)
			{
				pViewpoint = static_cast<CLViewpoint*>(m_viewpointStack[0]);
			}
			else
			{
				// hmm...
			}

			//	glViewport(m_viewR[view].left, m_viewR[view].top, w, h);

			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluPickMatrix(winx, winy, 3, 3, viewport);
	//		glLoadMatrixd(projm);
		//
			double fov;
			if (pViewpoint)
			{
				CLSFFloat* fieldOfView = static_cast<CLSFFloat*>(pViewpoint->m_fieldOfView);
				fov = fieldOfView->m_value;
			}
			else
			{
				fov = M_PI/4;
			}

			gluPerspective(gmDegrees(fov), (GLfloat)w / (GLfloat)h, 1.0, 10000.0);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			//glLoadMatrixf((float*)modelm);

			CX3DDrawContext xdc;

#if 0
			// NavigationInfo
			{
				BOOL headlight;

				if (m_navigationinfoStack.GetSize() > 0)
				{
					CLNavigationInfo* pNavigationInfo = static_cast<CLNavigationInfo*>(m_navigationinfoStack[0]);

					headlight = static_cast<CLSFBool*>(pNavigationInfo->m_headlight)->m_v;
				}
				else
				{
					// Default values
					headlight = TRUE;
				}

				glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

				if (TRUE)//TRUE/*bAnyLights*/)
				{
				}

				if (headlight)
				{
					GLfloat light_direction[4] = { 0, 0, 1, 0};	// directional
					GLfloat color[4] = {1, 1, 1, 1};
					GLfloat ambient[4] = {0, 0, 0, 1};

					glEnable(GL_LIGHT0+xdc.m_nLight);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_POSITION, light_direction);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_AMBIENT, ambient);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_DIFFUSE, color);
					glLightfv(GL_LIGHT0+xdc.m_nLight, GL_SPECULAR , color);

					xdc.m_nLight++;
				}
			}
#endif

			if (pViewpoint)
			{
				CLSFRotation* orientation = static_cast<CLSFRotation*>(pViewpoint->m_orientation);
				CLSFVec3f* position = static_cast<CLSFVec3f*>(pViewpoint->m_position);
				gmVector3t<float> norientation = orientation->m_value.m_v;
				norientation.normalize();

				glRotate(gmDegrees(orientation->m_value.m_a), -norientation);
				glTranslate(-position->m_value);
			}
			else
			{
				// TODO
				glTranslatef(0, 0, -180);
			}

			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

			if (m_scene)
			{
				CComQIPtr<CLRenderImplImpl> render = static_cast<CLSAIScene*>(m_scene)->m_root;
				if (render)
				{
					render->Draw(&xdc);
				}
			}

			glFlush();
		}

		GLint hits = glRenderMode(GL_RENDER);

		if (hits > 0)
		{
			MessageBeep(-1);
			GLuint* ptr = selectBuf;

			GLuint names = *ptr++;
			float z1 = *ptr++ / 0x7fffffff;
			float z2 = *ptr++ / 0x7fffffff;

			double winz = z2;

			double modelMatrix[16];
			double projMatrix[16];

			glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
			glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);

			double objx, objy, objz;
			gluUnProject(winx, winy, winz, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

			for (int n = 0; n < names; n++)
			{
			}
		}
	}
#endif

	return 0;
}
Beispiel #17
0
void IMUTest::display(GLContextData& contextData) const
	{
	glPushAttrib(GL_ENABLE_BIT);
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
	glMaterialSpecular(GLMaterialEnums::FRONT,GLColor<GLfloat,4>(1.0f,1.0f,1.0f));
	glMaterialShininess(GLMaterialEnums::FRONT,25.0f);
	
	/* Draw a global coordinate frame: */
	glPushMatrix();
	glColor3f(1.0f,0.5f,0.5f);
	glRotated(90.0,0.0,1.0,0.0);
	glTranslated(0.0,0.0,5.0);
	glDrawArrow(0.5f,1.0f,1.5f,10.0f,16);
	glPopMatrix();
	
	glPushMatrix();
	glColor3f(0.5f,1.0f,0.5f);
	glRotated(-90.0,1.0,0.0,0.0);
	glTranslated(0.0,0.0,5.0);
	glDrawArrow(0.5f,1.0f,1.5f,10.0f,16);
	glPopMatrix();
	
	glPushMatrix();
	glColor3f(0.5f,0.5f,1.0f);
	glTranslated(0.0,0.0,5.0);
	glDrawArrow(0.5f,1.0f,1.5f,10.0f,16);
	glPopMatrix();
	
	/* Draw a local coordinate frame: */
	glPushMatrix();
	const IMUTracker::State& state=tracker->getLockedState();
	// if(lockPosition)
	// 	glTranslated(5.0,5.0,5.0);
	// else
	// 	glTranslate(state.translation*IMUTracker::Scalar(10));
	glRotate(state.rotation);
	
	glPushMatrix();
	glColor3f(1.0f,0.5f,0.5f);
	glRotated(90.0,0.0,1.0,0.0);
	glTranslated(0.0,0.0,2.5);
	glDrawArrow(0.5f,1.0f,1.5f,5.0f,16);
	glPopMatrix();
	
	glPushMatrix();
	glColor3f(0.5f,1.0f,0.5f);
	glRotated(-90.0,1.0,0.0,0.0);
	glTranslated(0.0,0.0,2.5);
	glDrawArrow(0.5f,1.0f,1.5f,5.0f,16);
	glPopMatrix();
	
	glPushMatrix();
	glColor3f(0.5f,0.5f,1.0f);
	glTranslated(0.0,0.0,2.5);
	glDrawArrow(0.5f,1.0f,1.5f,5.0f,16);
	glPopMatrix();
	
	const IMU::CalibratedSample& sample=samples.getLockedValue();
	
	/* Draw the current linear acceleration vector: */
	glPushMatrix();
	glColor3f(1.0f,1.0f,0.0f);
	GLfloat len=GLfloat(Geometry::mag(sample.accelerometer));
	glRotate(IMUTracker::Rotation::rotateFromTo(IMUTracker::Vector(0,0,1),sample.accelerometer));
	glTranslatef(0.0f,0.0f,len*0.5f);
	glDrawArrow(0.5f,1.0f,1.5f,len,16);
	glPopMatrix();
	
	/* Draw the current magnetic flux density vector: */
	glPushMatrix();
	glColor3f(1.0f,0.0f,1.0f);
	len=GLfloat(Geometry::mag(sample.magnetometer))*0.2f;
	glRotate(IMUTracker::Rotation::rotateFromTo(IMUTracker::Vector(0,0,1),sample.magnetometer));
	// glTranslatef(0.0f,0.0f,len*0.5f);
	glDrawArrow(0.5f,1.0f,1.5f,len*2.0f,16);
	glPopMatrix();
	
	glPopMatrix();
	
	glPopAttrib();
	}
inline void glRotate( const GLdouble & angle, const QVector3D & axis )	{ glRotate( angle, static_cast<GLdouble>(axis.x()), static_cast<GLdouble>(axis.y()), static_cast<GLdouble>(axis.z()) ); }
static void
GlesCube11_DrawCube2(Evas_Object *obj)
{
	ELEMENTARY_GLVIEW_USE(obj);
	appdata_s *ad = (appdata_s *)evas_object_data_get(obj, APPDATA_KEY);

	static const GlUnit VERTICES[] =
	{
		ONEN, ONEN, ONEP, ONEP, ONEN, ONEP, ONEN, ONEP, ONEP, ONEP, ONEP, ONEP,
		ONEN, ONEN, ONEN, ONEN, ONEP, ONEN, ONEP, ONEN, ONEN, ONEP, ONEP, ONEN,
		ONEN, ONEN, ONEP, ONEN, ONEP, ONEP, ONEN, ONEN, ONEN, ONEN, ONEP, ONEN,
		ONEP, ONEN, ONEN, ONEP, ONEP, ONEN, ONEP, ONEN, ONEP, ONEP, ONEP, ONEP,
		ONEN, ONEP, ONEP, ONEP, ONEP, ONEP, ONEN, ONEP, ONEN, ONEP, ONEP, ONEN,
		ONEN, ONEN, ONEP, ONEN, ONEN, ONEN, ONEP, ONEN, ONEP, ONEP, ONEN, ONEN
	};

	static const GlUnit TEXTURE_COORD[] =
	{
		ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP,
		ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP,
		ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP,
		ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP,
		ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP,
		ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP
	};

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_TFIXED, 0, VERTICES);

	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer(2, GL_TFIXED, 0, TEXTURE_COORD);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, ad->tex_ids[ad->current_tex_index]);

	glMatrixMode(GL_MODELVIEW);
	{
		const  float Z_POS_INC = 0.01f;
		static float zPos      = -5.0f;
		static float zPosInc   = Z_POS_INC;

		zPos += zPosInc;

		if (zPos < -8.0f)
		{
			zPosInc = Z_POS_INC;
			ad->current_tex_index = 1 - ad->current_tex_index;
		}

		if (zPos > -5.0f)
		{
			zPosInc = -Z_POS_INC;
		}

		glLoadIdentity();
		glTranslate(0, GetGlUnit(1.2f), GetGlUnit(zPos));

		{
			static int angle = 0;
			angle = (angle + 1) % (360 * 3);
			glRotate(GetGlUnit(angle) / 3, 0, 0, GetGlUnit(1.0f));
			glRotate(GetGlUnit(angle), 0, GetGlUnit(1.0f), 0);
		}
	}

	for(int i = 0; i < 6; i++)
	{
		glDrawArrays(GL_TRIANGLE_STRIP, 4 * i, 4);
	}

	glDisable(GL_TEXTURE_2D);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
void glMultMatrix(const Geometry::Rotation<ScalarParam,3>& r)
{
    glRotate(Math::deg(r.getAngle()),r.getAxis());
}
void glMultMatrix(const Geometry::OrthonormalTransformation<ScalarParam,3>& t)
{
    glTranslate(t.getTranslation());
    glRotate(t.getRotation());
}
static void
GlesCube11_DrawCube1(Evas_Object *obj)
{
	ELEMENTARY_GLVIEW_USE(obj);
	appdata_s *ad = (appdata_s *)evas_object_data_get(obj, APPDATA_KEY);

	static const GlUnit VERTICES[] =
	{
		ONEN, ONEP, ONEN, // 0
		ONEP, ONEP, ONEN, // 1
		ONEN, ONEN, ONEN, // 2
		ONEP, ONEN, ONEN, // 3
		ONEN, ONEP, ONEP, // 4
		ONEP, ONEP, ONEP, // 5
		ONEN, ONEN, ONEP, // 6
		ONEP, ONEN, ONEP  // 7
	};

	static const GlUnit VERTEX_COLOR[] =
	{
		ONEP, ZERO, ONEP, ONEP,
		ONEP, ONEP, ZERO, ONEP,
		ZERO, ONEP, ONEP, ONEP,
		ONEP, ZERO, ZERO, ONEP,
		ZERO, ZERO, ONEP, ONEP,
		ZERO, ONEP, ZERO, ONEP,
		ONEP, ONEP, ONEP, ONEP,
		ZERO, ZERO, ZERO, ONEP
	};

	static const unsigned short INDEX_BUFFER[] =
	{
		0, 1, 2, 2, 1, 3,
		1, 5, 3, 3, 5, 7,
		5, 4, 7, 7, 4, 6,
		4, 0, 6, 6, 0, 2,
		4, 5, 0, 0, 5, 1,
		2, 3, 6, 6, 3, 7
	};

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_TFIXED, 0, VERTICES);

	glEnableClientState(GL_COLOR_ARRAY);
	glColorPointer(4, GL_TFIXED, 0, VERTEX_COLOR);

	glMatrixMode(GL_MODELVIEW);
	{
		glLoadIdentity();
		glTranslate(0, GetGlUnit(-0.7f), GetGlUnit(-5.0f));

		{
			static int angle = 0;
			angle = (angle + 1) % (360 * 3);
			glRotate(GetGlUnit(angle) / 3, GetGlUnit(1.0f), 0, 0);
			glRotate(GetGlUnit(angle), 0, 0, GetGlUnit(1.0f));
		}
	}

	glDrawElements(GL_TRIANGLES, 6 * (3 * 2), GL_UNSIGNED_SHORT, &INDEX_BUFFER[0]);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
}
void glLoadMatrix(const Geometry::Rotation<ScalarParam,3>& r)
{
    glLoadIdentity();
    glRotate(Math::deg(r.getAngle()),r.getAxis());
}