Пример #1
0
void MiniMap::render(OBJECTid fronterID, Lyubu* lyubu, OurEnemyActor **enemyActor, int enemy_num)
{
	//render miniMap
	FnObject miniMapStand, mapRef, anchor_lyubu;

	float pos[3];
	lyubu->actor.GetWorldDirection(pos,NULL);
	anchor_lyubu.Object(anchorID);
	anchor_lyubu.SetWorldDirection(pos,NULL);
	miniMapStand.Object(miniMapStandID);
	mapRef.Object(fronterID);
	miniMapStand.SetMatrix(mapRef.GetMatrix(FALSE), REPLACE);

	for(int i = 0; i < enemy_num; i++)
	{
		FnObject base, anchor;
		OBJECTid baseID = enemyActor[i]->actor.GetBaseObject();
		base.Object(baseID);
		anchor.Object(enemyActor[i]->anchorID);
		anchor.SetMatrix(base.GetMatrix(FALSE), REPLACE);
	}
	

	FnViewport vp;
	vp.Object(vpMiniMapID);
	//vp.Render(miniMapCameraID, FALSE, FALSE);
	vp.Render(miniMapCameraID, FALSE, TRUE);
}
Пример #2
0
/*--------------------------
  set rendering target data
  C.Wang 0522, 2006
 ---------------------------*/
void FuCShadowModify::SetRenderTarget(int w, float *bgColor)
{
   FnScene scene;
   FnWorld gw;
   FnViewport vp;
   char shadowName[256];

   scene.Object(mHost);
   gw.Object(scene.GetWorld());
   gw.DeleteMaterial(mRenderTarget);
   gw.DeleteViewport(mViewport);

   // create the viewport with the associated size
   mViewport = gw.CreateViewport(0, 0, w, w);

   // create the render target material
   mRenderTarget = gw.CreateMaterial(NULL, NULL, NULL, 1.0f, NULL);

   // generate a unique shadow texture name
   sprintf(shadowName, "shadow%d", mRenderTarget);

   FnMaterial mat;
   mat.Object(mRenderTarget);
   mat.AddRenderTargetTexture(0, 0, shadowName, TEXTURE_32, mViewport);
   mat.SetTextureAddressMode(0, CLAMP_TEXTURE);

   // set render target
   vp.Object(mViewport);
   vp.SetRenderTarget(mRenderTarget, 0, 0, 0);
   vp.SetBackgroundColor(bgColor[0], bgColor[1], bgColor[2]);
}
Пример #3
0
/* ----------------------
perform the rendering
C.Wang 0720, 2006
---------------------- - /
/ ----------------------
perform the rendering
C.Wang 0720, 2006
---------------------- - */
void RenderIt(int skip)
{
	FnViewport vp;

	// render the whole scene
	vp.ID(vID);
	vp.Render3D(cID, TRUE, TRUE);

	// get camera's data
	FnCamera camera;
	camera.ID(cID);

	float pos[3], fDir[3], uDir[3];
	camera.GetPosition(pos);
	camera.GetDirection(fDir, uDir);

	// show frame rate
	static char string[128];
	if (frame == 0) {
		FyTimerReset(0);
	}

	if (frame / 10 * 10 == frame) {
		float curTime;

		curTime = FyTimerCheckTime(0);
		sprintf(string, "Fps: %6.2f", frame / curTime);
	}

	frame += skip;
	if (frame >= 1000) {
		frame = 0;
	}

	FnText text;
	text.ID(textID);

	text.Begin(vID);
	text.Write(string, 20, 20, 255, 0, 0);

	char posS[256], fDirS[256], uDirS[256];
	float cpos[3], apos[3], distance, height, length;//
	FnCharacter actor;
	actor.ID(actorID);

	FnObject terrain;
	terrain.ID(tID);

	sprintf(posS, "pos: %8.3f %8.3f %8.3f", pos[0], pos[1], pos[2]);
	sprintf(fDirS, "facing: %8.3f %8.3f %8.3f", fDir[0], fDir[1], fDir[2]);
	sprintf(uDirS, "up: %8.3f %8.3f %8.3f", uDir[0], uDir[1], uDir[2]);
	text.Write(posS, 20, 35, 255, 255, 0);
	text.Write(fDirS, 20, 50, 255, 255, 0);
	text.Write(uDirS, 20, 65, 255, 255, 0);

	text.End();

	// swap buffer
	FySwapBuffers();
}
Пример #4
0
/*------------------
  the main program
  C.Wang 0904, 2012
 -------------------*/
void FyMain(int argc, char **argv)
{
   // create a new world
   FyStartFlyWin32("Hello Fly2 !", 0, 0, 800, 600, FALSE);

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

   // create a viewport
   vID = FyCreateViewport(0, 0, 800, 600);
   FnViewport vp;
   vp.ID(vID);
   vp.SetBackgroundColor(0.3f, 0.4f, 0.5f);

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

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

   // load the teapot model
   FnObject model;
   model.ID(nID);
   model.Load("teapot");

   // translate the camera
   FnCamera camera;
   camera.ID(cID);
   camera.Rotate(X_AXIS, 90.0f, LOCAL);
   camera.Translate(0.0f, 10.0f, 100.0f, LOCAL);

   // translate the light
   FnLight light;
   light.ID(lID);
   light.SetName("MainLight");
   light.Translate(-50.0f, -50.0f, 50.0f, GLOBAL);

   // 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);
}
Пример #5
0
/*------------------
  render the shadow
  C.Wang 0522, 2006
 -------------------*/
