Esempio n. 1
0
void display ()  // dipanggil dari init -> untuk selanjutnya dipanggil dari gl_library 
{
	mint::Time start, stop;	

//	iso = sin(frame*0.01f );
	
	// Do simulation!
	if ( !bPause ) psys.Run (); // running simulasi

	frame++;
	measureFPS ();

	glEnable ( GL_DEPTH_TEST );

	// Render depth map shadows
	start.SetSystemTime ( ACC_NSEC );
	disableShadows ();
	#ifdef USE_SHADOWS
		if ( iShade==1 ) {
			renderDepthMap_FrameBuffer ( 0, window_width, window_height );
		} else {
			renderDepthMap_Clear ( window_width, window_height );		
		}
	#endif	

	// Clear frame buffer
	if ( iShade<=1 ) 	glClearColor( 0.29, 0.29, 0.29, 1.0 );
	else				glClearColor ( 0, 0, 0, 0 );
	glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glDisable ( GL_CULL_FACE );
	glShadeModel ( GL_SMOOTH );

	// Compute camera view
	computeFromPositions ();
	computeProjection ();
	computeView ();		

	// Draw Shadows (if on)
	#ifdef USE_SHADOWS	
		if ( iShade==1 )	renderShadows ( view_matrix );			
	#endif

	// Draw 3D	
	start.SetSystemTime ( ACC_NSEC );
	glEnable ( GL_LIGHTING );  
	glLoadMatrixf ( view_matrix );	
	drawScene ( view_matrix, true );
	if ( bTiming) { stop.SetSystemTime ( ACC_NSEC ); stop = stop - start; printf ( "SCENE: %s\n", stop.GetReadableTime().c_str() ); }

	// Draw 2D overlay
	draw2D ();
 
	// Swap buffers
	glutSwapBuffers();  
	glutPostRedisplay();
}
Esempio n. 2
0
void ViewingCore::getZNearZFarProj(double &zNear, double &zFar, osg::Matrixd &projMat)
{
    projMat = computeProjection();

    if( getOrtho() ) {
        double l, r, b, t;
        projMat.getOrtho( l, r, b, t, zNear, zFar );
    } else {
        double fovy, aspect;
        projMat.getPerspective( fovy, aspect, zNear, zFar );
    }
}
Esempio n. 3
0
/// class MatchReplayScene
MatchReplayScene::MatchReplayScene(MatchRecording *const &recording, QObject *const &parent) :
	QGraphicsScene(parent),
	recording(recording),
	controller(recording),
	projection(computeProjection(1000, 700)) {

	initPitch();
	initScoreboard();
	initBall();
	initPlayers();

	connect(&controller, SIGNAL(frameChanged(MatchSnapshot *const &)),
			this, SLOT(changeFrame(MatchSnapshot *const &)));
}
Esempio n. 4
0
osg::Vec3d ViewingCore::findDeltaOnPanPlane(double ndcX1, double ndcY1, double ndcX2, double ndcY2)
{
    // Get the view volume far plane value, and the distance from
    // the near to far plane.
    double zNear, zFar;
    osg::Matrixd p = computeProjection();
    if( getOrtho() ) {
        double l, r, b, t;
        p.getOrtho( l, r, b, t, zNear, zFar );
    } else {
        double fovy, aspect;
        p.getPerspective( fovy, aspect, zNear, zFar );
    }
    const double distance = zFar - zNear;

    // Create two points, both in NDC space, and lying on the far plane at the back
    // of the view volume. One is the xy origin, the other with the passed xy parameters.
    osg::Vec4d farPoint0 = osg::Vec4d( ndcX1, ndcY1, 1., 1. );
    osg::Vec4d farPoint1 = osg::Vec4d( ndcX2, ndcY2, 1., 1. );
    if( !getOrtho() ) {
        // Not ortho, so w != 1.0. Multiply by the far plane distance.
        // This yields values in clip coordinates.
        farPoint0 *= zFar;
        farPoint1 *= zFar;
    }

    // Get inverse view & proj matrices to back-transform the
    // two clip coord far points into world space.
    osg::Matrixd v = getMatrix();
    p.invert( p );
    osg::Vec4d wc0 = farPoint0 * p * v;
    osg::Vec4d wc1 = farPoint1 * p * v;

    // Intersect the two world coord points with the pan plane.
    osg::Vec3d result0, result1;
    osg::Vec3d p1( wc0.x(), wc0.y(), wc0.z() );
    osg::Vec3d p0 = getOrtho() ? p1 - ( _viewDir * distance ) : getEyePosition();
    intersectPlaneRay( result0, _panPlane, p0, p1 );
    p1 = osg::Vec3d( wc1.x(), wc1.y(), wc1.z() );
    p0 = getOrtho() ? p1 - ( _viewDir * distance ) : getEyePosition();
    intersectPlaneRay( result1, _panPlane, p0, p1 );

    // Subtract the two plane intersection points to get the delta world coord
    // motion return
    return result1 - result0;
}
Esempio n. 5
0
osg::Vec3d ViewingCore::getFarPoint(const double ndcX, const double ndcY)
{
    osg::Matrixd p = computeProjection();

    osg::Vec4d ccFarPoint( ndcX, ndcY, 1., 1. );
    if( !getOrtho() ) {
        // Not ortho, so w != 1.0. Multiply by the far plane distance.
        // This yields a value in clip coords.
        double fovy, aspect, zNear, zFar;
        p.getPerspective( fovy, aspect, zNear, zFar );
        ccFarPoint *= zFar;
    }

    // Get inverse view & proj matrices to back-transform the clip coord point.
    osg::Matrixd v = getMatrix();
    p.invert( p );

    osg::Vec4d wc = ccFarPoint * p * v;
    osg::Vec3d farPoint( wc.x(), wc.y(), wc.z() );
    return farPoint;
}
void ThirdPersonManipulator::render(RenderDevice* rd) {
    rd->pushState();
    // Highlight the appropriate axis

    // X, Y, Z, XY, YZ, ZX, RX, RY, RZ
    Color3 color[] = 
        {Color3(0.9f, 0, 0), 
         Color3(0, 0.9f, 0.1f), 
         Color3(0.0f, 0.4f, 1.0f), 
         
         Color3(0.6f, 0.7f, 0.7f), 
         Color3(0.6f, 0.7f, 0.7f), 
         Color3(0.6f, 0.7f, 0.7f),
    
         Color3(0.9f, 0, 0), 
         Color3(0, 0.9f, 0.1f), 
         Color3(0.0f, 0.4f, 1.0f)}; 
         
    static const Color3 highlight[] = 
       {Color3(1.0f, 0.5f, 0.5f), 
        Color3(0.6f, 1.0f, 0.7f), 
        Color3(0.5f, 0.7f, 1.0f), 
        
        Color3::white(), 
        Color3::white(), 
        Color3::white(),
    
        Color3(1.0f, 0.5f, 0.5f), 
        Color3(0.6f, 1.0f, 0.7f), 
        Color3(0.5f, 0.7f, 1.0f)};

    static const Color3 usingColor = Color3::yellow();

    // Highlight whatever we're over
    if (m_overAxis != NO_AXIS) {
        color[m_overAxis] = highlight[m_overAxis];
    }

    // Show the selected axes
    for (int a = 0; a < NUM_GEOMS; ++a) {
        if (m_usingAxis[a]) {
            color[a] = usingColor;
        }
    }

    // The Draw::axes command automatically doubles whatever scale we give it
    Draw::axes(m_controlFrame, rd, 
               color[0], color[1], color[2], m_axisScale * 0.5f);

    rd->setBlendFunc(RenderDevice::BLEND_SRC_ALPHA, 
                     RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA);
    rd->setShadeMode(RenderDevice::SHADE_SMOOTH);
    rd->setObjectToWorldMatrix(m_controlFrame);

    if (m_translationEnabled) {
        for (int g = FIRST_TRANSLATION; g <= LAST_TRANSLATION; ++g) {
            rd->setColor(color[g]);
            m_geomArray[g].render(rd);
        }
    }

    if (m_rotationEnabled) {
        for (int g = FIRST_ROTATION; g <= LAST_ROTATION; ++g) {
            rd->setColor(color[g]);
            m_geomArray[g].render(rd, 0.8f);
        }
    }

    computeProjection(rd);
    rd->popState();
}