当前位置: 首页>>代码示例>>C++>>正文


C++ FnObject::HitTest方法代码示例

本文整理汇总了C++中FnObject::HitTest方法的典型用法代码示例。如果您正苦于以下问题:C++ FnObject::HitTest方法的具体用法?C++ FnObject::HitTest怎么用?C++ FnObject::HitTest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FnObject的用法示例。


在下文中一共展示了FnObject::HitTest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GameAI


//.........这里部分代码省略.........
	genSpot[1][0] = 729.288;
	genSpot[1][1] = -2472.88;

	// Bad guys generator
	for (int i = 0; i < NUM_OF_GENERATOR; i++)
	{
		if (!InArea(origin, genSpot[i], generator[i].range))
		{
			generator[i].in = 0;
			generator[i].double_in = 0;
		}
		if (generator[i].in && InArea(origin, genSpot[i], generator[i].range))
		{
			generator[i].double_in = 1;
		}
		if (InArea(origin, genSpot[i], generator[i].range))
		{
			generator[i].in = 1;
		}

		if (generator[i].in == 1 && generator[i].double_in == 0)
			generator[i].produce(origin, actoruDir, scene, i, NUM_OF_GENERATOR);
	}

	origin[2] = origin[2] + HEIGHTOFFSET; // need an offset to probe the hit
	dir[0] = actorfDir[0] / ACTORPROBE;
	dir[1] = actorfDir[1] / ACTORPROBE;
	dir[2] = -1.0f;

	//////////////////////////////////////////
	// Homework #01 part 1
	//////////////////////////////////////////

	if (dirCount % SMOOTHINESS != 0)
	{
		if ((dirCount + SMOOTHINESS) % SMOOTHINESS < SMOOTHINESS / 2 + 1)
		{
			dirCount--;
			actor.TurnRight(360 / SMOOTHINESS);
		}
		else
		{
			dirCount++;
			actor.TurnRight(360 - 360 / SMOOTHINESS);
		}
	}

	if ((FyCheckHotKeyStatus(FY_UP) || FyCheckHotKeyStatus(FY_S)) && dirCount % SMOOTHINESS == 0)
	{
		actor.SetDirection(camerafDir, camerauDir);
		if (terrain.HitTest(origin, dir) > 0)
			actor.MoveForward(RUNSPEED, FALSE, FALSE, 0, FALSE);
	}
	if (FyCheckHotKeyStatus(FY_D) && dirCount % SMOOTHINESS == 0)
		actor.TurnRight(TURNSPEED);
	if (FyCheckHotKeyStatus(FY_A) && dirCount % SMOOTHINESS == 0)
		actor.TurnRight(360 - TURNSPEED);
	else if (FyCheckHotKeyStatus(FY_RIGHT) && dirCount % SMOOTHINESS == 0)
	{
		actorfDir[0] = camerafDir[1];
		actorfDir[1] = -camerafDir[0];
		actor.SetDirection(actorfDir, actoruDir);
		if (terrain.HitTest(origin, dir) > 0)
		{
			//actor.MoveRight(CALLIBRATION, FALSE, FALSE, 0, FALSE); 
			actor.MoveForward(RUNSPEED / 2, FALSE, FALSE, 0, FALSE);
		}
	}
	else if (FyCheckHotKeyStatus(FY_LEFT) && dirCount % SMOOTHINESS == 0)
	{
		actorfDir[0] = -camerafDir[1];
		actorfDir[1] = camerafDir[0];
		actor.SetDirection(actorfDir, actoruDir);
		if (terrain.HitTest(origin, dir) > 0)
		{
			//actor.MoveRight(CALLIBRATION, FALSE, FALSE, 0, FALSE); 
			actor.MoveForward(RUNSPEED / 2, FALSE, FALSE, 0, FALSE);
		}
	}
	else if (FyCheckHotKeyStatus(FY_DOWN) && dirCount % SMOOTHINESS == 0)
	{
		actor.SetDirection(camerafDir, camerauDir);
		actor.TurnRight(180.0f);
		if (terrain.HitTest(origin, dir) > 0 && camVertical > MAXCAMANGLE)
			actor.MoveForward(RUNSPEED, FALSE, FALSE, 0, FALSE);
	}


	//Tang: FX
	if (gFXID != FAILED_ID) {
		FnGameFXSystem gxS(gFXID);
		BOOL4 beOK = gxS.Play((float)skip, ONCE);
		if (!beOK) {
			FnScene scene(sID);
			scene.DeleteGameFXSystem(gFXID);
			gFXID = FAILED_ID;
		}
	}
	//Tang
}
开发者ID:dragonkiss81,项目名称:Fly2_API,代码行数:101,代码来源:hw01_Tang.cpp

示例2: RenderIt


//.........这里部分代码省略.........
			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;
开发者ID:dragonkiss81,项目名称:Fly2_API,代码行数:66,代码来源:hw01_Tang.cpp

示例3: GameAI

