示例#1
0
/*------------------
  move the camera
  C.Wang 0329, 2004
 -------------------*/
void MoveCam(int x, int y)
{
   if (x != oldXM) {
      FnObject model;

      model.ID(cID);
      model.Translate((float)(x - oldXM)*0.1f, 0.0f, 0.0f, LOCAL);
      oldXM = x;
   }
   if (y != oldYM) {
      FnObject model;

      model.ID(cID);
      model.Translate(0.0f, (float)(oldYM - y)*0.1f, 0.0f, LOCAL);
      oldYM = y;
   }
}
示例#2
0
/*------------------
  zoom the camera
  C.Wang 0329, 2004
 -------------------*/
void ZoomCam(int x, int y)
{
   if (x != oldXMM || y != oldYMM) {
      FnObject model;

      model.ID(cID);
      model.Translate(0.0f, 0.0f, (float)(x - oldXMM), LOCAL);
      oldXMM = x;
      oldYMM = y;
   }
}
示例#3
0
/*------------------
  move the camera
  C.Wang 0329, 2005
 -------------------*/
void MoveCam ( int x, int y )
{
	float dx = float(x - oldXM);
	float dy = float(y - oldYM);
	float dd = sqrt(dx*dx + dy*dy);
	if (sgn(dd) == 0)return;
	dx /= dd;
	dy /= dd;
	FnObject model;
	if ( x != oldXM ) {
		model.ID ( cID );
		model.Translate(0.1f*dx, 0.0f, 0.0f, LOCAL);
		oldXM = x;
	}
	if ( y != oldYM ) {
		model.ID ( cID );
		model.Translate(0.0f, 0.1f*dy, 0.0f, LOCAL);
		oldYM = y;
	}
}
示例#4
0
/*------------------
  the main program
  C.Wang 0308, 2004
 -------------------*/
void FyMain(int argc, char **argv)
{
   // create a new world
   FyStartFlyWin32("Hello TheFly3D !", 0, 0, 800, 600, beFullScreen);

   FySetModelPath("Data\\Models");
   FySetTexturePath("Data\\textures");
   FySetShaderPath("Data\\Shaders");

   FyBeginMedia("data\\media", 2);
   //mmID = FyCreateMediaPlayer("dawn.mpg", 0, 0, 800, 600);
   //mmID = FyCreateMediaPlayer("opening.avi", 0, 0, 800, 600);
   mmID = FyCreateMediaPlayer("MUSIC_fogforest.mp3", 0, 0, 800, 600);
   FnMedia mP;
   mP.Object(mmID);
   mP.Play(ONCE);
   //mP.SetVolume(0.1f);
   
   // create a viewport
   vID = FyCreateViewport(0, 0, 800, 600);
   FnViewport vp;
   vp.Object(vID);
   vp.SetBackgroundColor(0.3f, 0.4f, 0.5f);

   // create a 3D scene & the 3D entities
   sID = FyCreateScene(1);

   FnScene scene;
   scene.Object(sID);
   nID = scene.CreateObject(OBJECT);
   cID = scene.CreateObject(CAMERA);
   lID = scene.CreateObject(LIGHT);

   // load the teapot
   FnObject model;
   model.ID(nID);
   model.Load("teapot.cw3");
   model.Translate(20.0f, 0.0f, 0.0f, GLOBAL);
   
   // translate the camera
   FnCamera camera;
   camera.ID(cID);
   camera.Rotate(X_AXIS, 90.0f, LOCAL);
   camera.SetAspectRatio(800.0f/600.0f);
   camera.Translate(0.0f, 10.0f, 200.0f, LOCAL);

   // translate the light
   FnLight light;
   light.ID(lID);
   light.Translate(-30.0f, -30.0f, 0.0f, GLOBAL);
   light.SetName("MainLight");
   light.SetColor(0.9f, 0.9f, 0.7f);

   // set Hotkeys
   FyDefineHotKey(FY_ESCAPE, QuitGame, FALSE);

   // define some mouse functions
   FyBindMouseFunction(LEFT_MOUSE, InitPivot, PivotCam, NULL, NULL);
   FyBindMouseFunction(MIDDLE_MOUSE, InitZoom, ZoomCam, NULL, NULL);
   FyBindMouseFunction(RIGHT_MOUSE, InitMove, MoveCam, NULL, NULL);

   /* bind a timer, frame rate = 30 fps */
   FyBindTimer(0, 30.0f, GameAI, TRUE);

   // invoke the system
   FyInvokeFly(TRUE);
}