コード例 #1
0
ファイル: turtle.cpp プロジェクト: SimranVasir/GlutGame
void Turtle::update(Salmon &salmon) {

    if (!isAlive_ || collided_) {
        return;
    }
    
    // Move the turtle with the current.
    move(current, 0);
    
    // Get window width.
    double viewport[4];
    glGetDoublev(GL_VIEWPORT, viewport);
    double window_w = viewport[2];
    double window_h = viewport[3];
    
    // Passof the screen (the left wall) and die.
    if (x_ < 0) {
        isAlive_ = false;
    }
    
	//
    // Impact with salmon (naive).
	//
    int salmon_x_ = salmon.getXcoordinate();
    int salmon_y_ = salmon.getYcoordinate();
    
    double distance = sqrt( pow((x_ - salmon_x_), 2) + pow((y_ - salmon_y_), 2) );
    if (distance <= 2.0 * radius_) {
        collided_ = true;
        setupLight();
        salmon.setCollided(true);
        salmon.setRandomColour();
    }
}
コード例 #2
0
ファイル: 040080244.cpp プロジェクト: uguzd/040080244_projeI
int main (int argc, char ** argv)
{
    GLenum type;

    glutInit(&argc, argv);
    glutInitWindowSize(800,600);
    type = GLUT_RGB;
    type |= GLUT_DOUBLE;
    type |= GLUT_DEPTH;
    type |= GLUT_MULTISAMPLE;
    glutInitDisplayMode(type);
    glutCreateWindow("Simple Solar System");

    glClearColor(0.0, 0, 1, 1.0);

    glEnable(GL_DEPTH_TEST);


    glMatrixMode(GL_PROJECTION);
    gluPerspective(55, 800/600, 0.1, 100);

    glMatrixMode(GL_MODELVIEW);

    setupLight();

    timerCallback(0);
    //setupLight();
    glutDisplayFunc(Draw);
    glutMainLoop();

    return 0;
}
コード例 #3
0
void EnSpotLight::initialize()
{
    // call the get method of light manager so it can register itself for getting camera callbacks (see constructor)
    LightManager::get()->initialize();

    // create a new light
    _lightSource = new osg::LightSource;

    _lightSource->setLight( setupLight().get() );
    _lightSource->setLocalStateSetModes( osg::StateAttribute::ON );
    // we do culling ourselves
    _lightSource->setCullingActive( false );

    // set cull callback. it manages the enabling / disabling of lights depending on camera's 
    //  frustum and light radius.
    osg::ref_ptr< LightCallback > cullcallback = new LightCallback( this );
    _lightSource->setCullCallback( cullcallback.get() );
       
    // set mesh if one defined
    if ( _meshFile.length() )
    {
        osg::ref_ptr< osg::Node > mesh = yaf3d::LevelManager::get()->loadMesh( _meshFile );
        if ( !mesh.valid() ) 
            log_warning << " cannot find mesh file" << _meshFile << std::endl;
        else
            addToTransformationNode( mesh.get() );
    }

    // register entity in order to get menu notifications
    yaf3d::EntityManager::get()->registerNotification( this, true );    
}
コード例 #4
0
ファイル: GLRenderer.cpp プロジェクト: FabrizioPerria/OpenGL
GLRenderer::GLRenderer(void)
{
	GLenum res = glewInit();
	if (res != GLEW_OK) {
		fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
		return;
	}

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);				// set the clear Display state to the black color; the windows will use this setting during the whole execution

	program = std::unique_ptr<GLProgram>(new GLProgram());
	program->run();
	program->transformObjIndex = glGetUniformLocation(program->getID(),"gObjectTransform");
	program->transformCamIndex = glGetUniformLocation(program->getID(),"gCamera");
	program->lightColorIndex = glGetUniformLocation(program->getID(), "light.lightColor");
	program->ambientIntensityIndex = glGetUniformLocation(program->getID(), "light.intensityAmbient");
	program->diffuseIntensityIndex = glGetUniformLocation(program->getID(), "light.intensityDiffuse");
	program->directionIndex = glGetUniformLocation(program->getID(), "light.direction");
	program->eyeIndex = glGetUniformLocation(program->getID(), "eyeWorldSpace");
	program->specularIntensityIndex = glGetUniformLocation(program->getID(), "specularIntensity");
	program->specularPowerIndex = glGetUniformLocation(program->getID(), "specularPower");

	_root = std::unique_ptr<Node>(new Node);

	/* Setup the scene */

	RawSceneLoader loader;
	Scene scene;
	loader.load(scene);

	setupMesh(scene.meshes[0],1);
	setupTexture(scene.textures[0],1);
	setupLight(scene.lights[0], 1);
	setupMaterial(scene.materials[0],1);
}
コード例 #5
0
//==========================================================================
void MyGlWindow::draw()
//==========================================================================
{

  glViewport(0,0,w(),h());

    // clear the window, be sure to clear the Z-Buffer too
  glClearColor(0.2f,0.2f,.2f,0);		// background should be blue


  glClearStencil(0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  glEnable(GL_DEPTH);
  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
  
  // now draw the ground plane
  setProjection();
  setupFloor();

  glPushMatrix();
  drawFloor(50,32);
  glPopMatrix();

  // now to draw the shadows



  setupLight();


  // Add a sphere to the scene.
  glBegin(GL_LINES);
  glColor3f(1,0,0);
  glVertex3f(0,0,0);
  glVertex3f(0,100,0);
  glColor3f(0,1,0);
  glVertex3f(0,0,0);
  glVertex3f(100,0,0);
  glColor3f(0,0,1);
  glVertex3f(0,0,0);
  glVertex3f(0,0,100);
  glEnd();
  

  setupShadows();
  drawStuff();
  unsetupShadows();

  // Enable blending
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  drawStuff();


}
コード例 #6
0
void EnSpotLight::handleNotification( const yaf3d::EntityNotification& notification )
{
    // handle notifications
    switch( notification.getId() )
    {
        case YAF3D_NOTIFY_MENU_ENTER:
        {
            if ( _enable )
            {
                if ( _usedInMenu )
                    addToTransformationNode( _lightSource.get() );
                else
                    removeFromTransformationNode( _lightSource.get() );
            }
        }
        break;

        case YAF3D_NOTIFY_MENU_LEAVE:
        {
            if ( _enable )
            {
                if ( _usedInMenu )
                    removeFromTransformationNode( _lightSource.get() );
                else
                    addToTransformationNode( _lightSource.get() );
            }
        }
        break;

        // update the light settings when attributes are changed (e.g. by a level editor)
        case YAF3D_NOTIFY_ENTITY_ATTRIBUTE_CHANGED:
        {
            removeFromTransformationNode( _lightSource.get() );
            if ( _enable )
            {
                _lightSource->setLight( setupLight().get() );
                addToTransformationNode( _lightSource.get() );
            }
        }
        break;

        // if used in menu then this entity is persisten, so we have to trigger its deletion on shutdown
        case YAF3D_NOTIFY_SHUTDOWN:
        {
            if ( _usedInMenu )
                yaf3d::EntityManager::get()->deleteEntity( this );
        }
        break;

        default:
            ;
    }
}
コード例 #7
0
ファイル: renderer.cpp プロジェクト: mathewbyrne/station
//
// Main drawing function. Renders a completed scene to the screen.
//
void Renderer::drawScene(Scene& scene, Camera& camera)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | 
      GL_STENCIL_BUFFER_BIT);

  // Load the viewing translations.
  resize(global.winWidth, global.winHeight);
  glLoadMatrix(camera.getWorldToCamMatrix());

  // Unlit scene + Depth Buffer info.
  ambientPass(scene, camera);

  // Only enter this loop if ambient only is not enabled.
  if (!global.drawAmbientOnly)
  {
    // The rest of the rendering is done on a 'per-light' basis, shadows are
    // determined for each light and the scene is additively illuminated.
  	for (int i = 0; i < scene.lights.size(); ++i)
  	{
  	  if (i >= global.maxVisibleLights) break;

  	  Light& light = scene.lights[i];
  	  
      // Setup the light for drawing and draw it.
      setupLight(light);
      if (global.drawPointLights)
        drawLight(light);

      // Determine shadows and light the scene.
      if (global.drawShadows)
      {
        determineShadows(scene.casters, light, camera);
      }
      
      // Iluminate the scene fro this light.
      illuminationPass(scene, camera);

	glClear(GL_STENCIL_BUFFER_BIT);
  	}
  	
    scene.dirtyAllCasters();
	}

	// Check for OpenGL errors.
	int er = glGetError();
	if (er) printf("%s\n", gluErrorString(er));
}
コード例 #8
0
ファイル: gfx8.cpp プロジェクト: IanFinlayson/ancient
/* main */
int main( int argc, char** argv )
{
	glutInit( &argc, argv );
	createWindow( 800, 800, "Penguin!" );
	setupLight( );
	
	/* register our call backs */
	glutDisplayFunc( &display ); 
	glutReshapeFunc( &reshape ); 
	glutIdleFunc( &animate );
	glutKeyboardFunc( &keyHandler );

	/* run the program */
	glutMainLoop( );

	return 0;
}
コード例 #9
0
ファイル: ofApp.cpp プロジェクト: elaye/of-deferred-rendering
void ofApp::setup(){
	setupLight();
	setupMaterial();

	// scene.addLight(light);
	scene.setLight(light);
	scene.setMaterial(material);

	extSphere.setup();

	cam.orbit(0, -10, 300);
	ofVec3f p = cam.getPosition();
	cam.setPosition(p.x, p.y + 20.0, p.z);
	// cam.setupPerspective(true, 60, 1, 2000);

	gui.setup(scene.parameters);
}
コード例 #10
0
Exercise20::Exercise20(QWidget  * parent)
    :   AbstractGLExercise(parent)
    ,   m_drawable(NULL)
    ,   m_he(NULL)
    ,   m_shadingMode(Phong_Shading)
    ,   m_materialMode(Gold)
{
    m_view = QMatrix4x4();
    m_view.lookAt(
        QVector3D( 0.f, 1.f,  4.f)
        ,   QVector3D( 0.f, 0.f,  0.f)
        ,   QVector3D( 0.f, 1.f,  0.f));

    m_prog_toon = new QGLShaderProgram;
    m_prog_phong = new QGLShaderProgram;

    setupLight();
    setupMaterials();
}
コード例 #11
0
ファイル: gwb_gui.cpp プロジェクト: jmlien/cs795-pa1
bool InitGL()
{
    // *Antialias*
    glEnable( GL_LINE_SMOOTH );
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glHint( GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST );

    glShadeModel(GL_SMOOTH);

    // others
    glEnable( GL_DEPTH_TEST);
    glClearColor( 1,1,1,1.0 );


    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    //let's have light
    setupLight();

    return true;
}
コード例 #12
0
int main (int argc, char ** argv)
{


    GLenum type;
    
	glutInit(&argc, argv);

	glutInitWindowSize(1600,1200);
	type = GLUT_RGB;
	type |= GLUT_DOUBLE;
	type |= GLUT_DEPTH;
    type |= GLUT_MULTISAMPLE;
	glutInitDisplayMode(type);
	glutCreateWindow("Ders 2");
   
    glClearColor(0.0, 0, 0.0, 0);
    glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
    texture[0] = LoadGLTexture("sun_sphere.jpg");
    texture[1] = LoadGLTexture("earth_sphere.jpg");
    texture[2] = LoadGLTexture("moon_sphere.jpg");
    texture[3] = LoadGLTexture("mercury_sphere.bmp");
    
    glMatrixMode(GL_PROJECTION);
    gluPerspective(55, 1600/1200, 0.1, 100);
    
    glMatrixMode(GL_MODELVIEW);
    
    timerCallback(0);
	
    glutDisplayFunc(Draw);
	setupLight();
    glutMainLoop();
    return 0;
}
コード例 #13
0
ファイル: main.cpp プロジェクト: chipsenkbeil-academic/cs4204
/*
 * Written by Robert "Chip" Senkbeil
 * Uses -lglut, -lGLU, and -lGL to compile on Linux.
 */
