本文整理汇总了C++中ISceneNode::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ ISceneNode::getPosition方法的具体用法?C++ ISceneNode::getPosition怎么用?C++ ISceneNode::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISceneNode
的用法示例。
在下文中一共展示了ISceneNode::getPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getArrowPrototype
ISceneNode* ArrowPrototypeFactory::getArrowPrototype(unsigned char type,
float offset) {
ISceneNode* newArrow = prototypes[type]->clone(parent, smgr);
newArrow->setVisible(true);
//if (offest != 0.0) {
newArrow->setPosition(
vector3df(newArrow->getPosition().X, ARROW_HEIGHT - offset,
newArrow->getPosition().Z));
// printf ("offset is %f. \n", offset);
//}
return newArrow;
}
示例2: isNeedMoveToStartPos
//-----------------------------------------------------------------------
Bool CCSEntityLineMoveAcion::isNeedMoveToStartPos()
{
if ( !mEntity )
return false;
if ( !mEntity->getEntity() )
return false ;
ISceneNode* sceneNode = mEntity->getEntity()->getSceneNode();
if( !sceneNode )
{
return false ;
}
Vec3 currPos;
sceneNode->getPosition(currPos);
Vec3 ec = mEndPos - currPos;
Vec3 es = mEndPos - mStartPos;
ec.y = 0;
es.y = 0;
Flt currDis = ec.length();
Flt dis = es.length();
if ( currDis > dis )
return true;
return false;
}
示例3: render
void LayerNode::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
ISceneNode* cameraNode = SceneManager->getActiveCamera();
core::matrix4 mxTrans = cameraNode->getAbsoluteTransformation();
core::vector3df vCamPos = cameraNode->getPosition();
core::vector3df vCamScale = cameraNode->getScale();
core::vector3df vCamRot = cameraNode->getRotation();
//Zoom factor: for Factor=0, zoom = 1; for Factor=1, zoom = vCamScale;
vCamScale.X = 1 - ( (1 - vCamScale.X) * m_paraxZoomFactor );
vCamScale.Y = 1 - ( (1 - vCamScale.Y) * m_paraxZoomFactor );
core::vector3df vCamPos2 = cameraNode->getPosition();
// Apply Offset
core::vector3df vOffset(m_offsetX, m_offsetY, 0);
// Apply parallax factor
vCamPos2.X *= m_paraxFactorX;
vCamPos2.Y *= m_paraxFactorY;
mxTrans =
core::matrix4().setTranslation(vCamPos)*
core::matrix4().setScale(vCamScale)*
core::matrix4().setTranslation(-vCamPos)*
core::matrix4().setRotationDegrees(vCamRot)*
core::matrix4().setTranslation(-vCamPos)* // remove camera offset because is applied automatically later by Irrlicht
core::matrix4().setTranslation(vOffset)* // apply offset without parallax factor to make easy to adjust layer
core::matrix4().setTranslation(vCamPos2) // then apply modified by parallax factor camera position
;
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, mxTrans*AbsoluteTransformation);
Drawing::draw2DImage( driver, m_texture, core::recti( 0, 0, m_width, m_height), core::IdentityMatrix, true, video::SColor(255, 255, 255, 255));
}
示例4: checkForCapture
void ActionManager::checkForCapture(){
//if one of the enemies gets the destination you lose
for(unsigned int i = 0; i < craftPool.size(); i++)
if(craftPool[i]->isMoveFinished()){
craftPool[i]->remove();//remove it from scene
delete craftPool[i];
craftPool.erase(i); //remove it from pool
ISceneNode* fighter = device->getSceneManager()->getSceneNodeFromId(NEWGAME_ELEMENT::NEWGAME_FIGHTER);
fighter->setVisible(false);
createExplosion(fighter->getPosition(), 12);
gameOver();
}
}
示例5: Java_zte_irrlib_scene_SceneNode_nativeUpdatePosition
int Java_zte_irrlib_scene_SceneNode_nativeUpdatePosition(
JNIEnv* env, jobject defaultObj, jobject jvec, jboolean isAbsolute, jint Id)
{
ISceneNode* node = smgr->getSceneNodeFromId(Id);
if (!node)
{
WARN_NODE_NOT_FOUND(Id, UpdatePosition);
return -1;
}
if (isAbsolute)
{
node->updateAbsolutePosition();
utils->setVector3dFromvector3df(env, jvec, node->getAbsolutePosition());
}
else utils->setVector3dFromvector3df(env, jvec, node->getPosition());
return 0;
}
示例6: collisionProjectileVsCraft
void ActionManager::collisionProjectileVsCraft(){
//check for collisions between crafts and projectiles
for(unsigned int i = 0; i < craftPool.size(); i++)
for(unsigned int j = 0; j < projectilePool.size(); j++)
if(collisionCheck(craftPool[i]->getSceneNode(), projectilePool[j]->getAnimatedMeshSceneNode())){
ISceneNode* craftNode = 0;
if(craftPool[i]->getSceneNode()->getID() < ENEMY_CRAFT_THRESHOLD) //define type of craft whether it is enemy or not
craftNode = craftPool[i]->getSceneNode();
ISceneNode* projectileNode = (ISceneNode*)projectilePool[j]->getAnimatedMeshSceneNode();
if(craftNode && projectileNode){
createExplosion(craftNode->getPosition(), 12);
craftPool[i]->remove(); //remove craft
delete craftPool[i]; //release its memory
craftPool.erase(i); //remove from active pool
projectilePool[j]->remove(); //remove projectile
delete projectilePool[j];
projectilePool.erase(j);
updateScore(10);
}
}
}
示例7: exportElements
// ----------------------------------------------------------------------------
void Track::exportElements(std::ofstream& stream, bool obj)
{
ISceneManager* sm = Editor::getEditor()->getSceneManager();
ISceneNode* node;
stringc name;
int i = 1;
while ((node = sm->getSceneNodeFromId(MAGIC_NUMBER + i)))
{
name = node->getName();
vector3df pos, rot, sca;
if (node->isVisible() && name != "banana" && name != "item"
&& name != "small-nitro" && name != "big-nitro"
&& (name.equalsn("obj/", 4) == obj))
{
pos = node->getPosition();
rot = node->getRotation();
sca = node->getScale();
if (name.equalsn("obj/", 4))
{
stream << " <static-object model=\"" << Editor::toRelative(name).c_str();
copyObj(name);
ITexture* tex;
for (int j = 0; (tex = node->getMaterial(0).getTexture(j)); j++)
copyObj(stringc("obj/") + Editor::toRelative(tex->getName()));
} // export as static-object
else
{
stream << " <library name=\"" << Editor::getLib(node->getName()).c_str();
} // export as library
stream << "\" xyz=\"";
stream << pos.X << " " << pos.Y << " " << pos.Z << "\" hpr=\"";
stream << rot.X << " " << rot.Y << " " << rot.Z << "\" scale=\"";
stream << sca.X << " " << sca.Y << " " << sca.Z << "\"/>\n";
}
i++;
}
} // exportElements
示例8: collisionCraftVsCraft
void ActionManager::collisionCraftVsCraft(){
for(unsigned int i = 0; i < craftPool.size(); i++)
for(unsigned int j = i + 1; j < craftPool.size(); j++)
if(collisionCheck(craftPool[i]->getSceneNode(), craftPool[j]->getSceneNode())){
ISceneNode* fighter;
ISceneNode* craft;
bool isFighter = false;
if(craftPool[i]->getSceneNode()->getID() == NEWGAME_ELEMENT::NEWGAME_FIGHTER){
fighter = craftPool[i]->getSceneNode();
craft = craftPool[j]->getSceneNode();
isFighter = true;
} else if (craftPool[j]->getSceneNode()->getID() == NEWGAME_ELEMENT::NEWGAME_FIGHTER){
fighter = craftPool[j]->getSceneNode();
craft = craftPool[i]->getSceneNode();
isFighter = true;
}
if(isFighter){
craft->setVisible(false);
fighter->setVisible(false);
createExplosion(fighter->getPosition(), 12);
gameOver();
}
}
}
示例9: main
//.........这里部分代码省略.........
EnemyManager.GetEntity(i)->X = EnemyManager.GetEntity(i)->AI_DestinationX;
EnemyManager.GetEntity(i)->Y = EnemyManager.GetEntity(i)->AI_DestinationY; //new path will be created
EnemyManager.GetEntity(i)->Position();
EnemyManager.GetEntity(i)->AI_State = AI::Patrol;
EnemyManager.GetEntity(i)->isAI = true;
EntityList.push_back(EnemyManager.GetEntity(i));
}
bool rkf = false;
//Game loop
while (device->run())
{
//Create a list of all entities
EntityList.clear();
vector<Entity*> EnemyList( EnemyManager.GetEntityList() );
EntityList.insert( EntityList.end(), EnemyList.begin(), EnemyList.end() );
/* * * * * * * * * * * * * * */
/* Player switching module */
/* * * * * * * * * * * * * * */
for (int i = 0; i < PlayerManager.Size; i++)
PlayerManager.GetEntity(i)->CheckIfDead();
PlayerManager.ManageCharacterSwitching(Receiver);
/* * * * * * * * * * * */
/* Pathfinding module */
/* * * * * * * * * * * */
PlayerManager.GetCurrentEntity()->UpdatePathDisplayTimer();
if (Receiver.MouseState.LeftButtonDown && PlayerManager.GetCurrentEntity()->NewPathDisplayTimer < 1)
PlayerManager.GetCurrentEntity()->CreatePathToDestination(EntityList,smgr,Receiver,Cursor->getPosition(),dimension2d<s32>(MR.XSize,MR.YSize),MG.Convert());
/* * * * * * * * * * * * * */
/* Update position module */
/* * * * * * * * * * * * * */
PlayerManager.GetCurrentEntity()->Position();
/* * * * * * * * * * * */
/* Follow path module */
/* * * * * * * * * * * */
if (Receiver.IsKeyDown(Receiver.KeyConfig.FOLLOW_PATH))
PlayerManager.GetCurrentEntity()->FollowPath(EntityList);
/* * * * * * * * * */
/* End turn module */
/* * * * * * * * * */
if (Receiver.IsKeyDown(Receiver.KeyConfig.END_TURN) && !rkf)
{
rkf = true;
PlayerManager.EndTurn();
EnemyManager.AI_StartTurn(EntityList, PlayerManager, smgr, Receiver, irr::core::dimension2d<s32>(MR.XSize,MR.YSize), MG.Convert(), MR.MetaTriangleSelector, MR.MetaCoverTriangleSelector);
PlayerManager.StartTurn();
}
else if (!Receiver.IsKeyDown(Receiver.KeyConfig.END_TURN))
rkf = false;
/* * * * * * * * */
/* Cursor module */
/* * * * * * * * */
Cursor->setPosition( vftovi(MouseTo3D( Receiver, MR.CollisionManager, MR.TriSelector)) );
/* * * * * * * * */
/* Camera module */
示例10: checkBBoxIntersection
static bool checkBBoxIntersection(IrrlichtDevice * device,
ISceneManager * smgr)
{
video::IVideoDriver* driver = device->getVideoDriver();
// add camera
scene::ICameraSceneNode* camera = smgr->addCameraSceneNode();
camera->setPosition(core::vector3df(30, 30, 30));
camera->setTarget(core::vector3df(8.f, 8.f, 8.f));
camera->setID(0);
// add a cube to pick
scene::ISceneNode* cube = smgr->addCubeSceneNode(30, 0, -1, core::vector3df(0,0,0),core::vector3df(30,40,50));
bool result=true;
for (u32 round=0; round<2; ++round)
{
driver->beginScene(true, true, video::SColor(100, 50, 50, 100));
smgr->drawAll();
driver->endScene();
core::matrix4 invMat = cube->getAbsoluteTransformation();
invMat.makeInverse();
s32 hits=0;
u32 start = device->getTimer()->getRealTime();
for (u32 i=10; i<150; ++i)
{
for (u32 j=10; j<110; ++j)
{
const core::position2di pos(i, j);
// get the line used for picking
core::line3df ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(pos, camera);
invMat.transformVect(ray.start);
invMat.transformVect(ray.end);
hits += (cube->getBoundingBox().intersectsWithLine(ray)?1:0);
}
}
u32 duration = device->getTimer()->getRealTime()-start;
logTestString("bbox intersection checks %d hits (of 14000).\n", hits);
hits = -hits;
start = device->getTimer()->getRealTime();
for (u32 i=10; i<150; ++i)
{
for (u32 j=10; j<110; ++j)
{
const core::position2di pos(i, j);
// get the line used for picking
core::line3df ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(pos, camera);
invMat.transformVect(ray.start);
invMat.transformVect(ray.end);
hits += (IntersectBox(ray.start, (ray.end-ray.start).normalize(), cube->getBoundingBox())?1:0);
}
}
u32 duration2 = device->getTimer()->getRealTime()-start;
logTestString("bbox intersection resulted in %d misses at a speed of %d (old) compared to %d (new).\n", abs(hits), duration, duration2);
if (duration>(duration2*1.2f))
logTestString("Consider replacement of bbox intersection test.\n");
result &= (hits==0);
assert(result);
// second round without any hits, so check opposite direction
camera->setTarget(core::vector3df(80.f, 80.f, 80.f));
}
ISceneNode* node = smgr->addSphereSceneNode(5.f, 16, 0, -1, core::vector3df(0, 0, 1), core::vector3df(), core::vector3df(0.3f, 0.3f, 0.3f));
cube->remove();
cube = smgr->addCubeSceneNode(10.f, 0, -1, core::vector3df(0, 6.5f, 1), core::vector3df(), core::vector3df(10, 0.1f, 1.f));
camera->setPosition(core::vector3df(0, 0, 10));
camera->setTarget(core::vector3df());
u32 count=0;
for (u32 i=0; i<30; ++i)
{
driver->beginScene(true, true, video::SColor(100, 50, 50, 100));
smgr->drawAll();
driver->endScene();
count += node->getTransformedBoundingBox().intersectsWithBox(cube->getTransformedBoundingBox())?1:0;
node->setPosition(node->getPosition()+core::vector3df(.5f,.5f,0));
if (i==8 && count != 0)
result=false;
if (i==17 && count != 9)
result=false;
}
if (count != 9)
result=false;
smgr->clear();
return result;
}
示例11: build
//.........这里部分代码省略.........
mat << " <material name=\"splatt.png\" graphical-effect=\"splatting\"";
SMaterial m = m_terrain->getMaterial(0);
for (int i = 1; i < 5; i++)
{
mat << " splatting-texture-" << i << "=\"";
mat << Editor::toRelative(m.getTexture(i+1)->getName()).c_str();
mat << "\"";
}
mat << "/>\n";
if (m_gravity_road)
{
for (u32 i = 1; i < m_roads.size(); i++)
{
stringc tex = m_roads[i]->getTexName();
if (tex.size()>0)
{
mat << " <material name=\"";
mat << tex.c_str();
mat << "\" has-gravity=\"yes\" />\n";
}
} // roads
} // gravity road mode
mat <<"</materials>\n";
mat.close();
stringw track;
track += "<track name = \"";
track += m_track_name + L"\"\n";
track += " version = \"5\"\n";
track += " groups = \"made-by-STK-TE\"\n";
track += " designer = \"";
track += m_designer + "\"\n";
track += " music = \"";
track += m_music.c_str();
track += "\"\n";
track += " screenshot = \"screenshot.jpg\"\n";
track += " smooth-normals = \"true\"\n";
track += " reverse = \"Y\"\n>\n";
track += "</track>\n";
PHYSFS_uint64 len = 4 * track.size();
char* dst = new char[len];
#ifdef _WIN32
PHYSFS_utf8FromUcs2((PHYSFS_uint16*)track.c_str(),dst,len);
#else
PHYSFS_utf8FromUcs4((PHYSFS_uint32*)track.c_str(), dst, len);
#endif
FILE* f;
f = fopen((p + "/track.xml").c_str(), "wb");
fwrite(dst, sizeof(char), strlen(dst), f);
fclose(f);
delete[] dst;
std::ofstream scene;
scene.open((p + "/scene.xml").c_str());
scene << "<scene>\n";
scene << " <track model=\"track.b3d\" x=\"0\" y=\"0\" z=\"0\">\n";
exportElements(scene, true);
scene << " </track>\n";
exportElements(scene, false);
ISceneManager* sm = Editor::getEditor()->getSceneManager();
ISceneNode* node;
int i = 1;
stringc name;
while ((node = sm->getSceneNodeFromId(MAGIC_NUMBER + i)))
{
name = node->getName();
vector3df pos;
if (node->isVisible() && (name == "banana" || name == "item"
|| name == "small-nitro" || name == "big-nitro"))
{
pos = node->getPosition();
scene << " <" << name.c_str() << " x=\"" << pos.X << "\" y=\"" << pos.Y
<< "\" z=\"" << pos.Z << "\" />\n";
}
i++;
}
scene << Viewport::get()->getSky()->getXmlString().c_str();
Viewport::get()->printCheckLine(&scene);
scene << " <default-start karts-per-row = \"3\"\n";
scene << " forwards-distance =\"1.50\"\n";
scene << " sidewards-distance=\"3.00\"\n";
scene << " upwards-distance =\"0.10\"/>\n";
scene << "</scene>\n";
scene.close();
MsgWndw::get()->showMsg(_("Track exported!"));
} // build
示例12: save
// ----------------------------------------------------------------------------
void Track::save()
{
FILE* pFile = 0;
path p = Editor::getEditor()->getMapsPath() + "/" + m_file_name.c_str();
pFile = fopen(p.c_str(), "wb");
if (!pFile)
{
MsgWndw::get()->showMsg(_("Save failed: file could not be created!\n"));
return;
}
// SIGN
u64 sign = TOP_SECRET_SIGNATURE_NUMBER;
fwrite(&sign, sizeof(u64), 1, pFile);
// TRACK NAME
u8 size = m_track_name.size() + 1;
fwrite(&size, sizeof(u8), 1, pFile);
fwrite(m_track_name.c_str(), sizeof(wchar_t), size, pFile);
// DESIGNER NAME
size = m_designer.size() + 1;
fwrite(&size, sizeof(u8), 1, pFile);
fwrite(m_designer.c_str(), sizeof(wchar_t), size, pFile);
// FILE NAME
size = m_file_name.size() + 1;
fwrite(&size, sizeof(u8), 1, pFile);
fwrite(m_file_name.c_str(), sizeof(c8), size, pFile);
// MUSIC
size = m_music.size() + 1;
fwrite(&size, sizeof(u8), 1, pFile);
fwrite(m_music.c_str(), sizeof(c8), size, pFile);
// TERRAIN
m_terrain->save(pFile);
// SKY
Viewport::get()->getSky()->save(pFile);
// GRAVITY ROAD FLAG
fwrite(&m_gravity_road, sizeof(bool), 1, pFile);
// ROADS
size = m_roads.size();
fwrite(&size, sizeof(u8), 1, pFile);
IRoad* r;
for (u8 i = 0; i < size; i++)
{
r = m_roads[i];
r->save(pFile);
}
//CHECKLINES
Viewport::get()->saveCheckLines(pFile);
// OBJECTS
ISceneManager* sm = Editor::getEditor()->getSceneManager();
ISceneNode* node;
u32 num = Viewport::getLastEntityID() - MAGIC_NUMBER;
u32 vnum = 0;
for (u32 i = 0; i < num; i++)
{
node = sm->getSceneNodeFromId(MAGIC_NUMBER + i + 1);
if (node && node->isVisible()) vnum++;
}
fwrite(&vnum, sizeof(u32), 1, pFile);
for (u32 i = 0; i < num; i++)
{
node = sm->getSceneNodeFromId(MAGIC_NUMBER + i + 1);
assert(node);
if (node->isVisible())
{
fwrite(&node->getPosition(), sizeof(vector3df), 1, pFile);
fwrite(&node->getRotation(), sizeof(vector3df), 1, pFile);
fwrite(&node->getScale(), sizeof(vector3df), 1, pFile);
u8 size = strlen(node->getName()) + 1;
fwrite(&size, sizeof(u8), 1, pFile);
fwrite(node->getName(), sizeof(c8), size, pFile);
}
}
fclose(pFile);
Editor::getEditor()->addToRecentlyOpenedList(m_file_name);
MsgWndw::get()->showMsg(_("Track saved!\n"));
} // save
示例13: updateSelector
// (private)
// gets a highlighted scene node if there is one
void GameInstance::updateSelector(){
// if a highlighted node exists, deselect. If it is still
// selected this frame, it will be re-selected below.
if (highlightedSceneNode) {
highlightedSceneNode = 0;
}
// get a pointer to whichever scene node is targetted (if any)
ISceneNode * selected = selector->getTarget();
if (selected){
highlightedSceneNode = selected;
}
// If no vehicle is currently being carried and the right mouse button is
// pressed, check if we're currently targetting (highlighting) a vehicle.
// If so, then pick it up.
if (!carriedVehicle && ((BorbiesEventReceiver *)receiver)->isRightMouseDown()){
VehicleInstance * vehicle =
(VehicleInstance *)(vehicles->getObject(highlightedSceneNode));
if(vehicle) { // if vehicle was in fact selected, pick it up
carriedVehicle = vehicle; // VehicleInstance* (carriedVehicle)
carriedVehicle->stop(); // remove all animators from the vehicle
objCarry->pickUp(highlightedSceneNode); // ISceneNode* (highlighted)
// remove the vehicle's collision so it doesn't make Borbie glitch out
this->removeCollision(carriedVehicle->getNode()->getTriangleSelector());
// flag carried vehicle as no longer pickable
carriedVehicle->getNode()->setID(IDFlag_IsNotPickable);
// display the target marker on the GUI
this->hud->setTargetMarkerEnabled(true);
//set hands invisible
this->hands->setVisible(false);
}
}
// If we're currently carrying a vehicle, and the left mouse button is
// pressed, throw it and break someone's face.
if (carriedVehicle && !vehicleThrown &&
((BorbiesEventReceiver *)receiver)->isLeftMouseDown())
{
// get the player's target node
ISceneNode *target = selector->getThrowTarget();
//target->setVisible(false);
if(target)
std::cout << "Target in sight at distance = " <<
target->getPosition().getDistanceFrom(carriedVehicle->
getNode()->getPosition()) << std::endl;
// throw the selected object at the found target; if target is null
// (not found), it will just fly to the maximum distance possible.
// This will start an animator to fly to the target.
objCarry->throwObj(target);
//turn hands back on
this->hands->setVisible(true);
vehicleThrown = true;
// hide the target marker (no longer needed)
this->hud->setTargetMarkerEnabled(false);
}
// update thrownObject (checks if vehicles need to be thrown)
this->updateThrownObject();
}
示例14: applyExplosionDamage
/******************************************************************************
* Apply explosion damage to all objects within the radius of the given
* gameObject, scaled based on distance from the explosion, up to a maximum
* damage as dictated by the given object's damage value. Explosions
* affect vehicles, buildings, enemies, and Borbie.
*****************************************************************************/
void GameInstance::applyExplosionDamage(GameObject *explodingObject) {
// get the exploding object's variables
GameObjectType explodingType = explodingObject->getObjectType();
ISceneNode *explodingNode = explodingObject->getNode();
float explosionRadius = explodingObject->getExplosionRadius();
float explosionDamage = explodingObject->getExplosionDamage();
vector3df explodePos = explodingNode->getPosition();
// calculate damage to enemies
int numEnemies = enemies->objList.size();
for(int i=0; i<numEnemies; i++){
ISceneNode *curNode = enemies->objList[i]->getNode();
// if current node is the exploding node, ignore it
if(curNode == explodingNode)
continue;
// if current node is NOT visible or if it already blew up, ignore it
else if(!curNode->isVisible() || enemies->objList[i]->hasExploded())
continue;
float distance = curNode->getPosition().getDistanceFrom(explodePos);
if(distance <= explosionRadius){
int damage = explosionDamage; // max damage
if(distance > 400){ // if more than 400 away, scale down damage
float scale = (distance-400) / (explosionRadius-400);
damage = int(explosionDamage * scale);
}
enemies->objList[i]->applyDamage(damage);
}
}
// calculate damage for buildings
int numBuild = buildings->objList.size();
for(int i=0; i<numBuild; i++){
ISceneNode *curNode = buildings->objList[i]->getNode();
// if current node is the exploding node, ignore it
if(curNode == explodingNode)
continue;
// if current node is NOT visible, ignore it
else if(!curNode->isVisible() || buildings->objList[i]->hasExploded())
continue;
// otherwise, check if the distance is close enough, and apply damage
// based on the distance to the explosion center. Offset position by 200
// since the buildings are not positioned relative to their center.
float distance = curNode->getPosition().getDistanceFrom(explodePos);
if(distance <= explosionRadius){
int damage = explosionDamage; // max damage
if(distance > 400){ // if more than 400 away, scale down damage
float scale = (distance-400) / (explosionRadius-400);
damage = int(explosionDamage * scale);
}
// if the exploding object is a building, reduce splash damage
// to prevent instant-killing an entire city. That would suck.
if(explodingType == TYPE_BUILDING)
damage = damage / 20;
buildings->objList[i]->applyDamage(damage);
}
}
// calculate damage for vehicles
int numVehicles = vehicles->objList.size();
for(int i = 0 ; i < numVehicles ; i++){
ISceneNode *curNode = vehicles->objList[i]->getNode();
// if current node is the exploding node, ignore it
if(curNode == explodingNode)
continue;
// if current node is NOT visible, ignore it
else if(!curNode->isVisible() || vehicles->objList[i]->hasExploded())
continue;
// otherwise, check if the distance is close enough, and apply damage
// based on the distance to the explosion center
float distance = curNode->getPosition().getDistanceFrom(explodePos);
if(distance <= explosionRadius){
int damage = explosionDamage; // max damage
if(distance > 400){ // if more than 400 away, scale down damage
float scale = (distance-400) / (explosionRadius-400);
damage = int(explosionDamage * scale);
}
vehicles->objList[i]->applyDamage(damage);
}
}
// if Borbie is already dead, don't kill her again :(
if(player->hasExploded())
return;
// apply damage to borbie herself (the player)
float distance = player->getNode()->getPosition().getDistanceFrom(explodePos);
// if a vehicle, lower the explosion radius that applies to borbie
if(explodingType == TYPE_VEHICLE)
explosionRadius = 600;
if(distance <= explosionRadius){
int damage = explosionDamage; // max damage
if(distance > 400){ // if more than 400 away, scale down damage
float scale = (distance-400) / (explosionRadius-400);
damage = int(explosionDamage * scale);
//.........这里部分代码省略.........
示例15: OnEvent
virtual bool OnEvent(const SEvent& event)
{
// Escape swaps Camera Input
if (event.EventType == EET_KEY_INPUT_EVENT
&& event.KeyInput.PressedDown == false)
{
if (event.KeyInput.Key == irr::KEY_ESCAPE)
{
if (g_Device)
{
scene::ICameraSceneNode * camera =
g_Device->getSceneManager()->getActiveCamera();
if (camera)
{
camera->setInputReceiverEnabled(
!camera->isInputReceiverEnabled());
}
return true;
}
}
}
else if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
//IGUIEnvironment* env = g_Device->getGUIEnvironment();
switch (event.GUIEvent.EventType)
{
case EGET_SCROLL_BAR_CHANGED:
{
IGUIScrollBar* scroll = (IGUIScrollBar*) event.GUIEvent.Caller;
const s32 pos = scroll->getPos();
if (id == GUI_ID_SPEED_SCROLL)
{
g_CameraAnimator->setMoveSpeed(pos * pos / 100000.0);
}
else if (id == GUI_ID_LEVEL)
{
//g_EarthVisualization->setLevel(pos);
}
}
break;
case EGET_CHECKBOX_CHANGED:
{
IGUICheckBox* checkBox = (IGUICheckBox*) event.GUIEvent.Caller;
if (id == GUI_ID_WIREFRAME)
{
g_EarthVisualization->setWireframe(checkBox->isChecked());
}
else if (id == GUI_ID_MESH_UPDATE)
{
g_EarthVisualization->setMeshGenerated(
checkBox->isChecked());
}
}
break;
default:
break;
}
}
else if (event.EventType == EET_USER_EVENT)
{
if (event.UserEvent.UserData1 == ANIMATION_MOVE_EVENT)
{
ISceneNode* node = (ISceneNode*) event.UserEvent.UserData2;
g_EarthVisualization->setViewerPoint(node->getPosition());
g_LevelScroll->setPos(g_EarthVisualization->getLevel());
}
}
return false;
}