Beispiel #1
0
//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;
}
Beispiel #2
0
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);
  }
Beispiel #3
0
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;
}
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;
}
Beispiel #5
0
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;
}
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;
}
Beispiel #7
0
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);
}
Beispiel #8
0
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);
}
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;
    }
}
Beispiel #10
0
PlayerInfo::PlayerInfo()
: MultiplayerObject("PlayerInfo")
{
    clientId = -1;
    main_screen_control = false;
    registerMemberReplication(&clientId);

    for(int n=0; n<maxCrewPositions; n++)
    {
        crew_position[n] = false;
        registerMemberReplication(&crew_position[n]);
    }
    registerMemberReplication(&ship_id);
    registerMemberReplication(&main_screen_control);
    
    playerInfoList.push_back(this);
}
Beispiel #11
0
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;
}
Beispiel #12
0
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;
    }
}
Beispiel #13
0
void GuiViewport3D::onDraw(sf::RenderTarget& window)
{
#if FEATURE_3D_RENDERING
    if (my_spaceship)
        soundManager->setListenerPosition(my_spaceship->getPosition(), my_spaceship->getRotation());
    else
        soundManager->setListenerPosition(sf::Vector2f(camera_position.x, camera_position.y), camera_yaw);
    window.pushGLStates();

    billboardShader->setParameter("camera_position", camera_position);

    float camera_fov = 60.0f;
    float sx = window.getSize().x * window.getView().getViewport().width / window.getView().getSize().x;
    float sy = window.getSize().y * window.getView().getViewport().height / window.getView().getSize().y;
    glViewport(rect.left * sx, (float(window.getView().getSize().y) - rect.height - rect.top) * sx, rect.width * sx, rect.height * sy);

    glClearDepth(1.f);
    glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glDepthMask(GL_TRUE);
    glEnable(GL_CULL_FACE);
    glColor4f(1,1,1,1);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    _glPerspective(camera_fov, rect.width/rect.height, 1.f, 25000.f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    glRotatef(90, 1, 0, 0);
    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);
    }
Beispiel #14
0
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 ) {
            ++errorFlag;
        }

    }
    catch (std::logic_error err) {
        *outStream << err.what() << "\n";
        errorFlag = -1000;
    }; // end try

    if (errorFlag != 0)
        std::cout << "End Result: TEST FAILED\n";
    else
        std::cout << "End Result: TEST PASSED\n";

    return 0;


}
Beispiel #15
0
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);
	}
}