int main(int argc, char** argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowPosition(0, 0);
  glutInitWindowSize(640, 640);
  glutCreateWindow(argv[0]);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);

  //glutReshapeFunc(/* ... */);
  glutSpecialFunc(arrowPress);
  glutKeyboardFunc(keyPress);
  glutMouseFunc(mouseEvent);
  glutMotionFunc(mouseMoveEvent);
  glutDisplayFunc(render);
  glutIdleFunc(idleEvent);

  // Build and attach the menu
  buildPopupMenu();
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  // Allocate memory for a new robot
  printf("Allocating new robot...\n");
  robot = new Robot();

  // Add robot initial keyframe to animation clip
  {
    Keyframe k_;
    k_.getKeyframeFromRobot(robot);
    aClip.addKeyframeAtCurrent(k_);
  }

  printf("Setting up the camera...\n");
  camera.setCameraMaxDistance(4.0f);
  //camera.lock();

  // Set default fps
  framesPerSecond = DEFAULT_FRAMES_PER_SECOND;
  isPlaying = 0;
  playingForward = 1;
  playingBackward = 0;
  currentTime = 0;
  baseTime = 0;
  frames = 0;
  framesTotal = 0;

  // Set termination callback
  atexit(terminate_prog);

  // Enable lighting
  setupLight();

  // Setup a global material
  initMaterial();

  // Enable texture
  glEnable(GL_TEXTURE_2D);
  robot->loadTexture("texture/CorrugatedSharp.png");

  // Start the main loop
  glutMainLoop();

  // Exit program
  return 0;
}
コード例 #14
0
void redraw(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    /* Only need this if you care to look at the stencil buffer */
    if(dataChoice == STENCIL)
	glClear(GL_STENCIL_BUFFER_BIT);

    glPushMatrix();
    glScalef(.5, .5, .5);

    if(stage == 1)
       goto doneWithFrame;

    setupLight();

    setupNormalDrawingState();
    glPushMatrix();
    glTranslatef(0, 1, 4);
    glRotatef(135, 0, 1, 0);
    drawAirplane();
    glPopMatrix();

    if(stage == 2)
       goto doneWithFrame;

    setupBasePolygonState(3);	/* 2 decals */
    drawGround();

    if(stage == 3)
       goto doneWithFrame;

    setupDecalState(1);		/* decal # 1 = the runway asphalt */
    drawAsphalt();

    if(stage == 4)
       goto doneWithFrame;

    setupDecalState(2);		/* decal # 2 = yellow paint on the runway */
    drawStripes();

    if(stage == 5)
       goto doneWithFrame;

    setupDecalState(3);		/* decal # 3 = the plane's shadow */
    glDisable(GL_LIGHTING);
    glEnable(GL_BLEND);
    glPushMatrix();
    glColor4f(0, 0, 0, .5);
    glTranslatef(0, 0, 4);
    glRotatef(135, 0, 1, 0);
    glScalef(1, 0, 1);
    drawAirplane();
    glPopMatrix();
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

doneWithFrame:

    setupNormalDrawingState();

    glPopMatrix();

    switch(dataChoice) {
        case COLOR:
	    break; /* color already in back buffer */

	case STENCIL:
	    copyStencilToColor(GL_BACK);
	    break;

	case DEPTH:
	    copyDepthToColor(GL_BACK);
	    break;
    }

    glutSwapBuffers();
}
コード例 #15
0
ファイル: turtle.cpp プロジェクト: SimranVasir/GlutGame
void Turtle::draw() {
    

    // setup lights
    if(collided_)
        setupLight();

    // Setup transformation matrix for the turtle
    
    glPushMatrix();
    glTranslatef(x_, y_, 0);
    glNormal3f(0, 0, 1);
    
    glNormal3f(0, 0, 1);
    
    // Turtle shell.
    glColor4fv(shell_);
    glBegin(GL_POLYGON);
    for (double i = 0; i < M_PI; i += M_PI / 12)
        glVertex3f(cos(i) * radius_, sin(i) * radius_, 0.0);
    glEnd();
    
    // Turtle body, tail, legs, and head.
    float skin_[] = { 0.73, 0.59, 0.27, 1.0};
    glColor4fv(skin_);

    glBegin(GL_TRIANGLES);
    
    glVertex3f(-radius_ - 5, 10, 0);
    glVertex3f(-radius_ - 5, 20, 0);
    glVertex3f((-radius_ - 40), 15, 0);

    glVertex3f(-radius_ - 5, 10, 0);
    glVertex3f(-radius_ - 5, 0, 0);
    glVertex3f((-radius_ - 40), 5, 0);

    glVertex3f(-radius_ - 5, 10, 0);
    glVertex3f(-radius_ - 5, 0, 0);
    glVertex3f((-radius_ - 40), 5, 0);
    
    glEnd();

    glPushMatrix();
    glScalef(1, 0.15, 0.0);
    glBegin(GL_POLYGON);
    for (double i = 4.0 * M_PI / 6.0; i < 2 * M_PI; i += M_PI / 12)
        glVertex3f(cos(i) * radius_, sin(i) * radius_, 0.0);
    glEnd();
    glPopMatrix();

    glBegin(GL_TRIANGLES);
    
    glVertex3f(-radius_ - 5, 11, 0);
    glVertex3f(radius_ + 5, 0, 0);
    glVertex3f(-radius_ - 5, 0, 0);
    
    glVertex3f(-radius_ + 5, 0, 0);
    glVertex3f(-radius_ + 35, 0, 0);
    glVertex3f(-radius_ + 30, -25, 0);
    
    glVertex3f(20, 0, 0);
    glVertex3f(40, 0, 0);
    glVertex3f(40, -25, 0);
    
    glVertex3f(38, 10, 0);
    glVertex3f(40, 0, 0);
    glVertex3f(50, 15, 0);
    
    glEnd();
    
    glPushMatrix();
    glTranslatef(-radius_ - 10, 10, 0);
    glScalef(1, 0.5, 0.0);
    glBegin(GL_POLYGON);
    for (double i = -M_PI / 2.0; i < M_PI / 2.0; i += M_PI / 12)
        glVertex3f(cos(i) * 20, sin(i) * 20, 0.0);
    glEnd();
    glPopMatrix();
    
    // Turtle lowlights.
    glColor4fv(shell_);
    
    glBegin(GL_TRIANGLES);
    
    glVertex3f(-radius_ + 25, 5, 0);
    glVertex3f(-radius_ + 34, -7, 0);
    glVertex3f(-radius_ + 30, -25, 0);
    
    glVertex3f(15, -2, 0);
    glVertex3f(40, -10, 0);
    glVertex3f(40, -25, 0);
    
    glEnd();
    
    float lowlights_[] = { 0.17, 0.49, 0.27, 1.0 };
    glColor4fv(lowlights_);
    
    glBegin(GL_TRIANGLES);
    
    glVertex3f(-30, 10, 0);
    glVertex3f(-30, 5, 0);
    glVertex3f(40, 0, 0);
    
    glEnd();
    
    // Eyes and frowning eyebrows.
    glPushMatrix();
    glTranslatef(-radius_ - 10, 20, 0);
    const float white[] = {1.0, 1.0, 1.0, 1.0};
    glColor4fv(white);
    glNormal3f(0, 0, 1);
    glBegin(GL_POLYGON);
    for (double i = 0.0; i < 2 * M_PI; i += M_PI / 6)
        glVertex3f(cos(i) * 6, sin(i) * 6, 0.0);
    glEnd();
    const float black[] = {0.0, 0.0, 0.0, 1.0};
    glColor4fv(black);
    glNormal3f(0, 0, 1);
    glBegin(GL_POLYGON);
    for (double i = 0.0; i < 2 * M_PI; i += M_PI / 6)
        glVertex3f(cos(i) * 2, sin(i) * 2, 0.0);
    glEnd();
    glTranslatef(10, 0, 0);
    glColor4fv(white);
    glNormal3f(0, 0, 1);
    glBegin(GL_POLYGON);
    for (double i = 0.0; i < 2 * M_PI; i += M_PI / 6)
        glVertex3f(cos(i) * 6, sin(i) * 6, 0.0);
    glEnd();
    glColor4fv(black);
    glNormal3f(0, 0, 1);
    glBegin(GL_POLYGON);
    for (double i = 0.0; i < 2 * M_PI; i += M_PI / 6)
        glVertex3f(cos(i) * 2, sin(i) * 2, 0.0);
    glEnd();
    glPopMatrix();
    
    glBegin(GL_TRIANGLES);
    glVertex3f(-radius_ - 5, 23, 0);
    glVertex3f(-radius_ - 15, 30, 0);
    glVertex3f(-radius_ - 15, 25, 0);
    
    glVertex3f(-radius_ - 5, 23, 0);
    glVertex3f(-radius_ + 5, 30, 0);
    glVertex3f(-radius_ + 5, 25, 0);
    glEnd();

    // Restore the transformation matrix.
    glPopMatrix();
}
コード例 #16
0
void display()
{
	glClearDepth( 1 );
	glClearColor( 1, 1, 1, 1 );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	setupLight();

	glTranslatef( 0, 0, -view_distance );

	switch( view_mode ) {
	case PERSPECTIVE_VIEW:
		{
			float rot_mat[16];
			track_ball.BuildRotationMatrix( (float *)rot_mat );
			glMultMatrixf( (float *)rot_mat );
		}
		break;
	case TOP_VIEW:
		{
			glRotatef( 90, 1, 0, 0 );
		}
		break;
	}

	//
	unsigned int num_frames = motion_data.getNumFrames();
	unsigned int f = current_frame % num_frames;
	float thickness = 5.0f;
	//float thickness = 1.0f;

	glDisable( GL_DEPTH_TEST );
	glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );

	glEnable( GL_STENCIL_TEST );
	glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE );
	glStencilFunc( GL_ALWAYS, 1, 0xffffffff );

	drawFloor();

	glEnable( GL_DEPTH_TEST );
	glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );

	glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
	glStencilFunc( GL_EQUAL, 1, 0xffffffff );

	glPushMatrix();
	glScalef( 1, -1, 1 );

