本文整理汇总了C++中PVector类的典型用法代码示例。如果您正苦于以下问题:C++ PVector类的具体用法?C++ PVector怎么用?C++ PVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PVector类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClassifyPoly
//classifies a polygon with regards to the plane. It will return one of the PLANE_XXX values
//indicating the classification of the polygon
static uint32 ClassifyPoly(const PVector& vNormal, PReal fPlaneDist, CPrePoly* pPoly)
{
//sanity check
ASSERT(pPoly);
//first classify the poly sphere
PReal fDot = vNormal.Dot(pPoly->m_BasePoly.GetCenterDirect()) - fPlaneDist;
//see if it lies entirely on one side
PReal fPolyRad = pPoly->m_BasePoly.GetRadiusDirect();
if(fDot > fPolyRad)
{
//it is entirely on the front side
return PLANE_FRONT;
}
else if(fDot < -fPolyRad)
{
//it is entirely on the back side
return PLANE_BACK;
}
uint32 nRV = PLANE_ON;
uint32 nNumVerts = pPoly->NumVerts();
//the polygon could span, so now we have to do the full every vert check
for(uint32 nCurrVert = 0; nCurrVert < nNumVerts; nCurrVert++)
{
fDot = vNormal.Dot(pPoly->Pt(nCurrVert)) - fPlaneDist;
if(fDot < -PLANAR_EPSILON)
{
//check for front side intersection
for(nCurrVert++; nCurrVert < nNumVerts; nCurrVert++)
{
if(vNormal.Dot(pPoly->Pt(nCurrVert)) - fPlaneDist > PLANAR_EPSILON)
{
return PLANE_SPAN;
}
}
return PLANE_BACK;
}
if(fDot > PLANAR_EPSILON)
{
//check for front side intersection
for(nCurrVert++; nCurrVert < nNumVerts; nCurrVert++)
{
if(vNormal.Dot(pPoly->Pt(nCurrVert)) - fPlaneDist < -PLANAR_EPSILON)
{
return PLANE_SPAN;
}
}
return PLANE_FRONT;
}
}
return nRV;
}
示例2: seek
void Vehicle::seek() {
PVector *target = player->getLocation();
PVector *desired = PVector::sub(target, location);
desired->normalize();
desired->mult(maxspeed);
PVector *steer = PVector::sub(desired, velocity);
steer->limit(maxforce);
applyForce(steer);
}
示例3: getRepairCrewFor
PVector<RepairCrew> getRepairCrewFor(P<PlayerSpaceship> ship)
{
PVector<RepairCrew> ret;
if (!ship)
return ret;
foreach(RepairCrew, c, repairCrewList)
if (c->ship_id == ship->getMultiplayerId())
ret.push_back(c);
return ret;
}
示例4: update
void Mover::update(PVector *mouse)
{
//Example 1.10: Accelerating towards the mouse
PVector *dir = PVector::sub(mouse,location);
dir->normalize();
dir->mult(0.3);
acceleration = dir;
//Example 1.9: Motion 101 (velocity and random acceleration)
//acceleration->random2D();
//acceleration->mult(0.3);
//Example 1.8: Motion 101 (velocity and constant acceleration)
velocity->add(acceleration);
velocity->limit(topspeed);
location->add(velocity);
}
示例5: main
int main(int argc, const char * argv[])
{
// Vectors
PVector<int, persister<int> > pvInt = PVector<int, persister<int> >("/Users/Raphael/Dropbox/uzh/uzh-13-fall/uzh-apc/uzh-apc-ex/apc-ex-04-1/apc-ex-04-1/tmp.txt");
pvInt.push_back(12);
pvInt.push_back(13);
PVector<std::string, persister<std::string> > pv = PVector<std::string, persister<std::string> >("/Users/Raphael/Dropbox/uzh/uzh-13-fall/uzh-apc/uzh-apc-ex/apc-ex-04-1/apc-ex-04-1/tmp2.txt");
pv.push_back("Test1.");
pv.push_back("Test2.a Test2.b Test2.c");
PVector<Fraction, persister<Fraction> > pvFr = PVector<Fraction, persister<Fraction> >("/Users/Raphael/Dropbox/uzh/uzh-13-fall/uzh-apc/uzh-apc-ex/apc-ex-04-1/apc-ex-04-1/tmp5.txt");
Fraction fr1 = Fraction();
fr1.set_counter(4);
fr1.set_denominator(5);
Fraction fr2 = Fraction();
fr2.set_counter(5);
fr2.set_denominator(7);
pvFr.push_back(fr1);
pvFr.push_back(fr2);
// Sets: unique Values
PSet<int, persisterTwo<int> > psInt = PSet<int, persisterTwo<int> >("/Users/Raphael/Dropbox/uzh/uzh-13-fall/uzh-apc/uzh-apc-ex/apc-ex-04-1/apc-ex-04-1/tmp3.txt");
psInt.insert(2);
psInt.insert(4);
PSet<std::string, persisterTwo<std::string> > ps = PSet<std::string, persisterTwo<std::string> >("/Users/Raphael/Dropbox/uzh/uzh-13-fall/uzh-apc/uzh-apc-ex/apc-ex-04-1/apc-ex-04-1/tmp4.txt");
std::string a = "Test1";
std::string b = "Test2.a Test2.b Test2.c";
ps.insert(a);
ps.insert(b);
PSet<Fraction, persisterTwo<Fraction> > psFr = PSet<Fraction, persisterTwo<Fraction> >("/Users/Raphael/Dropbox/uzh/uzh-13-fall/uzh-apc/uzh-apc-ex/apc-ex-04-1/apc-ex-04-1/tmp6.txt");
psFr.insert(fr1);
psFr.insert(fr2);
return 0;
}
示例6: glViewport
//.........这里部分代码省略.........
glScalef(1,1,-1);
glRotatef(-camera_pitch, 1, 0, 0);
glRotatef(-camera_yaw - 90, 0, 0, 1);
glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
glGetDoublev(GL_MODELVIEW_MATRIX, model_matrix);
glGetDoublev(GL_VIEWPORT, viewport);
sf::Texture::bind(textureManager.getTexture("Stars"), sf::Texture::Pixels);
glDepthMask(false);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(1024, 0); glVertex3f( 100, 100, 100);
glTexCoord2f( 0, 0); glVertex3f( 100, 100,-100);
glTexCoord2f(1024, 1024); glVertex3f(-100, 100, 100);
glTexCoord2f( 0, 1024); glVertex3f(-100, 100,-100);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(1024, 0); glVertex3f(-100, 100, 100);
glTexCoord2f( 0, 0); glVertex3f(-100, 100,-100);
glTexCoord2f(1024, 1024); glVertex3f(-100,-100, 100);
glTexCoord2f( 0, 1024); glVertex3f(-100,-100,-100);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(1024, 0); glVertex3f(-100,-100, 100);
glTexCoord2f( 0, 0); glVertex3f(-100,-100,-100);
glTexCoord2f(1024, 1024); glVertex3f( 100,-100, 100);
glTexCoord2f( 0, 1024); glVertex3f( 100,-100,-100);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(1024, 0); glVertex3f( 100,-100, 100);
glTexCoord2f( 0, 0); glVertex3f( 100,-100,-100);
glTexCoord2f(1024, 1024); glVertex3f( 100, 100, 100);
glTexCoord2f( 0, 1024); glVertex3f( 100, 100,-100);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(1024, 0); glVertex3f( 100,-100, 100);
glTexCoord2f( 0, 0); glVertex3f(-100,-100, 100);
glTexCoord2f(1024, 1024); glVertex3f( 100, 100, 100);
glTexCoord2f( 0, 1024); glVertex3f(-100, 100, 100);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(1024, 0); glVertex3f( 100,-100,-100);
glTexCoord2f( 0, 0); glVertex3f(-100,-100,-100);
glTexCoord2f(1024, 1024); glVertex3f( 100, 100,-100);
glTexCoord2f( 0, 1024); glVertex3f(-100, 100,-100);
glEnd();
if (gameGlobalInfo)
{
//Render the background nebulas from the gameGlobalInfo. This ensures that all screens see the same background as it is replicated across clients.
for(int n=0; n<GameGlobalInfo::max_nebulas; n++)
{
sf::Texture::bind(textureManager.getTexture(gameGlobalInfo->nebula_info[n].textureName), sf::Texture::Pixels);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glPushMatrix();
glRotatef(180, gameGlobalInfo->nebula_info[n].vector.x, gameGlobalInfo->nebula_info[n].vector.y, gameGlobalInfo->nebula_info[n].vector.z);
glColor4f(1,1,1,0.1);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(1024, 0); glVertex3f( 100, 100, 100);
glTexCoord2f( 0, 0); glVertex3f( 100, 100,-100);
glTexCoord2f(1024, 1024); glVertex3f(-100, 100, 100);
glTexCoord2f( 0, 1024); glVertex3f(-100, 100,-100);
glEnd();
glPopMatrix();
}
}
glColor4f(1,1,1,1);
glDisable(GL_BLEND);
sf::Texture::bind(NULL);
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
{
float lightpos1[4] = {0, 0, 0, 1.0};
glLightfv(GL_LIGHT1, GL_POSITION, lightpos1);
float lightpos0[4] = {20000, 20000, 20000, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, lightpos0);
}
PVector<SpaceObject> renderList;
sf::Vector2f viewVector = sf::vector2FromAngle(camera_yaw);
float depth_cutoff_back = camera_position.z * -tanf((90+camera_pitch + camera_fov/2.0) / 180.0f * M_PI);
float depth_cutoff_front = camera_position.z * -tanf((90+camera_pitch - camera_fov/2.0) / 180.0f * M_PI);
if (camera_pitch - camera_fov/2.0 <= 0.0)
depth_cutoff_front = std::numeric_limits<float>::infinity();
if (camera_pitch + camera_fov/2.0 >= 180.0)
depth_cutoff_back = -std::numeric_limits<float>::infinity();
foreach(SpaceObject, obj, space_object_list)
{
float depth = sf::dot(viewVector, obj->getPosition() - sf::Vector2f(camera_position.x, camera_position.y));
if (depth + obj->getRadius() < depth_cutoff_back)
continue;
if (depth - obj->getRadius() > depth_cutoff_front)
continue;
if (depth > 0 && obj->getRadius() / depth < 1.0 / 500)
continue;
renderList.push_back(obj);
}
示例7: main
int main(int argc, char *argv[]) {
using Teuchos::RCP;
using Teuchos::rcp;
typedef std::vector<RealT> vector;
typedef ROL::StdVector<RealT> StdVector;
typedef Teuchos::RCP<ROL::Vector<RealT> > PVector;
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
// This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
int iprint = argc - 1;
Teuchos::RCP<std::ostream> outStream;
Teuchos::oblackholestream bhs; // outputs nothing
if (iprint > 0)
outStream = Teuchos::rcp(&std::cout, false);
else
outStream = Teuchos::rcp(&bhs, false);
// Save the format state of the original std::cout.
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(std::cout);
int errorFlag = 0;
// Specify interval on which to generate uniform random numbers.
RealT left = 0.1, right = 1.1;
// *** Test body.
try {
int dim = 1;
RCP<vector> x_rcp = rcp( new vector(dim,0.0) );
RCP<vector> y_rcp = rcp( new vector(dim,0.0) );
RCP<vector> v_rcp = rcp( new vector(dim,0.0) );
RCP<vector> d_rcp = rcp( new vector(dim,0.0) );
RCP<vector> gx_rcp = rcp( new vector(dim,0.0) );
RCP<vector> gy_rcp = rcp( new vector(dim,0.0) );
RCP<vector> hv_rcp = rcp( new vector(dim,0.0) );
for( int i=0; i<dim; ++i ) {
(*x_rcp)[i] = 2+( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
(*d_rcp)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
(*v_rcp)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
}
StdVector x( x_rcp);
StdVector y( y_rcp);
StdVector v( v_rcp);
StdVector d( d_rcp);
StdVector gx(gx_rcp);
StdVector gy(gy_rcp);
StdVector hv(hv_rcp);
// Fixed difference step size
RealT delta = 1.e-7;
y.set(x); // y = x
y.axpy(delta,d); // y = x+delta*d
ROL::LogBarrierObjective<RealT> obj;
// Do step size sweep
obj.checkGradient(x, d, true, *outStream);
*outStream << "\n";
obj.checkHessVec(x, v, true, *outStream);
*outStream << "\n";
RealT tol = 0;
// Compute objective at x and y
RealT fx = obj.value(x,tol);
RealT fy = obj.value(y,tol);
// Compute gradient at x and y
obj.gradient(gx,x,tol);
obj.gradient(gy,y,tol);
// Compute action of Hessian on v at x
obj.hessVec(hv,v,x,tol);
// FD gradient error
RealT graderr = (fy - fx)/delta - gx.dot(d);
// FD Hessian error
PVector dg = gx.clone();
dg->set(gy);
dg->axpy(-1.0,gx);
RealT hesserr = ( dg->dot(v) )/delta - hv.dot(d);
if( std::abs(graderr) > 1e-8 ) {
++errorFlag;
}
if( std::abs(hesserr) > 1e-8 ) {
//.........这里部分代码省略.........
示例8: threes
void threes(const Vec2 &point)
{
point.toString();
int l,f,u,d;
l = f = point.x;
u = d = point.y;
PVector tmpX;
PVector tmpY;
WTF node;
node.centre = point;
int countX = 0;
while(--l > 0)
{
if (Map[l][point.y] == Map[point.x][point.y])
{
cout<<l<<" l "<<point.y<<endl;
tmpX.push_back(Vec2(l,point.y));
++countX;
}
else
break;
};
while(++f < xCount)
{
if (Map[f][point.y] == Map[point.x][point.y])
{
cout<<f<<" f "<<point.y<<endl;
tmpX.push_back(Vec2(f,point.y));
++countX;
}
else
break;
};
if (countX>=2)
{
cout<<"X is THREE"<<endl;
node.vecX = tmpX;
}
int countY = 0;
while(--u > 0)
{
if (Map[point.x][u] == Map[point.x][point.y])
{
cout<<point.x<<" u "<<u<<endl;
tmpY.push_back(Vec2(point.x,u));
++countY;
}
else
break;
};
while(++d < yCount)
{
if (Map[point.x][d] == Map[point.x][point.y])
{
cout<<point.x<<" d "<<d<<endl;
tmpY.push_back(Vec2(point.x,d));
++countY;
}
else
break;
};
if (countY>=2)
{
cout<<"Y is THREE"<<endl;
node.vecY = tmpY;
}
bool cross = countX>=2&&countY>=2;
bool five = countX>=4||countY>=4;
bool four = countX>=3||countY>=3;
bool three = countX>=2||countY>=2;
node.p = 0;
if (countX>=2&&countY>=2)
{
node.p |= CROSS;
}
if (countX>=4||countY>=4)
{
node.p |= FIVE;
}
else if (countX>=3||countY>=3)
{
node.p |= FOUR;
}
else if (countX>=2||countY>=2)
{
node.p |= THREE;
}
if (node.p!=0)
{
cout<<"Yes"<<endl;
nodes.push_back(node);
}
}
示例9: foreach
FactionInfo::FactionInfo()
{
foreach(FactionInfo, i, factionInfo)
i->states.push_back(FVF_Neutral);
factionInfo.push_back(this);
for(unsigned int n = 0; n < factionInfo.size(); n++)
states.push_back(FVF_Neutral);
for(unsigned int n = 0; n < factionInfo.size(); n++)
if (factionInfo[n] == this)
states[n] = FVF_Friendly;
}
示例10: foreach
FactionInfo::FactionInfo()
{
if (game_server) { LOG(ERROR) << "FactionInfo objects can not be created during a scenario right now."; destroy(); return; }
foreach(FactionInfo, i, factionInfo)
i->states.push_back(FVF_Neutral);
factionInfo.push_back(this);
for(unsigned int n = 0; n < factionInfo.size(); n++)
states.push_back(FVF_Neutral);
for(unsigned int n = 0; n < factionInfo.size(); n++)
if (factionInfo[n] == this)
states[n] = FVF_Friendly;
}
示例11: findFactionId
unsigned int FactionInfo::findFactionId(string name)
{
for(unsigned int n = 0; n < factionInfo.size(); n++)
if (factionInfo[n]->name == name)
return n;
LOG(ERROR) << "Failed to find faction: " << name;
return 0;
}
示例12: MultiplayerObject
RepairCrew::RepairCrew()
: MultiplayerObject("RepairCrew")
{
ship_id = -1;
position.x = -1;
action = RC_Idle;
direction = ERepairCrewDirection(irandom(RC_Up, RC_Right + 1));
selected = false;
registerMemberReplication(&ship_id);
registerMemberReplication(&position, 1.0);
registerMemberReplication(&target_position);
repairCrewList.push_back(this);
}
示例13: setFriendly
void FactionInfo::setFriendly(P<FactionInfo> other)
{
int id1 = -1;
int id2 = -1;
for(unsigned int n = 0; n < factionInfo.size(); n++)
{
if (factionInfo[n] == this)
id1 = n;
if (factionInfo[n] == other)
id2 = n;
}
if (id1 != -1 && id2 != -1)
{
factionInfo[id1]->states[id2] = FVF_Friendly;
factionInfo[id2]->states[id1] = FVF_Friendly;
}
}
示例14: setFriendly
void FactionInfo::setFriendly(P<FactionInfo> other)
{
if (!other)
{
LOG(WARNING) << "Tried to set a an undefined faction to friendly with " << name;
return;
}
int id1 = -1;
int id2 = -1;
for(unsigned int n = 0; n < factionInfo.size(); n++)
{
if (factionInfo[n] == this)
id1 = n;
if (factionInfo[n] == other)
id2 = n;
}
if (id1 != -1 && id2 != -1)
{
factionInfo[id1]->states[id2] = FVF_Friendly;
factionInfo[id2]->states[id1] = FVF_Friendly;
}
}