/* ------------------------------------------------------------ -
30fps timer callback in fixed frame rate for major game loop
-------------------------------------------------------------- */
void GameAI(int skip)
{
	FnCharacter actor, npc1, npc2;

	// play character pose
	actor.ID(actorID);
	actor.Play(LOOP, (float)skip, FALSE, TRUE);

	npc1.ID(npc1ID);
	if (HP1>0 || (frame - framedamage1 + 1000) % 1000 < dietime1)
		npc1.Play(LOOP, (float)skip, FALSE, TRUE);
	npc2.ID(npc2ID);
	if (HP2>0 || (frame - framedamage2 + 1000) % 1000 < dietime2)
		npc2.Play(LOOP, (float)skip, FALSE, TRUE);
	if ((frame - frameattack + 1000) % 1000 == attacktime)
		actor.SetCurrentAction(NULL, 0, curPoseID, 5.0f);
	if (HP1 > 0)
	{
		if ((frame - framedamage1 + 1000) % 1000 == damagetime1)
			npc1.SetCurrentAction(NULL, 0, idle1ID, 0.0f);
		else if (frame == framedamage1)
			npc1.SetCurrentAction(NULL, 0, damage1ID, 0.0f);
	}
	else if (frame == framedamage1)
	{
		npc1.SetCurrentAction(NULL, 0, die1ID, 0.0f);
	}
	if (HP2 > 0)
	{
		if ((frame - framedamage2 + 1000) % 1000 == damagetime2)
			npc2.SetCurrentAction(NULL, 0, idle2ID, 0.0f);
		else if (frame == framedamage2)
			npc2.SetCurrentAction(NULL, 0, damage2ID, 0.0f);
	}
	else if (frame == framedamage2)
	{
		npc2.SetCurrentAction(NULL, 0, die2ID, 0.0f);
	}

	FnCamera camera;
	camera.ID(cID);

	FnObject terrain;
	terrain.ID(tID);

	float fDir[3], uDir[3] = { 0, 0, 1 }, cpos[3], apos[3], distance, height, length;
	camera.GetPosition(cpos);
	actor.GetPosition(apos);
	fDir[0] = apos[0] - cpos[0]; fDir[1] = apos[1] - cpos[1]; fDir[2] = apos[2] - cpos[2];
	distance = sqrt(double((fDir[0])*(fDir[0]) + (fDir[1])*(fDir[1])));
	height = -fDir[2];
	length = sqrt(double(distance*distance + height*height));
	uDir[0] = -fDir[2] * fDir[0] / distance; uDir[1] = -fDir[2] * fDir[1] / distance; uDir[2] = distance;
	camera.SetDirection(fDir, uDir);
	uDir[0] = 0; uDir[1] = 0; uDir[2] = 1;
	bool up = FyCheckHotKeyStatus(FY_UP) || FyCheckHotKeyStatus('W'),
		down = FyCheckHotKeyStatus(FY_DOWN) || FyCheckHotKeyStatus('S'),
		left = FyCheckHotKeyStatus(FY_LEFT) || FyCheckHotKeyStatus('A'),
		right = FyCheckHotKeyStatus(FY_RIGHT) || FyCheckHotKeyStatus('D'),
		act = (frame - frameattack + 1000) % 1000 >= attacktime;
	if (act)
	{
		if (up&&!down)
		{
			actor.SetDirection(fDir, uDir);
			float norm = sqrt(double((fDir[0])*(fDir[0]) + (fDir[1])*(fDir[1])));

			actor.MoveForward(speed, TRUE);
			actor.GetPosition(apos);
			cpos[0] = apos[0] - LENGTH*fDir[0] / norm;
			cpos[1] = apos[1] - LENGTH*fDir[1] / norm;
			cpos[2] = apos[2] + HEIGHT;
			float dir[3] = { cpos[0] - apos[0], cpos[1] - apos[1], 0 }, result[3];
			if (terrain.HitTest(apos, dir, result) > 0)
			{
				float line[3] = { result[0] - apos[0], result[1] - apos[1], result[2] - apos[2] };
				if (line[0] * line[0] + line[1] * line[1]<LENGTH*LENGTH)
				{
					cpos[0] = result[0];
					cpos[1] = result[1];
					cpos[2] = apos[2] + sqrt(double(LENGTH*LENGTH + HEIGHT*HEIGHT - (line[0] * line[0] + line[1] * line[1])));
				}
			}
			camera.SetPosition(cpos);
		}
		if (down&&!up)
		{
			float bDir[3] = { -fDir[0], -fDir[1], -fDir[2] };
			actor.SetDirection(bDir, uDir);
			float norm = sqrt(double((bDir[0])*(bDir[0]) + (bDir[1])*(bDir[1])));

			actor.MoveForward(speed, TRUE);
			actor.GetPosition(apos);
			cpos[0] = apos[0] - LENGTH*fDir[0] / norm;
			cpos[1] = apos[1] - LENGTH*fDir[1] / norm;
			cpos[2] = apos[2] + HEIGHT;
			float dir[3] = { cpos[0] - apos[0], cpos[1] - apos[1], 0 }, result[3];
//.........这里部分代码省略.........
开发者ID:raichu2652,项目名称:GameProgramming2015,代码行数:101,代码来源:Hello.cpp


注:本文中的FnObject::HitTest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。