Exemple #1
0
void appInit (int resX, int resY)
{
  int argc = 0;

  //Init GLUT
  glutInit( &argc, NULL );
  glutInitDisplayMode( GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STENCIL );

  glutInitWindowPosition( 100,100 );
  glutInitWindowSize( resX,resY );
  glutCreateWindow( "Game App" );

  //glutGameModeString( "1280x1024:32@60" );
  //glutEnterGameMode();
  
  glutReshapeFunc( reshape );
  glutDisplayFunc( display );
  glutKeyboardFunc( keyDown );
  glutKeyboardUpFunc( keyUp );
  glutSpecialFunc( specialKey );
  glutMouseFunc( mouseClick );
  glutMotionFunc( mouseMove );
  glutPassiveMotionFunc( mouseMove );
  glutIdleFunc( animate );

  //Create kernel
  Kernel *kernel = new Kernel;
  kernel->enableVerticalSync( false );
  renderer = kernel->getRenderer();
  renderer->setWindowSize( resX, resY );
}
Exemple #2
0
int main (int argc, char **argv)
{
  //Initialize GLUT
  initGlut( argc, argv );
  
  Kernel kernel;
  kernel.enableVerticalSync( false );
  printf( "Kernel loaded\n" );
  
  //Setup camera
  cam3D.setCenter( center );
  cam3D.translate( 0,0,200 );
  cam3D.orbitV( Util::DegToRad( -20 ), true );
  cam3D.orbitH( Util::DegToRad( +45 ), true );
  cam3D.setNearClipPlane( 10.0f );
  cam3D.setFarClipPlane( 1000.0f );
  
  //VertColorMaterial mat;
  //StandardMaterial mat;
  PhongMaterial mat;
  mat.setSpecularity( 0.5 );
  
  //StandardMaterial mat;
  //mat.setCullBack( false );
  //mat.setUseLighting( false );
  /*
  polyActor = new SPolyActor;
  polyActor->setMaterial( &mat );
  polyActor->setMesh( polyMesh );
  
  triActor = new TriMeshActor;
  triActor->setMaterial( &mat );
  triActor->setMesh( triMesh );
  */
  
  lblFps.setLocation( Vector2( 0.0f, (Float)resY ));
  lblFps.setColor( Vector3( 1.0f, 1.0f, 1.0f ));
  
  //Find model center
  findCenter();
  cam3D.setCenter( center );

  //Run application
  atexit( cleanup );
  glutMainLoop();
  cleanup();

  return EXIT_SUCCESS;
}
Exemple #3
0
int main (int argc, char **argv)
{  
  //Initialize GLUT
  initGlut(argc, argv);
  
  Kernel kernel;
  kernel.enableVerticalSync( false );
  renderer = kernel.getRenderer();
  printf( "Kernel loaded\n" );
  
  //Load shape model
  LoaderObj ldr;
  File f( "zekko.obj" );
  ldr.setUVMeshClass( Class( ETexMesh ));
  
  int start = GE::Time::GetTicks();
  ldr.loadFile( f.getPathName() );
  int end = GE::Time::GetTicks();
  printf( "Time: %d\n", end - start );
  
  PolyMesh *dmesh;
  uvmesh = (ETexMesh*) ldr.getFirstResource( Class(TexMesh) );
  dmesh = (PolyMesh*) ldr.getFirstResource( Class(PolyMesh) );
  zekko = (PolyMeshActor*) ldr.getFirstObject( Class(PolyMeshActor) );
  if (dmesh == NULL) return EXIT_FAILURE;
  if (uvmesh == NULL) return EXIT_FAILURE;
  if (zekko == NULL) return EXIT_FAILURE;
  
  //Check if UV mesh type correct
  printf( "uvmesh = %s\n", StringOf( ClassOf( zekko->getTexMesh() )));
  
  printf( "uvmesh %s ETexMesh\n",
          SafeCast( ETexMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s TexMesh\n",
          SafeCast( TexMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s Resource\n",
          SafeCast( Resource, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  printf( "uvmesh %s PolyMesh\n",
          SafeCast( PolyMesh, zekko->getTexMesh() ) ?
          "IS" : "is NOT");
  
  //Setup camera
  cam3D.translate( 0,35,-100 );
  cam3D.setCenter( center );
  //cam3D.setNearClipPlane(100.0f);
  //cam3D.setFarClipPlane(100000.0f);
  
  //Find model center
  findCenter();
  
  //Set half bunny green
  for (PolyMesh::FaceIter f(dmesh); !f.end(); ++f) {
    //f->smoothGroups = 0x1;
    if (f->firstHedge()->dstVertex()->point.y > center.y)
      dmesh->setMaterialID( *f, 1 ); }

  //Convert to static mesh
  //dmesh->updateNormals();
  smesh.fromPoly( dmesh, uvmesh );
  
  //Load texture image
  imgDiff.readFile( "texture.jpg", "" );
  
  //Create texture from image
  texDiff = new Texture;
  texDiff->fromImage( &imgDiff );
  
  //Load specularity image
  Image imgSpec;
  imgSpec.readFile( "specularity.jpg", "" );

  //Create specularity texture
  texSpec = new Texture();
  texSpec->fromImage(&imgSpec);
  
  //Create material using texture
  PhongMaterial mat;
  mat.setDiffuseTexture( texDiff );
  //mat.setSpecularityTexture( texSpec );
  mat.setDiffuseColor( Vector3( 1,0.0f,0.0f ));
  mat.setAmbientColor( Vector3( 0.2f,0.2f,0.2f ));
  mat.setSpecularity( 1.0f );
  mat.setGlossiness( 0.2f );
  
  PhongMaterial mat2;
  mat2.setDiffuseTexture( texDiff );
  //mat2.setSpecularityTexture( texSpec );
  mat2.setDiffuseColor( Vector3( 0.0f, 1.0f, 0.0f ));
  mat2.setAmbientColor( Vector3( 0.2f, 0.2f, 0.2f ));
  mat2.setSpecularity( 1.0f );
  mat2.setGlossiness( 0.2f );
  
  MultiMaterial mm;
  mm.setNumSubMaterials( 2 );
  mm.setSubMaterial( 0, &mat );
  mm.setSubMaterial( 1, &mat2 );
  zekko->setMaterial( &mm );

  scene = new Scene;
  scene->addChild( zekko );

  //Light *light = new SpotLight( Vector3(-200,200,-200), Vector3(1,-1,1), 60, 0 );
  Light *light = new HeadLight;
  scene->addChild( light );
  
  lblFps.setLocation( Vector2( 0.0f,(Float)resY ));
  lblFps.setColor( Vector3( 1.0f,1.0f,1.0f ));
  
  //Run application
  atexit( cleanup );
  glutMainLoop();
  cleanup();

  return EXIT_SUCCESS;
}
Exemple #4
0
int main (int argc, char **argv)
{
  //Initialize GLUT
  initGlut( argc, argv );
  
  Kernel kernel;
  kernel.enableVerticalSync( false );
  renderer = kernel.getRenderer();
  printf( "Kernel loaded\n" );

  StandardMaterial matRedLogo;
  matRedLogo.setSpecularity( 0.5 );
  matRedLogo.setDiffuseColor( Vector3(1,0,0) );
  matRedLogo.setAmbientColor( matRedLogo.getDiffuseColor() * .8f );

  StandardMaterial matWhiteLogo;
  matWhiteLogo.setSpecularity( 0.5 );
  matWhiteLogo.setAmbientColor( matWhiteLogo.getDiffuseColor() * .8f );

  StandardMaterial matWhite;
  matWhite.setSpecularity( 0.5 );

  StandardMaterial matBlue;
  matBlue.setSpecularity( 0.5 );
  matBlue.setDiffuseColor( Vector3(0,0.5,1) );

  StandardMaterial matGreen;
  matGreen.setSpecularity( 0.5 );
  matGreen.setDiffuseColor( Vector3(0,0.6,0) );

  StandardMaterial matYellow;
  matYellow.setSpecularity( 0.5 );
  matYellow.setDiffuseColor( Vector3(1,1,0.7) );

  StandardMaterial matBlack;
  matBlack.setSpecularity( 0.5 );
  matBlack.setDiffuseColor( Vector3(0.2,0.2,0.2) );

  MultiMaterial mm;
  mm.setNumSubMaterials( 5 );
  mm.setSubMaterial( 0, &matBlue );
  mm.setSubMaterial( 1, &matYellow );
  mm.setSubMaterial( 2, &matWhite );
  mm.setSubMaterial( 3, &matBlack );
  mm.setSubMaterial( 4, &matBlue );

  MultiMaterial mm2;
  mm2.setNumSubMaterials( 5 );
  mm2.setSubMaterial( 0, &matGreen );
  mm2.setSubMaterial( 1, &matYellow );
  mm2.setSubMaterial( 2, &matWhite );
  mm2.setSubMaterial( 3, &matBlack );
  mm2.setSubMaterial( 4, &matGreen );

  MultiMaterial mmLogo;
  mmLogo.setNumSubMaterials( 2 );
  mmLogo.setSubMaterial( 0, &matWhiteLogo );
  mmLogo.setSubMaterial( 1, &matRedLogo );

  //Setup Logo scene

  sceneLogo = new Scene;

  loadLogo( "logo.pak" );
  actLogo = new TriMeshActor;
  actLogo->setMesh( mshLogo );
  actLogo->translate( 200, 0, 0 );
  actLogo->setMaterial( &mmLogo );
  sceneLogo->addChild( actLogo );

  camLogo = new Camera3D;
  camLogo->translate( 0,0,-600 );
  camLogo->setNearClipPlane( 1.0f );
  camLogo->setFarClipPlane( 3000.0f );

  lightLogo = new SpotLight( Vector3(0,0,-500), Vector3(0,0,1), 60, 50 );
  lightLogo->setCastShadows( true );
  sceneLogo->addChild( lightLogo );

  //Setup Bub scene

  loadPackage( "bub.pak" );
  scene = new Scene;
  
  skinActor = new SkinMeshActor;
  skinActor->setMaterial( &mm );
  skinActor->setMesh( character );
  skinActor->translate( 60, 0, 0 );
  scene->addChild( skinActor );

  skinActor2 = new SkinMeshActor;
  skinActor2->setMaterial( &mm2 );
  skinActor2->setMesh( character );
  skinActor2->translate( -60, 0, 0 );
  scene->addChild( skinActor2 );

  TriMesh *cubeMesh = new CubeMesh;
  TriMeshActor *cube = new TriMeshActor;
  cube->setMaterial( &matWhiteLogo );
  cube->setMesh( cubeMesh );
  cube->scale( 300, 10, 300 );
  cube->translate( 0, -70, 0 );
  scene->addChild( cube );

  StandardMaterial axesMat;
  axesMat.setUseLighting( false );
  AxisActor *axes = new AxisActor;
  axes->scale( 100 );
  axes->setMaterial( &axesMat );
  //scene->addChild( axes );

  cam3D.setCenter( center );
  cam3D.translate( 0,0,-400 );
  cam3D.orbitV( Util::DegToRad( 20 ), true );
  cam3D.orbitH( Util::DegToRad( 30 ), true );
  cam3D.setNearClipPlane( 1.0f );
  cam3D.setFarClipPlane( 3000.0f );

  light = new SpotLight( Vector3(-200,200,-200), Vector3(1,-1,1), 60, 59 );
  light->setCastShadows( true );
  //light->setDiffuseColor( Vector3( 1,.2,.2 ) );
  scene->addChild( light );

  Light* l = new SpotLight( Vector3(200,200,-200), Vector3(-1,-1,1), 60, 0 );
  l->setCastShadows( true );
  //l->setDiffuseColor( Vector3( .2,.2,1 ) );
  scene->addChild( l );

  //Start with Logo scene
  sceneRender = sceneLogo;
  lightRender = lightLogo;
  camRender = camLogo;

  //sceneRender = scene;
  //lightRender = light;
  //camRender = &cam3D;

  ///////////////////////////////////////
  //Test triangulation
  PolyMesh p;
  int numVerts = 6;
  ArrayList< PolyMesh::Vertex* > verts;
  for (int v=0; v<numVerts; ++v)
    verts.pushBack( p.addVertex() );
  p.addFace( verts.buffer(), numVerts );

  verts[0]->point.set( 0,0,0 );
  verts[1]->point.set( 1,0,0 );
  verts[2]->point.set( 1,1,0 );
  verts[3]->point.set( 2,1,0 );
  verts[4]->point.set( 2,2,0 );
  verts[5]->point.set( 0,2,0 );
  p.triangulate();

  PolyMeshActor *pa = new PolyMeshActor;
  pa->setMesh( &p );
  pa->scale( 100, 100, 100 );
  //scene->addChild( pa );

  /////////////////////////////////
  
  lblFps.setLocation( Vector2( 0.0f, (Float)resY ));
  lblFps.setColor( Vector3( 1.0f, 1.0f, 1.0f ));
  
  //Find model center
  findCenter();
  cam3D.setCenter( center );

  //Run application
  atexit( cleanup );
  glutMainLoop();
  cleanup();

  return EXIT_SUCCESS;
}