//	setupLight();

	drawing_tool.setColor( 1.0, 0.4, 0.0, 1 );
	drawing_tool.drawPose( &motion_data, f, thickness );

	glPopMatrix();

	glDisable( GL_STENCIL_TEST );

//	setupLight();

	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
	drawFloor();

	glDisable( GL_BLEND );

	drawing_tool.setColor( 1.0, 0.4, 0.0, 1 );
	drawing_tool.drawPose( &motion_data, f, thickness );

	char frame_str[128];
	sprintf( frame_str, "Current frame: %5d", f );
	//drawing_tool.drawText( 0, 0, GLUT_BITMAP_TIMES_ROMAN_24, frame_str );

	/*
	Joint* lf = motion_data.getHumanJoint( Human::LEFT_FOOT );
	Joint* rf = motion_data.getHumanJoint( Human::RIGHT_FOOT );
	Joint* lt = motion_data.getHumanJoint( Human::LEFT_TOE );
	Joint* rt = motion_data.getHumanJoint( Human::RIGHT_TOE );

	math::vector lf_v = motion_data.getLinearVelocity( f, lf->getIndex() );
	math::vector rf_v = motion_data.getLinearVelocity( f, rf->getIndex() );

	math::position lf_p = motion_data.getPosition( f, lf->getIndex() );
	math::position rf_p = motion_data.getPosition( f, rf->getIndex() );

	math::vector lt_v = motion_data.getLinearVelocity( f, lt->getIndex() );
	math::vector rt_v = motion_data.getLinearVelocity( f, rt->getIndex() );

	math::position lt_p = motion_data.getPosition( f, lt->getIndex() );
	math::position rt_p = motion_data.getPosition( f, rt->getIndex() );

	std::cout << "Foot height: Left( " << lf_p.y() << ", " << lf_v.y() << "), Right( " << rf_p.y() << ", " << rf_v.y() << ")\n";

//	double hl = 6, sl = 0.3;
	double hl = 20, sl = 3.0;

	if( lf_p.y() < hl && fabs(lf_v.y()) < sl && lt_p.y() < hl && fabs(lt_v.y()) < sl )
	{
		drawing_tool.drawText( 0, 0, GLUT_BITMAP_TIMES_ROMAN_24, "Left foot CONTACT" );
	}
	else
	{
		drawing_tool.drawText( 0, 0, GLUT_BITMAP_TIMES_ROMAN_24, "Left foot FLYING" );
	}

	if( rf_p.y() < hl && fabs(rf_v.y()) < sl && rt_p.y() < hl && fabs(rt_v.y()) < sl )
	{
		drawing_tool.drawText( 0, 30, GLUT_BITMAP_TIMES_ROMAN_24, "Right foot CONTACT" );
	}
	else
	{
		drawing_tool.drawText( 0, 30, GLUT_BITMAP_TIMES_ROMAN_24, "Right foot FLYING" );
	}
	*/

	//
	glutSwapBuffers();
}
コード例 #17
0
ファイル: Source.cpp プロジェクト: ceylanmeh/bilgisayarproje2
static void Draw(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    
	gluLookAt(0,10,10,0.f,0.f,-15.f,0,1,0);
    setupLight();
	
    GLUquadric* sun = gluNewQuadric();
    gluQuadricNormals(sun, GLU_SMOOTH);
    gluQuadricTexture(sun, GL_TRUE);
	glTranslatef(0.f, 0.f, -15.f);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,sun_2d);
	glPushMatrix();
    glRotated(90, 1, 0, 0);
	GLfloat emission[] = {0.9, 0.9, 0.9, 1};
	glMaterialfv(GL_FRONT, GL_EMISSION, emission);
	gluSphere( sun , 1 , 50 , 25 );
	glPopMatrix();
    glDisable(GL_TEXTURE_2D);
	
	GLfloat r_emission[4] = {0.0, 0.0, 0.0, 1.0};
    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, r_emission);
	
	glPushMatrix();
	
	GLUquadric* earth = gluNewQuadric();
    gluQuadricNormals(earth, GLU_SMOOTH);
    gluQuadricTexture(earth, GL_TRUE);
	glRotated(angle,0,1,0);
	glTranslatef(6.f, 0.f, 0.f);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,earth_2d);
	glRotated(angle,0,1,0);
	glPushMatrix();
	glRotated(90, -1, 0, 0);
	gluSphere( earth , 1 , 50 , 25 );
	glPopMatrix();
	glDisable(GL_TEXTURE_2D);
	
	glPushMatrix();

	GLUquadric* moon = gluNewQuadric();
    gluQuadricNormals(moon, GLU_SMOOTH);
    gluQuadricTexture(moon, GL_TRUE);
	glRotated(2*angle,0,-1,0);
	glTranslatef(2.f, 0.f, 0.f);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,moon_2d);
	glRotated(2*angle,0,-1,0);
	glPushMatrix();
	glRotated(90, 1, 0, 0);
	gluSphere( moon , 0.5 , 50 , 25 );
	glPopMatrix();
	glDisable(GL_TEXTURE_2D);
	
	glPopMatrix();
	glPushMatrix();

	GLUquadric* moon2 = gluNewQuadric();
    gluQuadricNormals(moon2, GLU_SMOOTH);
    gluQuadricTexture(moon2, GL_TRUE);
	glColor3ub(255, 255, 255);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,moon2_2d);
    glTranslatef(4.f, 0.f, 0.f);
	glRotated(angle,0,1,0);
	glPushMatrix();
	glRotated(90, 1, 0, 0);
	gluSphere( moon2 , 0.5 , 50 , 25 );
	glPopMatrix();
	glDisable(GL_TEXTURE_2D);
	glPopMatrix();
	
	glPopMatrix();

	GLUquadric* jupiter = gluNewQuadric();
    gluQuadricNormals(jupiter, GLU_SMOOTH);
    gluQuadricTexture(jupiter, GL_TRUE);
	glRotated(angle,0,-1,0);
	glTranslatef(14.f, 0.f, 0.f);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,mars_2d);
	glRotated(2*angle,0,1,0);
	glPushMatrix();
	glRotated(90, -1, 0, 0);
	gluSphere( jupiter , 1 , 50 , 25 );
	glPopMatrix();
	glDisable(GL_TEXTURE_2D);

	glPushMatrix();

	GLUquadric* moon3 = gluNewQuadric();
    gluQuadricNormals(moon3, GLU_SMOOTH);
    gluQuadricTexture(moon3, GL_TRUE);
	glRotated(3*angle,0,-1,0);
	glTranslatef(2.f, 0.f, 0.f);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,moon2_2d);
	glRotated(3*angle,0,-1,0);
	glPushMatrix();
	glRotated(90, 1, 0, 0);
	gluSphere( moon , 0.5 , 50 , 25 );
	glPopMatrix();
	glDisable(GL_TEXTURE_2D);
    
	
	glPopMatrix();
	
    glutSwapBuffers();
    
}
コード例 #18
0
ファイル: fog.cpp プロジェクト: gordon0308/cg-assignment3
/**
 * Program entry. Sets up OpenGL state, GLSL Shaders and GLUT window and function call backs
 * Takes no arguments
 */
