本文整理汇总了C++中Portal类的典型用法代码示例。如果您正苦于以下问题:C++ Portal类的具体用法?C++ Portal怎么用?C++ Portal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Portal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _checkNodeAgainstPortals
void DefaultZone::_checkNodeAgainstPortals(PCZSceneNode * pczsn, Portal * ignorePortal)
{
if (pczsn == mEnclosureNode ||
pczsn->allowedToVisit() == false)
{
// don't do any checking of enclosure node versus portals
return;
}
PCZone * connectedZone;
for ( PortalList::iterator it = mPortals.begin(); it != mPortals.end(); ++it )
{
Portal * p = *it;
//Check if the portal intersects the node
if (p != ignorePortal &&
p->intersects(pczsn) != Portal::NO_INTERSECT)
{
// node is touching this portal
connectedZone = p->getTargetZone();
// add zone to the nodes visiting zone list unless it is the home zone of the node
if (connectedZone != pczsn->getHomeZone() &&
!pczsn->isVisitingZone(connectedZone))
{
pczsn->addZoneToVisitingZonesMap(connectedZone);
// tell the connected zone that the node is visiting it
connectedZone->_addNode(pczsn);
//recurse into the connected zone
connectedZone->_checkNodeAgainstPortals(pczsn, p->getTargetPortal());
}
}
}
}
示例2: Ray
void World::shootPortal(int button) {
//Shooting
Vector3f cameraDir = Math::toDirection(scene->camera.rotation);
//Find the closest intersection
Entity closestWall;
float intersection = INT_MAX;
for (unsigned int i = 0; i < scene->walls.size(); i++) {
Entity wall = scene->walls[i];
Ray bullet = Ray(scene->camera.position, cameraDir);
float tNear, tFar;
if (bullet.collides(wall, &tNear, &tFar)) {
if (wall.texture.handle == TextureLoader::getTexture("wall.png").handle) {
if (tNear < intersection) {
closestWall = wall;
intersection = tNear;
}
}
}
}
BoxCollider wall(closestWall.position, closestWall.scale);
Vector3f ipos = scene->camera.position + (cameraDir * intersection);
Portal portal;
portal.placeOnWall(wall, ipos);
if (button == 1) {
portal.texture = TextureLoader::getTexture("blueportal.png");
scene->bluePortal = portal;
} else {
portal.texture = TextureLoader::getTexture("orangeportal.png");
scene->orangePortal = portal;
}
}
示例3: handleCamera
void handleCamera(Camera * camera)
{
vec3 oldCameraPos = camera->getPosition();
vec3 move(glfwGetKey('D')-glfwGetKey('A'),0,glfwGetKey('S')-glfwGetKey('W'));
move *= 0.1f;
camera->move(move);
vec3 newCameraPos = camera->getPosition();
vec2 lookVec( glfwGetKey(GLFW_KEY_LEFT)-glfwGetKey(GLFW_KEY_RIGHT),
glfwGetKey(GLFW_KEY_UP)-glfwGetKey(GLFW_KEY_DOWN));
camera->rotateY(lookVec.x * 2.0);
// Handle portaling :)
Module * currentModule = camera->getOwnerModule();
std::vector<Portal*> portals = currentModule->getPortals();
for(u32 i=0; i<portals.size(); ++i)
{
Portal * portal = portals[i];
if( intersectLinePortal(oldCameraPos, newCameraPos, *portal) )
{
camera->getOwnerModule()->removeGameObject(camera);
portal->getTargetPortal()->getOwnerModule()->addGameObject(camera);
camera->setTransform(portal->getInvViewMatrix(camera));
}
}
}
示例4: transportBall
void Portal::transportBall(Ball &ball, Portal &portal)
{
int nextX = portal.getXPos();
int nextY = portal.getYPos();
ball.setXPos(nextX);
ball.setYPos(nextY);
}
示例5: destroyPortal
// delete a portal instance by pointer
void PCZSceneManager::destroyPortal(Portal * p)
{
// remove the portal from it's target portal
Portal * targetPortal = p->getTargetPortal();
if (targetPortal)
{
targetPortal->setTargetPortal(0); // the targetPortal will still have targetZone value, but targetPortal will be invalid
}
// remove the Portal from it's home zone
PCZone * homeZone = p->getCurrentHomeZone();
if (homeZone)
{
// inform zone of portal change. Do here since PCZone is abstract
homeZone->setPortalsUpdated(true);
homeZone->_removePortal(p);
}
// remove the portal from the master portal list
PortalList::iterator it = std::find( mPortals.begin(), mPortals.end(), p );
if (it != mPortals.end())
{
mPortals.erase(it);
}
// delete the portal instance
OGRE_DELETE p;
}
示例6: Portal
// Create a portal instance
Portal* PCZSceneManager::createPortal(const String& name, PortalBase::PORTAL_TYPE type)
{
Portal* newPortal = OGRE_NEW Portal(name, type);
newPortal->_notifyCreator(Root::getSingleton().getMovableObjectFactory("Portal"));
newPortal->_notifyManager(this);
mPortals.push_front(newPortal);
return newPortal;
}
示例7: if
//---------------------------------------------------------------------------------------
void Portal::Split(Plane& plane, Portal& a, Portal& b)
{
a.CopyProps(*this);
b.CopyProps(*this);
if((_n == plane._n && _c == plane._c) ||
(_n == -plane._n && _c == -plane._c) )
{
#ifdef WINDOWS
# pragma message("see this")
#endif
a._vxes = _vxes;
b._vxes = _vxes;
return;
}
v3d_t iv;
v3d_t itxB = *_vxes.begin();
v3d_t itxA = _vxes.back();
f32_t fB;
f32_t fA = plane.DistTo(itxA);
FOREACH(vvector<v3d_t>, _vxes, vxI)
{
itxB = *vxI;
fB = plane.DistTo(itxB);
if(fB > GEpsilon)
{
if(fA < -GEpsilon)
{
f32_t t = -fA /(fB - fA);
iv.interpolate(itxA,itxB,t);
a._vxes << iv;
b._vxes << iv;
}
a._vxes<<itxB;
}
else if(fB < -GEpsilon)
{
if(fA > GEpsilon)
{
f32_t t = -fA /(fB - fA); // t of segment
iv.interpolate(itxA,itxB,t);
a._vxes <<iv;
b._vxes <<iv;
}
b._vxes<<itxB;
}
else
{
a._vxes << itxB;
b._vxes << itxB;
}
itxA = itxB;
fA = fB;
}
示例8: new
Portal* Portal::create(Stage* _stage) {
Portal* ret = new (std::nothrow) Portal();
if (ret &&ret->init(_stage))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
示例9: glDisable
void Sector::render(Portal *portal) {
if(frame == Engine::frame) return;
frame = Engine::frame;
this->portal = portal;
Bsp::visible_sectors[Bsp::num_visible_sectors++] = this;
num_visible_objects = 0;
root->render();
for(int i = 0; i < num_objects; i++) {
Object *o = objects[i];
if(o->frame == Engine::frame) continue;
if(Engine::frustum->inside(o->pos + o->getCenter(),o->getRadius())) {
Engine::num_triangles += o->render(Object::RENDER_OPACITY);
visible_objects[num_visible_objects++] = o;
}
}
for(int i = 0; i < num_portals; i++) {
Portal *p = &Bsp::portals[portals[i]];
if(p->frame == Engine::frame) continue;
p->frame = Engine::frame;
if(Engine::frustum->inside(p->center,p->radius)) {
float dist = (Engine::camera - p->center).length();
if(Engine::have_occlusion && dist > p->radius) {
if(Material::old_material) Material::old_material->disable();
glDisable(GL_CULL_FACE);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glDepthMask(GL_FALSE);
glBeginQueryARB(GL_SAMPLES_PASSED_ARB,Engine::query_id);
p->render();
glEndQueryARB(GL_SAMPLES_PASSED_ARB);
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glEnable(GL_CULL_FACE);
GLuint samples;
glGetQueryObjectuivARB(Engine::query_id,GL_QUERY_RESULT_ARB,&samples);
if(samples == 0) continue;
}
if(dist > p->radius) Engine::frustum->addPortal(Engine::camera,p->points);
for(int j = 0; j < p->num_sectors; j++) {
Bsp::sectors[p->sectors[j]].render(dist > p->radius ? p : NULL);
}
if(dist > p->radius) Engine::frustum->removePortal();
}
}
}
示例10: switch
/* The following function checks if a node has left it's current home zone.
* This is done by checking each portal in the zone. If the node has crossed
* the portal, then the current zone is no longer the home zone of the node. The
* function then recurses into the connected zones. Once a zone is found where
* the node does NOT cross out through a portal, that zone is the new home zone.
NOTE: For this function to work, the node must start out in the proper zone to
begin with!
*/
PCZone* DefaultZone::updateNodeHomeZone( PCZSceneNode * pczsn, bool allowBackTouches )
{
// default to newHomeZone being the current home zone
PCZone * newHomeZone = pczsn->getHomeZone();
// Check all portals of the start zone for crossings!
Portal* portal;
PortalList::iterator pi, piend;
piend = mPortals.end();
for (pi = mPortals.begin(); pi != piend; pi++)
{
portal = *pi;
Portal::PortalIntersectResult pir = portal->intersects(pczsn);
switch (pir)
{
default:
case Portal::NO_INTERSECT: // node does not intersect portal - do nothing
case Portal::INTERSECT_NO_CROSS:// node intersects but does not cross portal - do nothing
break;
case Portal::INTERSECT_BACK_NO_CROSS:// node intersects but on the back of the portal
if (allowBackTouches)
{
// node is on wrong side of the portal - fix if we're allowing backside touches
if (portal->getTargetZone() != this &&
portal->getTargetZone() != pczsn->getHomeZone())
{
// set the home zone of the node to the target zone of the portal
pczsn->setHomeZone(portal->getTargetZone());
// continue checking for portal crossings in the new zone
newHomeZone = portal->getTargetZone()->updateNodeHomeZone(pczsn, false);
}
}
break;
case Portal::INTERSECT_CROSS:
// node intersects and crosses the portal - recurse into that zone as new home zone
if (portal->getTargetZone() != this &&
portal->getTargetZone() != pczsn->getHomeZone())
{
// set the home zone of the node to the target zone of the portal
pczsn->setHomeZone(portal->getTargetZone());
// continue checking for portal crossings in the new zone
newHomeZone = portal->getTargetZone()->updateNodeHomeZone(pczsn, true);
}
break;
}
}
// return the new home zone
return newHomeZone;
}
示例11: Save
//=================================================================================================
void Location::Save(GameWriter& f, bool)
{
f << type;
f << pos;
f << name;
f << state;
int refid;
if(active_quest)
{
if(active_quest == (Quest_Dungeon*)ACTIVE_QUEST_HOLDER)
refid = ACTIVE_QUEST_HOLDER;
else
refid = active_quest->refid;
}
else
refid = -1;
f << refid;
f << last_visit;
f << st;
f << outside;
f << reset;
f << spawn;
f << dont_clean;
f << seed;
f << image;
// portals
Portal* p = portal;
while(p)
{
f.Write1();
p->Save(f);
p = p->next_portal;
}
f.Write0();
// events
f << events.size();
for(Event& e : events)
{
f << e.type;
f << e.quest->refid;
}
}
示例12: dist
long Portal::dist(Portal &p) const
{
//Om de är i samma grupp
if (p.group->id == this->group->id)
{
//Om du ska hitta avtåndet i en cykel
if (group->type == 1)
{
if (p.i() < i())
return group->high - i() + 1 + p.i() - group->low;
else
return p.i() - i();
}
//Avståndet i en gren
if (group->type == 2)
{
if (p.in(group) && p.i() > i())
return p.i() - i();
else
return -1;
}
}
else
{
//Om det finns en väg mellan de två nodernas grupper
if (group->merge.find(p.group->id) != group->merge.end())
{
//Om noden har en index högre än där grenen ansluter till dens grupp
if (portals[group->merge[p.group->id].first].i() <= p.i())
{
return group->high - i() + 1 + group->merge[p.group->id].second + p.i() - portals[group->merge[p.group->id].first].i();
}
else if (p.group->type == 1)
{
return group->high - i() + 1 + group->merge[p.group->id].second + p.group->high - portals[group->merge[p.group->id].first].i() + p.i() - p.group->low + 1;
}
}
else
return -1;
}
return -1;
}
示例13: descriptionForStrengthAndCharacterInRoom
void SoundEvent::visitRoom(Room *room, double strength) {
strength *= room->eventMultiplier(GameEventType::Sound);
if (strength >= 0.1) {
for (const GameObjectPtr &characterPtr : room->characters()) {
if (excludedCharacters().contains(characterPtr)) {
continue;
}
Character *character = characterPtr.cast<Character *>();
QString message = descriptionForStrengthAndCharacterInRoom(strength, character, room);
if (character->isPlayer()) {
character->send(message);
} else {
character->invokeTrigger("onsound", message);
}
addAffectedCharacter(characterPtr);
}
for (const GameObjectPtr &portalPtr : room->portals()) {
Portal *portal = portalPtr.cast<Portal *>();
Room *room1 = portal->room().unsafeCast<Room *>();
Room *room2 = portal->room2().unsafeCast<Room *>();
Room *oppositeRoom = (room == room1 ? room2 : room1);
if (hasBeenVisited(oppositeRoom) || !portal->canHearThrough()) {
continue;
}
double propagatedStrength = strength * portal->eventMultiplier(GameEventType::Sound);
if (propagatedStrength >= 0.1) {
addVisit(oppositeRoom, propagatedStrength);
}
}
}
}
示例14: while
/* Attempt to automatically connect unconnected portals to proper target zones
* by looking for matching portals in other zones which are at the same location
*/
void PCZSceneManager::connectPortalsToTargetZonesByLocation(void)
{
// go through every zone to find portals
ZoneMap::iterator i, iend;
PCZone* zone;
iend = mZones.end();
bool foundMatch;
for (i = mZones.begin(); i != iend; i++)
{
zone = i->second;
// go through all the portals in the zone
Portal* portal;
PortalList::iterator pi, piend;
piend = zone->mPortals.end();
for (pi = zone->mPortals.begin(); pi != piend; pi++)
{
portal = *pi;
//portal->updateDerivedValues();
if (portal->getTargetZone() == 0)
{
// this is a portal without a connected zone - look for
// a matching portal in another zone
PCZone* zone2;
ZoneMap::iterator j= mZones.begin();
foundMatch = false;
while (!foundMatch && j != mZones.end())
{
zone2 = j->second;
if (zone2 != zone) // make sure we don't look in the same zone
{
Portal * portal2 = zone2->findMatchingPortal(portal);
if (portal2)
{
// found a match!
Ogre::LogManager::getSingletonPtr()->logMessage("Connecting portal "+portal->getName()+" to portal "+portal2->getName());
foundMatch = true;
portal->setTargetZone(zone2);
portal->setTargetPortal(portal2);
portal2->setTargetZone(zone);
portal2->setTargetPortal(portal);
}
}
j++;
}
if (foundMatch == false)
{
// error, didn't find a matching portal!
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
"Could not find matching portal for portal " + portal->getName(),
"PCZSceneManager::connectPortalsToTargetZonesByLocation");
}
}
}
}
}
示例15: rec
//Skapa den nya datastrukturen med grupper
//Varje nod besöks 1 gång O(N)
//a = noden som skall besökas, low = lägsta noden (ny index) som besökts (början på en gren)
inline Group * rec(long a, const long & low)
{
Portal * p = &portals[a];
//Om noden inte har fått en ny index
if (p->i() == 0) {
//Ge en ny index
p->new_index = first++;
Group * g = rec(p->exit, low);
//Om vi ansluter till en cykel
if (g->type == 1)
{
//Om den nuvarande noden finns i cykeln
if (p->in(g))
{
//sätt nodens grupp till cykelns
return p->group = g;
}
else
{
//Annars skapa en gren
p->group->type = 2;
p->group->merge[portals[p->exit].group->id] = make_pair(p->exit, 0);
p->group->low = low;
p->group->high = p->new_index;
return p->group;
}
}
else
{
//Om numret inte finns i den nuvarande grenen
if (!p->in(g)) {
//_(Optimering)_
//Om du ansluter en nod i början av grenen
if (portals[p->exit].i() == g->low)
{
//Flytta upp noderna i grenens index så att de nu är över den nuvarande nodens index
g->add += (p->i() - g->low) + 1;
g->high += (p->i() - g->low) + 1;
first = g->high + 1;
p->new_index -= g->add;
g->low = low;
}else
{
//Om den nya noden ansluter mitt på grenen skapa en ny gren.
p->group->type = 2;
//Hämta avtånde och anslutningsinformation från överliggadne gren
for (auto item : g->merge)
p->group->merge[item.first] = make_pair(item.second.first, item.second.second + g->high - portals[p->exit].i() + 1);
p->group->merge[g->id] = make_pair(p->exit, 0);
p->group->low = low;
p->group->high = p->new_index;
return p->group;
}
}
else
{
//Om noden finns på grenen justera dens index
p->new_index -= g->add;
}
return p->group = g;
}
}
else
{
//Om noden är besökt men inte har en grupp
if (p->group->type == 0)
{
//Skapa en cykel
p->group->type = 1;
p->group->low = p->i();
p->group->high = first - 1;
return p->group;
}
else
{
return p->group;
}
}
}