void FuCShadowModify::Render()
{
	if ( !m_objVec.empty() )
	{
		FnViewport vp;
		vp.Object(mViewport);
		m_fyActor.GetWorldPosition( m_actorPos );
		m_lightCam.SetWorldPosition( m_actorPos + m_lightPos );
		vp.RenderShadow( m_lightCam.Object() , &m_objVec[0] , m_objVec.size() , mShadowMat, TRUE);
	}
}
Пример #6
0
/*-------------------------------------------------------------------------------
  timer callback function which will be invoked by Fly2 System every 1/30 second
  C.Wang 0308, 2004
 --------------------------------------------------------------------------------*/
void GameAI(int skip)
{
   // render the scene
   FnViewport vp;
   vp.Object(vID);
   vp.Render3D(cID, TRUE, TRUE);

   int nV, nT;
   FyRenderBenchMark(&nT, &nV);

   FySwapBuffers();
}
Пример #7
0
//------------------------------------------------------------------------------------
// timer callback function which will be invoked by TheFly3D System every 1/30 second
// C.Wang 0308, 2004
//------------------------------------------------------------------------------------
void GameAI(int skip)
{
   if (mmID != FAILED_ID) {
      FnMedia md;
      md.Object(mmID);
      if (md.GetState() == MEDIA_STOPPED) {
         // after playing, delete the media object
         FyDeleteMediaPlayer(mmID);
         mmID = FAILED_ID;
      }
      else {
         return;
      }
   }

   FnLight lgt;
   lgt.Object(lID);
   lgt.Rotate(Z_AXIS, 0.5f, GLOBAL);

   FnObject model;
   model.Object(nID);
   model.Rotate(Z_AXIS, 3.0f, GLOBAL);

   // render the scene
   FnViewport vp;
   vp.Object(vID);
   vp.Render3D(cID, TRUE, TRUE);

   // show frame rate

   static char string[128];

   if (frame == 0) {
      FyTimerReset(0);
   }

   if (frame/10*10 == frame) {
      float curTime;

      curTime = FyTimerCheckTime(0);
      sprintf(string, "Fps: %6.2f", frame/curTime);
   }

   frame += skip;

   if (frame >= 1000) {
      frame = 0;
   }

   FySwapBuffers();
}
Пример #8
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);
}
Пример #9
0
void RenderIt(int skip){
	float pos[3], fDir[3], uDir[3];

	FnViewport vp;

	if(!stateMenu) {mouseInput.update();}

	//render the whole scene
	vp.ID(viewportID);
	if (!stateGhost)
		vp.Render3D(cameraID, TRUE, TRUE);
	
	if(stateMenu)
		vp.RenderSprites(sID2menu, FALSE, TRUE);  // no clear the background but clear the z buffer
	else
		vp.RenderSprites(sID2, FALSE, TRUE);  // no clear the background but clear the z buffer
	
	//show frame rate
	static char string[128];
	if(frame == 0){
		FyTimerReset(0);
	}

	if((frame/10)*10 == frame){
		float curTime;
		curTime = FyTimerCheckTime(0);
		sprintf_s(string, "Fps: %6.2f", frame/curTime);
	}

	frame += skip;
	if(frame >= 1000){
		frame = 0;
	}

	FnText text, charactorInfo,char_HP,info;
	text.ID(textID);
	charactorInfo.ID(textCharID);
	char_HP.ID(textHP_vID);
	info.ID(textInfo_vID);


	text.Begin(viewportID);
	charactorInfo.Begin(viewportID);
	text.Write(string, 20, 20, 255, 0, 0);

	//get camera's data
	camera.getCameraPos(pos);
	camera.getCameraDir(fDir, uDir);

	float fCameraAngle = camera.getCameraAngle();

	char posS[256], fDirS[256], uDirS[256];
	sprintf_s(posS, "pos: %8.3f %8.3f %8.3f", pos[0], pos[1], pos[2]);
	sprintf_s(fDirS, "facing: %8.3f %8.3f %8.3f", fDir[0], fDir[1], fDir[2]);
	sprintf_s(uDirS, "up: %8.3f %8.3f %8.3f", uDir[0], uDir[1], uDir[2]);

	char sCameraAngle[256], sMousePosX[256], sMousePosY[256];
	sprintf_s(sCameraAngle, "camera angle: %8.3f", fCameraAngle);
	sprintf_s(sMousePosX, "mouse X %d ", mouseInput.mousePosX);
	sprintf_s(sMousePosY, "mouse Y %d ", mouseInput.mousePosY);
	text.Write(sCameraAngle, 20, 35, 255, 255, 0);
	text.Write(sMousePosX, 20, 50, 255, 255, 0);
	text.Write(sMousePosY, 20, 65, 255, 255, 0);
    
	text.Write(posS, 20, 80, 255, 255, 0);
    text.Write(fDirS, 20, 95, 255, 255, 0);
    text.Write(uDirS, 20, 110, 255, 255, 0);

	FnCharacter actor;
	actor.ID(actorID);
	//get actor's data
	actor.GetPosition(pos);
	actor.GetDirection(fDir, uDir);
	sprintf_s(posS, "pos: %8.3f %8.3f %8.3f", pos[0], pos[1], pos[2]);
	sprintf_s(fDirS, "facing: %8.3f %8.3f %8.3f", fDir[0], fDir[1], fDir[2]);
	sprintf_s(uDirS, "up: %8.3f %8.3f %8.3f", uDir[0], uDir[1], uDir[2]);
    
	text.Write(posS, 20, 125, 255, 255, 0);
    text.Write(fDirS, 20, 140, 255, 255, 0);
    text.Write(uDirS, 20, 155, 255, 255, 0);

   text.End();

   	sprintf_s(posS, "HEALTH");
	charactorInfo.Write(posS, 50, 700, 255, 255, 100);
	sprintf_s(posS, "ROUND");
	charactorInfo.Write(posS, 400, 700, 255, 255, 100);
	sprintf_s(posS, "TIME");
	charactorInfo.Write(posS, 515, 700, 255, 255, 100);
	charactorInfo.End();

	sprintf_s(posS, "%d", chrMgtSystem.getCharacterblood(actorID));
	char_HP.Write(posS, 110, 672, 255, 255, 255);
	sprintf_s(posS, "%d", game_timer.getCurrentRound());
	info.Write(posS, 460, 694 ,255, 255, 255);
	sprintf_s(posS, "%d", game_timer.getTimeLeft());
	info.Write(posS, 560, 694, 255, 255, 255);
	info.End();

   FySwapBuffers();
}
Пример #10
0
/*------------------
the main program
C.Wang 1010, 2014
-------------------*/
void FyMain(int argc, char **argv)
{
	// create a new world
	BOOL4 beOK = FyStartFlyWin32("NTU@2015 Homework #02 - Use Fly2", 0, 0, 1024, 768, FALSE);

	// setup the data searching paths
	FySetShaderPath("Data\\NTU6\\Shaders");
	FySetModelPath("Data\\NTU6\\Scenes");
	FySetTexturePath("Data\\NTU6\\Scenes\\Textures");
	FySetScenePath("Data\\NTU6\\Scenes");

	//Tang: FX
	FySetGameFXPath("Data\\NTU6\\FX");
	//Tang

	// create a viewport
	vID = FyCreateViewport(0, 0, 1024, 768);
	FnViewport vp;
	vp.ID(vID);

	// create a 3D scene
	sID = FyCreateScene(10);
	FnScene scene;
	scene.ID(sID);

	// load the scene
	scene.Load("gameScene02");
	scene.SetAmbientLights(1.0f, 1.0f, 1.0f, 0.6f, 0.6f, 0.6f);

	// load the terrain
	tID = scene.CreateObject(OBJECT);
	FnObject terrain;
	terrain.ID(tID);
	BOOL beOK1 = terrain.Load("terrain");
	terrain.Show(FALSE);

	// set terrain environment
	terrainRoomID = scene.CreateRoom(SIMPLE_ROOM, 10);
	FnRoom room;
	room.ID(terrainRoomID);
	room.AddObject(tID);

	// load the character
	FySetModelPath("Data\\NTU6\\Characters");
	FySetTexturePath("Data\\NTU6\\Characters");
	FySetCharacterPath("Data\\NTU6\\Characters");
	actorID = scene.LoadCharacter("Lyubu2");

	// put the character on terrain
	float pos[3], fDir[3], uDir[3];
	SetValues(pos, 3569.0f, -3208.0f, 1000.0f);
	SetValues(fDir, 1.0f, 1.0f, 0.0f);
	SetValues(uDir, 0.0f, 0.0f, 1.0f);

	ActorGen(scene, terrainRoomID, LyubuID, "Lyubu2", "Idle", pos, fDir, uDir);
	actorID = LyubuID.actorID;

	FnCharacter actor;
	actor.ID(actorID);

	// Get two character actions pre-defined at Lyubu2
	idleID = actor.GetBodyAction(NULL, "Idle");
	runID = actor.GetBodyAction(NULL, "Run");
	NormalAttack1ID = actor.GetBodyAction(NULL, "NormalAttack1");
	NormalAttack2ID = actor.GetBodyAction(NULL, "NormalAttack2");
	HeavyAttack1ID = actor.GetBodyAction(NULL, "HeavyAttack1");

	// translate the camera
	cID = scene.CreateObject(CAMERA);
	FnCamera camera;
	camera.ID(cID);
	camera.SetNearPlane(5.0f);
	camera.SetFarPlane(100000.0f);

	//hw3 : Donzo and Robber02 initialization
	float temp_pos[3];
	float temp_fDir[3];

	/*
	for (int i = 0; i < NUM_OF_BADGUYS; i++)
	{
	temp_pos[0] = pos[0] + 30 * (rand()%8);
	temp_pos[1] = pos[1] + 30 * (rand()%8);
	temp_pos[2] = pos[2] + 30 * (rand()%8);
	temp_fDir[0] = -1.0f; temp_fDir[1] = -1.0f; temp_fDir[2] = 1.0f;

	ActorGen(scene, terrainRoomID, badguyID[i], "Robber02", "CombatIdle", temp_pos, temp_fDir, uDir);
	}
	*/
	for (int i = 0; i < NUM_OF_BOSS; i++)
	{
		temp_pos[0] = pos[0] + 30 * (rand() % 8);
		temp_pos[1] = pos[1] + 30 * (rand() % 8);
		temp_pos[2] = pos[2] + 30 * (rand() % 8);
		SetValues(temp_fDir, -1.0f, -1.0f, 1.0f);

		ActorGen(scene, terrainRoomID, BossID[i], "Donzo2", "CombatIdle", temp_pos, temp_fDir, uDir);
	}


	// hw2 initial : set camera position
	actor.GetPosition(pos);

	pos[0] = pos[0] - SHORTDIST * fDir[0];
	pos[1] = pos[1] - SHORTDIST * fDir[1];
	pos[2] = pos[2] + HEIGHTOFFSET;

	SetValues(fDir, 1.0f, 1.0f, 0.0f);
	SetValues(uDir, 0.0f, 0.0f, 1.0f);

	camera.SetPosition(pos);
	camera.SetDirection(fDir, uDir); // the same as actor

	float mainLightPos[3] = { -4579.0, -714.0, 15530.0 };
	float mainLightFDir[3] = { 0.276, 0.0, -0.961 };
	float mainLightUDir[3] = { 0.961, 0.026, 0.276 };

	FnLight lgt;
	lgt.ID(scene.CreateObject(LIGHT));
	lgt.Translate(mainLightPos[0], mainLightPos[1], mainLightPos[2], REPLACE);
	lgt.SetDirection(mainLightFDir, mainLightUDir);
	lgt.SetLightType(PARALLEL_LIGHT);
	lgt.SetColor(1.0f, 1.0f, 1.0f);
	lgt.SetName("MainLight");
	lgt.SetIntensity(0.4f);

	// create a text object for displaying messages on screen
	textID = FyCreateText("Trebuchet MS", 18, FALSE, FALSE);

	// create a 2D scene for sprite rendering which will be rendered on the top of 3D
	sID2 = FyCreateScene(1);
	scene.ID(sID2);
	scene.SetSpriteWorldSize(800, 600);         // 2D scene size in pixels

	spID0 = scene.CreateObject(SPRITE);
	sp.ID(spID0);
	//showPicture(sp, "talk_mission.jpg", 780, 200 , 10, 10); //showPicture parameter : FnSprite ,imageName, size, position

	// set Hotkeys
	FyDefineHotKey(FY_ESCAPE, QuitGame, FALSE);  // escape for quiting the game
	FyDefineHotKey(FY_UP, Movement, FALSE);      // Up for moving forward
	FyDefineHotKey(FY_RIGHT, Movement, FALSE);   // Right for turning right
	FyDefineHotKey(FY_LEFT, Movement, FALSE);    // Left for turning left
	FyDefineHotKey(FY_DOWN, Movement, FALSE);
	FyDefineHotKey(FY_Q, Movement, FALSE);
	FyDefineHotKey(FY_W, Movement, FALSE);
	FyDefineHotKey(FY_E, Movement, FALSE);

	FyDefineHotKey(FY_A, Movement, FALSE);       // Turn left with camera rotation
	FyDefineHotKey(FY_D, Movement, FALSE);		 // Turn right with camera rotation
	FyDefineHotKey(FY_S, Movement, 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 timers, frame rate = 30 fps
	FyBindTimer(0, 30.0f, GameAI, TRUE);
	FyBindTimer(1, 30.0f, RenderIt, TRUE);

	// invoke the system
	FyInvokeFly(TRUE);
}
Пример #11
0
/*----------------------
perform the rendering
C.Wang 0720, 2006
-----------------------*/
void RenderIt(int skip)
{
	FnViewport vp;

	// render the whole scene
	vp.ID(vID);
	vp.Render3D(cID, TRUE, TRUE);

	// render the sprites
	vp.RenderSprites(sID2, FALSE, TRUE);  // no clear the background but clear the z buffer
	FySwapBuffers();

	// get camera's data
	FnCamera camera;
	camera.ID(cID);

	FnObject terrain;
	terrain.ID(tID);

	float pos[3], fDir[3], uDir[3];

	//-----------------HW2 added-----------------------//

	float actorPos[3], actorfDir[3], actoruDir[3];
	FnCharacter actor;
	actor.ID(actorID);

	actor.GetPosition(actorPos);
	actor.GetDirection(actorfDir, actoruDir);

	camera.GetPosition(pos);
	camera.GetDirection(fDir, uDir);

	// Initialze probing ray direction
	float dir[3], charDir[3];

	dir[0] = -fDir[0] / CAMERAPROBE;
	dir[1] = -fDir[1] / CAMERAPROBE;
	dir[2] = -1;

	charDir[0] = actorfDir[0] / ACTORPROBE;
	charDir[1] = actorfDir[1] / ACTORPROBE;
	charDir[2] = -1;

	if ((FyCheckHotKeyStatus(FY_A) || FyCheckHotKeyStatus(FY_D)) && dirCount % SMOOTHINESS == 0)
	{
		int tempHeight = pos[2];
		pos[2] = actorPos[2];
		int theDistance = FyDistance(pos, actorPos);

		pos[0] = actorPos[0] - theDistance * actorfDir[0];
		pos[1] = actorPos[1] - theDistance * actorfDir[1];
		pos[2] = tempHeight;

		fDir[0] = actorfDir[0];
		fDir[1] = actorfDir[1];

		uDir[0] = fDir[0] / abs(fDir[0] * fDir[1]);
		uDir[1] = fDir[1] / abs(fDir[0] * fDir[1]);
		uDir[2] = -abs(uDir[0] * fDir[0] + uDir[1] * fDir[1]) / fDir[2];
	}
	if ((FyCheckHotKeyStatus(FY_UP) || FyCheckHotKeyStatus(FY_S)) && dirCount % SMOOTHINESS == 0)
	{
		if (pos[2] > actorPos[2] + HEIGHTOFFSET)
		{
			pos[2] = actorPos[2];
			pos[2] = actorPos[2] + HEIGHTBOUND + HEIGHTOFFSET - FyDistance(pos, actorPos);

			fDir[0] = actorPos[0] - pos[0];
			fDir[1] = actorPos[1] - pos[1];
			fDir[2] = -pos[2];

			uDir[0] = fDir[0] / abs(fDir[0] * fDir[1]);
			uDir[1] = fDir[1] / abs(fDir[0] * fDir[1]);
			uDir[2] = -abs(uDir[0] * fDir[0] + uDir[1] * fDir[1]) / fDir[2];
		}
		else  // Reset the up direction 
		{
			pos[2] = actorPos[2] + HEIGHTOFFSET;
			fDir[0] = actorfDir[0];		fDir[1] = actorfDir[1];		fDir[2] = 0;
			uDir[0] = 0;	            uDir[1] = 0;	            uDir[2] = 1;
		}

		if (FyDistance(pos, actorPos) > LONGDIST)
		{
			pos[0] = actorPos[0] - LONGDIST * actorfDir[0];
			pos[1] = actorPos[1] - LONGDIST * actorfDir[1];
			pos[2] = actorPos[2] + HEIGHTOFFSET;

			fDir[0] = actorfDir[0];
			fDir[1] = actorfDir[1];
			fDir[2] = -0.0f;

			uDir[0] = actoruDir[0];
			uDir[1] = actoruDir[1];
			uDir[2] = actoruDir[2];

		}
	}

	if (FyCheckHotKeyStatus(FY_RIGHT) && dirCount % SMOOTHINESS == 0)
	{
		actorPos[2] += HEIGHTOFFSET;
		if (terrain.HitTest(actorPos, charDir) <= 0)
		{
			camera.MoveRight(-CAMERASPEED, FALSE, FALSE, 0, FALSE);
			camera.GetPosition(pos);
		}

		fDir[0] = actorPos[0] - pos[0];
		fDir[1] = actorPos[1] - pos[1];
		fDir[2] = 0.0f;
	}
	if (FyCheckHotKeyStatus(FY_LEFT) && dirCount % SMOOTHINESS == 0)
	{
		actorPos[2] += HEIGHTOFFSET;
		if (terrain.HitTest(actorPos, charDir) <= 0)
		{
			camera.MoveRight(CAMERASPEED, FALSE, FALSE, 0, FALSE);
			camera.GetPosition(pos);
		}

		fDir[0] = actorPos[0] - pos[0];
		fDir[1] = actorPos[1] - pos[1];
		fDir[2] = 0.0f;
	}
	if (FyCheckHotKeyStatus(FY_DOWN) && dirCount % SMOOTHINESS == 0)
	{
		if (FyDistance(pos, actorPos) < SHORTDIST)
		{
			if (terrain.HitTest(pos, dir) > 0)
			{
				pos[0] = actorPos[0] + SHORTDIST * actorfDir[0];
				pos[1] = actorPos[1] + SHORTDIST * actorfDir[1];
				pos[2] = actorPos[2] + HEIGHTOFFSET;

				fDir[0] = -actorfDir[0];
				fDir[1] = -actorfDir[1];
				fDir[2] = 0.0f;

				uDir[0] = actoruDir[0];
				uDir[1] = actoruDir[1];
				uDir[2] = actoruDir[2];
			}
			else
			{
				// go back and hit Obstacle : camera look down at the actor

				pos[2] = actorPos[2];
				pos[2] = actorPos[2] + HEIGHTBOUND + HEIGHTOFFSET - FyDistance(pos, actorPos);

				fDir[0] = actorPos[0] - pos[0];
				fDir[1] = actorPos[1] - pos[1];
				fDir[2] = -pos[2];

				uDir[0] = fDir[0] / abs(fDir[0] * fDir[1]);
				uDir[1] = fDir[1] / abs(fDir[0] * fDir[1]);
				uDir[2] = -abs(uDir[0] * fDir[0] + uDir[1] * fDir[1]) / fDir[2];
			}
		}
	}

	//-----------------HW2 end-------------------------//


	if (dirCount % SMOOTHINESS == 0)
	{
		camera.SetPosition(pos);
		camera.SetDirection(fDir, uDir);
	}
	// show frame rate
	static char string[128];
	if (frame == 0) {
		FyTimerReset(0);
	}

	if (frame / 10 * 10 == frame) {
		float curTime;

		curTime = FyTimerCheckTime(0);
		sprintf(string, "Fps: %6.2f", frame / curTime);
	}

	frame += skip;
	if (frame >= 1000) {
		frame = 0;
	}

	FnText text;
	text.ID(textID);

	text.Begin(vID);
	text.Write(string, 20, 20, 255, 0, 0);

	char posS[256], fDirS[256], uDirS[256], debug[256];
	sprintf(posS, "pos: %8.3f %8.3f %8.3f", pos[0], pos[1], pos[2]);
	sprintf(fDirS, "facing: %8.3f %8.3f %8.3f", fDir[0], fDir[1], fDir[2]);
	sprintf(uDirS, "up: %8.3f %8.3f %8.3f", uDir[0], uDir[1], uDir[2]);
	sprintf(debug, "debug: %d %d %d", LyubuID.level, LyubuID.exp_cur, LyubuID.blood_remain);

	text.Write(posS, 20, 35, 255, 255, 0);
	text.Write(fDirS, 20, 50, 255, 255, 0);
	text.Write(uDirS, 20, 65, 255, 255, 0);
	text.Write(debug, 20, 90, 255, 255, 0);

	text.End();

	// swap buffer
	FySwapBuffers();
}
Пример #12
0
/* ------------------
the main program
C.Wang 1010, 2014
-------------------*/
void FyMain(int argc, char **argv)
{
	// create a new world
	BOOL4 beOK = FyStartFlyWin32("NTU@2014 Homework #02 - Use Fly2", 0, 0, 1024, 768, FALSE);

	// setup the data searching paths
	FySetShaderPath("Data\\NTU6\\Shaders");
	FySetModelPath("Data\\NTU6\\Scenes");
	FySetTexturePath("Data\\NTU6\\Scenes\\Textures");
	FySetScenePath("Data\\NTU6\\Scenes");

	// create a viewport
	vID = FyCreateViewport(0, 0, 1024, 768);
	FnViewport vp;
	vp.ID(vID);

	// create a 3D scene
	sID = FyCreateScene(10);
	FnScene scene;
	scene.ID(sID);

	// load the scene
	scene.Load("gameScene02");
	scene.SetAmbientLights(1.0f, 1.0f, 1.0f, 0.6f, 0.6f, 0.6f);

	// load the terrain
	tID = scene.CreateObject(OBJECT);
	FnObject terrain;
	terrain.ID(tID);
	BOOL beOK1 = terrain.Load("terrain");
	terrain.Show(FALSE);

	// set terrain environment
	terrainRoomID = scene.CreateRoom(SIMPLE_ROOM, 10);
	FnRoom room;
	room.ID(terrainRoomID);
	room.AddObject(tID);

	// load the character
	FySetModelPath("Data\\NTU6\\Characters");
	FySetTexturePath("Data\\NTU6\\Characters");
	FySetCharacterPath("Data\\NTU6\\Characters");
	actorID = scene.LoadCharacter("Lyubu2");
	npc1ID = scene.LoadCharacter("Donzo2");
	npc2ID = scene.LoadCharacter("Robber02");

	// put the character on terrain
	float apos[3], cpos[3], fDir[3], uDir[3];
	FnCharacter actor, npc1, npc2;
	actor.ID(actorID);
	npc1.ID(npc1ID);
	npc2.ID(npc2ID);
	apos[0] = 3569.0f; apos[1] = -3208.0f; apos[2] = 1000.0f;
	fDir[0] = 1.0f; fDir[1] = 0.0f; fDir[2] = 0.0f;
	uDir[0] = 0.0f; uDir[1] = 0.0f; uDir[2] = 1.0f;
	actor.SetDirection(fDir, uDir);
	fDir[0] = -1.0f; fDir[1] = -1.0f;
	npc1.SetDirection(fDir, uDir);
	fDir[0] = 1.0f;
	npc2.SetDirection(fDir, uDir);

	actor.SetTerrainRoom(terrainRoomID, 10.0f);
	npc1.SetTerrainRoom(terrainRoomID, 10.0f);
	npc2.SetTerrainRoom(terrainRoomID, 10.0f);
	beOK = actor.PutOnTerrain(apos);
	apos[1] -= 150.0f;
	beOK = npc1.PutOnTerrain(apos);
	apos[1] -= 50.0f;
	beOK = npc2.PutOnTerrain(apos);

	// Get two character actions pre-defined at Lyubu2
	idleID = actor.GetBodyAction(NULL, "Idle");
	runID = actor.GetBodyAction(NULL, "Run");
	attackID = actor.GetBodyAction(NULL, "NormalAttack1");

	idle1ID = npc1.GetBodyAction(NULL, "Idle");
	damage1ID = npc1.GetBodyAction(NULL, "DamageL");
	die1ID = npc1.GetBodyAction(NULL, "Die");
	idle2ID = npc2.GetBodyAction(NULL, "CombatIdle");
	damage2ID = npc2.GetBodyAction(NULL, "Damage1");
	die2ID = npc2.GetBodyAction(NULL, "DEAD");

	// set the character to idle action
	curPoseID = idleID;
	actor.SetCurrentAction(NULL, 0, curPoseID);
	actor.Play(START, 0.0f, FALSE, TRUE);
	actor.TurnRight(90.0f);

	npc1.SetCurrentAction(NULL, 0, idle1ID);
	npc1.Play(START, 0.0f, FALSE, TRUE);
	npc2.SetCurrentAction(NULL, 0, idle2ID);
	npc2.Play(START, 0.0f, FALSE, TRUE);

	// translate the camera
	cID = scene.CreateObject(CAMERA);
	FnCamera camera;
	camera.ID(cID);
	camera.SetNearPlane(5.0f);
	camera.SetFarPlane(100000.0f);

	// set camera initial position and orientation
	actor.GetPosition(apos);
	//cpos[0] = 4315.783f; cpos[1] = -3199.686f; cpos[2] = 93.046f;
	fDir[0] = DIST; fDir[1] = 0.0f; fDir[2] = -HEIGHT;
	cpos[0] = apos[0] - fDir[0]; cpos[1] = apos[1] - fDir[1]; cpos[2] = apos[2] - fDir[2];
	float distance = sqrt(double((fDir[0])*(fDir[0]) + (fDir[1])*(fDir[1])));
	uDir[0] = -fDir[2] * fDir[0] / distance; uDir[1] = -fDir[2] * fDir[1] / distance; uDir[2] = distance;
	//fDir[0] = -0.983f; fDir[1] = -0.143f; fDir[2] = -0.119f;
	//uDir[0] = -0.116f; uDir[1] = -0.031f; uDir[2] = 0.993f;
	camera.SetPosition(cpos);
	camera.SetDirection(fDir, uDir);

	float mainLightPos[3] = { -4579.0, -714.0, 15530.0 };
	float mainLightFDir[3] = { 0.276, 0.0, -0.961 };
	float mainLightUDir[3] = { 0.961, 0.026, 0.276 };

	FnLight lgt;
	lgt.ID(scene.CreateObject(LIGHT));
	lgt.Translate(mainLightPos[0], mainLightPos[1], mainLightPos[2], REPLACE);
	lgt.SetDirection(mainLightFDir, mainLightUDir);
	lgt.SetLightType(PARALLEL_LIGHT);
	lgt.SetColor(1.0f, 1.0f, 1.0f);
	lgt.SetName("MainLight");
	lgt.SetIntensity(0.4f);

	// create a text object for displaying messages on screen
	textID = FyCreateText("Trebuchet MS", 18, FALSE, FALSE);

	// set Hotkeys
	FyDefineHotKey(FY_ESCAPE, QuitGame, FALSE);  // escape for quiting the game
	FyDefineHotKey(FY_UP, Movement, FALSE);      // Up for moving forward
	FyDefineHotKey(FY_DOWN, Movement, FALSE);    // Down for turning right
	FyDefineHotKey(FY_RIGHT, Movement, FALSE);   // Right for turning right
	FyDefineHotKey(FY_LEFT, Movement, FALSE);    // Left for turning left
	FyDefineHotKey('W', Movement, FALSE);        // Up for moving forward
	FyDefineHotKey('S', Movement, FALSE);        // Down for turning right
	FyDefineHotKey('D', Movement, FALSE);        // Right for turning right
	FyDefineHotKey('A', Movement, FALSE);        // Left for turning left
	FyDefineHotKey('J', Movement, 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 timers, frame rate = 30 fps
	FyBindTimer(0, 30.0f, GameAI, TRUE);
	FyBindTimer(1, 30.0f, RenderIt, TRUE);

	// invoke the system
	FyInvokeFly(TRUE);
}
Пример #13
0
/*------------------
the main program
C.Wang 1010, 2014
-------------------*/
void FyMain(int argc, char **argv)
{
	// create a new world
	BOOL4 beOK = FyStartFlyWin32("NTU@2014 Homework #01 - Use Fly2", 0, 0, 1024, 768, FALSE);

	// setup the data searching paths
	FySetShaderPath("Data\\NTU6\\Shaders");
	FySetModelPath("Data\\NTU6\\Scenes");
	FySetTexturePath("Data\\NTU6\\Scenes\\Textures");
	FySetScenePath("Data\\NTU6\\Scenes");

	// create a viewport
	vID = FyCreateViewport(0, 0, 1024, 768);
	FnViewport vp;
	vp.ID(vID);

	// create a 3D scene
	sID = FyCreateScene(10);
	FnScene scene;
	scene.ID(sID);

	// load the scene
	scene.Load("gameScene02");
	scene.SetAmbientLights(1.0f, 1.0f, 1.0f, 0.6f, 0.6f, 0.6f);

	// load the terrain
	tID = scene.CreateObject(OBJECT);
	FnObject terrain;
	terrain.ID(tID);
	BOOL beOK1 = terrain.Load("terrain");
	terrain.Show(FALSE);

	// set terrain environment
	terrainRoomID = scene.CreateRoom(SIMPLE_ROOM, 10);
	FnRoom room;
	room.ID(terrainRoomID);
	room.AddObject(tID);

	// load the character
	FySetModelPath("Data\\NTU6\\Characters");
	FySetTexturePath("Data\\NTU6\\Characters");
	FySetCharacterPath("Data\\NTU6\\Characters");
	actorID = scene.LoadCharacter("Lyubu2");

	// put the character on terrain
	float pos[3], fDir[3], uDir[3];
	FnCharacter actor;
	actor.ID(actorID);
	pos[0] = 3569.0f; pos[1] = -3208.0f; pos[2] = 1000.0f;
	fDir[0] = 1.0f; fDir[1] = -1.0f; fDir[2] = 0.0f;
	uDir[0] = 0.0f; uDir[1] = 0.0f; uDir[2] = 1.0f;
	actor.SetDirection(fDir, uDir);

	actor.SetTerrainRoom(terrainRoomID, 10.0f);
	beOK = actor.PutOnTerrain(pos);

	// Get two character actions pre-defined at Lyubu2
	idleID = actor.GetBodyAction(NULL, "Idle");
	runID = actor.GetBodyAction(NULL, "Run");

	// set the character to idle action
	curPoseID = idleID;
	actor.SetCurrentAction(NULL, 0, curPoseID);
	actor.Play(START, 0.0f, FALSE, TRUE);
	actor.TurnRight(90.0f);

	// translate the camera
	cID = scene.CreateObject(CAMERA);
	FnCamera camera;
	camera.ID(cID);
	camera.SetNearPlane(5.0f);
	camera.SetFarPlane(100000.0f);

	// set camera initial position and orientation
	pos[0] = 4069.0f; pos[1] = -3208.0f; pos[2] = 93.046f;
	fDir[0] = -500.0f; fDir[1] = -0.0f; fDir[2] = -0.0f;
	uDir[0] = -0.116f; uDir[1] = -0.031f; uDir[2] = 0.993f;
	camera.SetPosition(pos);
	camera.SetDirection(fDir, uDir);

	float mainLightPos[3] = { -4579.0, -714.0, 15530.0 };
	float mainLightFDir[3] = { 0.276, 0.0, -0.961 };
	float mainLightUDir[3] = { 0.961, 0.026, 0.276 };

	FnLight lgt;
	lgt.ID(scene.CreateObject(LIGHT));
	lgt.Translate(mainLightPos[0], mainLightPos[1], mainLightPos[2], REPLACE);
	lgt.SetDirection(mainLightFDir, mainLightUDir);
	lgt.SetLightType(PARALLEL_LIGHT);
	lgt.SetColor(1.0f, 1.0f, 1.0f);
	lgt.SetName("MainLight");
	lgt.SetIntensity(0.4f);

	// create a text object for displaying messages on screen
	textID = FyCreateText("Trebuchet MS", 18, FALSE, FALSE);

	// set Hotkeys
	FyDefineHotKey(FY_ESCAPE, QuitGame, FALSE);  // escape for quiting the game
	FyDefineHotKey(FY_UP, Movement, FALSE);      // Up for moving forward
	FyDefineHotKey(FY_RIGHT, Movement, FALSE);   // Right for turning right
	FyDefineHotKey(FY_LEFT, Movement, FALSE);    // Left for turning left

	// define some mouse functions
	if (!IsCameraFollow)
	{
		FyBindMouseFunction(LEFT_MOUSE, InitPivot, PivotCam, NULL, NULL);
		FyBindMouseFunction(MIDDLE_MOUSE, InitZoom, ZoomCam, NULL, NULL);
		FyBindMouseFunction(RIGHT_MOUSE, InitMove, MoveCam, NULL, NULL);
	}
	else
	{
		FyBindMouseFunction(LEFT_MOUSE, InitZoom2, ZoomCam2, NULL, NULL);
		FyBindMouseFunction(RIGHT_MOUSE, NULL, RotateCam, NULL, NULL);
	}

	// bind timers, frame rate = 30 fps
	FyBindTimer(0, 30.0f, GameAI, TRUE);
	FyBindTimer(1, 30.0f, RenderIt, TRUE);

	// invoke the system
	FyInvokeFly(TRUE);
}