int main(int argc, char **argv) {
    std::cout << "Controls: arrow keys rotate cube\n";

    // Set up GLUT window
    glutInit(&argc, argv);
    glutInitWindowPosition(100, 0);
    glutInitWindowSize(winX, winY);

#ifdef __APPLE__    
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_3_2_CORE_PROFILE);
#else
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
#endif
    glutCreateWindow("Many Attributes");

    // Initialize GLEW
    glewExperimental = true; // Needed for core profile
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }

    lightProgramID = LoadShaders("pv-light.vert", "pv-light.frag");
    if (lightProgramID == 0) {
        fprintf(stderr, "Can't compile shaders!\n");
        return 1;
    }
    glUseProgram(lightProgramID);
    if (setupLight() !=0)
        return 1;

    glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glFrontFace(GL_CCW);
    tableprogramID = LoadShaders("pv-light.vert", "pv-light.frag");
    if (tableprogramID == 0)
        return 1;
    
    if (setupTable() !=0)
        return 1;
    
    skyID = LoadShaders("sky.vert", "sky.frag");
    if (skyID == 0)
        return 1;
    glUseProgram(skyID);
    if (setup() !=0)
        return 1;

    

    // Here we set a new function callback which is the GLUT handling of keyboard input
    glutKeyboardFunc(keyboardDown);
    glutSpecialFunc(SpecialFunc);
    glutMouseFunc(MouseFunc);
    glutMotionFunc(MotionFunc); 
    glutDisplayFunc(render);
    glutReshapeFunc(reshapeFunc);
    glutMainLoop();

    return 0;
}