예제 #1
0
void Camera::lookAt(const Point<double> &target)
{
    Vd dir = ~Vd(target-origin);

    double len = sqrt(dir.x * dir.x + dir.y * dir.y);
    double pitch = atan2(dir.z, len);
    double pan = atan2(dir.x, dir.y);

    objective = Qd(Rd(-pitch, Vd(1, 0, 0))) * Qd(Rd(pan, Vd(0, 0, 1)));

}
예제 #2
0
Cuboid::Cuboid(Pd origin, double S)
	: BoundedObject(origin, Qd(), BoundingBox(), Assets::Test),
	  u(Vd(S,0,0)),
	  v(Vd(0,S,0)),
	  w(Vd(0,0,S))
{
	bb.lbl = origin         ;
	bb.rbl = origin +u      ;
	bb.ltl = origin    +v   ;
	bb.rtl = origin +u +v   ;
	bb.lbh = origin       +w;
	bb.rbh = origin +u    +w;
	bb.lth = origin    +v +w;
	bb.rth = origin +u +v +w;
}
예제 #3
0
파일: movement.cpp 프로젝트: FerryT/OGO-2.3
void Controller::lookZ(double speed)
{
	speed *= LookSpeed;
	speed *= FRATE;

    Qd buffer = camAngle;//Used to rollback if out of bounds

	Vector<double> mystery = ~(camAngle * Vector<double>(0,1,0));
	double mysteryYaw = atan2(mystery.x, mystery.y);

	camAngle = Qd(Rd(speed, Vd(cos(mysteryYaw),-sin(mysteryYaw),0))) * camAngle;
       if((camAngle*Vector<double>(0,1,0)).z > 0.99 || (camAngle*Vector<double>(0,1,0)).z < -0.99){
           camAngle = buffer;
           return;
       }
	Vector<double> vec = ~(camAngle * Vector<double>(0,1,0));

	if (firstPerson == true)
	{
		camera.origin = player->origin + Pd(0,0,2.5) + vec;
		camera.lookAt(camera.origin + (vec * 5.0));
	}
	else
	{
		camera.origin = target - (vec * zoom);
		camera.lookAt(target);
	}
}
예제 #4
0
void Cuboid::draw()
{
	#define Vert(v) { Pd vt = (v); glVertex3d(vt.x,vt.y,vt.z); }
	#define Norm(u,v) { Vd n = ~((u)*(v)); glNormal3d(n.x,n.y,n.z); }
	#define A { glTexCoord2d(0.0,0.0); }
	#define B { glTexCoord2d(1.0,0.0); }
	#define C { glTexCoord2d(1.0,1.0); }
	#define D { glTexCoord2d(0.0,1.0); }

	Pd o = Vd(0,0,0);
	Pd a = o + u + v + w;

	glBegin(GL_QUADS);
		Norm(u,w); A Vert(o); B Vert(o+u); C Vert(o+u+w); D Vert(o+w);
		Norm(v,u); A Vert(o); B Vert(o+v); C Vert(o+v+u); D Vert(o+u);
		Norm(w,v); A Vert(o); B Vert(o+w); C Vert(o+w+v); D Vert(o+v);
		Norm(u,v); A Vert(a); B Vert(a-u); C Vert(a-u-v); D Vert(a-v);
		Norm(v,w); A Vert(a); B Vert(a-v); C Vert(a-v-w); D Vert(a-w);
		Norm(w,u); A Vert(a); B Vert(a-w); C Vert(a-w-u); D Vert(a-u);
	glEnd();

	#undef Vert
	#undef Norm
	#undef A
	#undef B
	#undef C
	#undef D
}
void FsGuiColorDialog::UpdateHSVSliderFromCurrentColor(void)
{
	auto col=GetCurrentColor();
	hueSlider->SetPosition(col.Hd());
	saturationSlider->SetPosition(col.Sd());
	valueSlider->SetPosition(col.Vd());
}
예제 #6
0
파일: world.cpp 프로젝트: FerryT/OGO-2.3
void Droppable::preRender(){
	Object::preRender();
	int timelived = Video::ElapsedTime() - dropped;
	if(timelived >= ttl){
		done = true;
		return;
	}
	rotation = rotation * Rd(0.02, Vd(0,0,1));
}
예제 #7
0
//----------------------------------------------------------------------
bool observer::Contract(box& P)	{

	vector<box> L;
	vector<box> Pi(N_window);
	Pi[N_window-1]=P;

	// Dans ce qui suit, on recopie les listes dans des vecteurs pour avoir un accès direct (c'est pas terrible, mais je ne sais pas faire autrement)
	// Je sais qu'il existe une classe qui permet de faire une liste-vecteur, mais je ne sais pas son nom.
	vector<double>   Vu1(N_window);     list<double>::iterator iLu1=Lu1.begin();       for(int i=0;i<N_window;i++)  {Vu1[i]=*iLu1;       iLu1++;};
	vector<double>   Vu2(N_window);     list<double>::iterator iLu2=Lu2.begin();       for(int i=0;i<N_window;i++)  {Vu2[i]=*iLu2;       iLu2++;};
	vector<double>   Valpha(N_window);  list<double>::iterator iLalpha=Lalpha.begin(); for(int i=0;i<N_window;i++)  {Valpha[i]=*iLalpha; iLalpha++;}
	vector<interval> Vd(N_window);      list <interval>::iterator iLd=Ld.begin();      for(int i=0;i<N_window;i++)  {Vd[i]=*iLd;         iLd++;}
	vector<box>      VXhat(N_window-1); list <box>::iterator iLXhat=LXhat.begin();     for(int i=0;i<N_window-1;i++){VXhat[i]=*iLXhat;   iLXhat++;}

	for  (int i=N_window-2;i>=0;i--)	{
		Pi[i]=box(4);
		Decremente(Pi[i+1][1],Pi[i+1][2],Pi[i+1][3],Pi[i+1][4],Pi[i][1],Pi[i][2],Pi[i][3],Pi[i][4],Vu1[i],Vu2[i]);
		Pi[i]=Inter(Pi[i],VXhat[i]);
	}

	for  (int i=0;i<N_window;i++)	{
		interval xi=Pi[i][1];       interval yi=Pi[i][2];
		interval thetai=Pi[i][3];   interval vi=Pi[i][4];
		interval betai=Valpha[i]+thetai;
		interval di=Vd[i];
		CLegOnWallsOrCircles(di,xi,yi,betai,murs_xa,murs_ya,murs_xb,murs_yb,cercles_x,cercles_y,cercles_r);
		Cplus(betai,Valpha[i],thetai,-1);
		interval xip,yip,thetaip,vip;
		for  (int i1=i;i1<N_window-1;i1++)	{     
			Incremente(xip,yip,thetaip,vip,xi,yi,thetai,vi,Vu1[i1],Vu2[i1]);
			xip=Inter(xip,Pi[i1+1][1]);yip=Inter(yip,Pi[i1+1][2]);
			thetaip=Inter(thetaip,Pi[i1+1][3]);vip=Inter(vip,Pi[i1+1][4]);
			xi=xip; yi=yip; thetai=thetaip; vi=vip;
		}
		box Pb(P);
		Pb[1]=xi; Pb[2]=yi; Pb[3]=thetai; Pb[4]=vi;
		L.push_back(Pb);
	}
	vector<box> Lv=L;
	C_q_in(P,N_window-N_outliers,Lv);

	return true;
}
예제 #8
0
파일: movement.cpp 프로젝트: FerryT/OGO-2.3
void Controller::frame()
{
	if (move[dirY] != 0.0) moveY(move[dirY]);
	if (move[dirZ] != 0.0) moveZ(move[dirZ]);
	
	if (look[dirX] != 0.0) lookX(look[dirX]);
	if (look[dirY] != 0.0) lookY(look[dirY]);
	if (look[dirZ] != 0.0) lookZ(look[dirZ]);
	
	if (move[dirY] != 0.0)
	{
		if ((move[dirX] < 0.0 && move[dirY] > 0.0)
		||  (move[dirX] > 0.0 && move[dirY] < 0.0))
			player->rotation = player->rotation * Rd(-0.05,Vd(0,0,1));
		else if ((move[dirX] > 0.0 && move[dirY] > 0.0)
		     ||  (move[dirX] < 0.0 && move[dirY] < 0.0))
			player->rotation = player->rotation * Rd(0.05,Vd(0,0,1));
		else
		{
            Vd camv = camAngle*Vd(0,1,0);
            Vd plav = player->rotation*Vd(0,1,0);
            camv.z = 0; camv = ~camv;
            plav.z = 0; plav = ~plav;
            double angle = atan2(camv.y - plav.y, camv.x - plav.x);
            double angle2 = (angle < 0? -angle : angle);
            double axis = angle2 >  0.5*Pi ^ angle > 0? 1 : -1;
            angle2 = angle2 > 0.5*Pi ? Pi - angle2 : angle2;
            angle2 = angle2 < 0.05? angle2 : 0.05;
			if (axis != 0)
                player->rotation = player->rotation * Rd(-angle2,Vd(0,0,axis));
		}
	}
	Vector<double> vec = (-player->rotation * Vector<double>(0,1,0));
	vec.z = 0;
	vec = ~vec;
	double yaw = atan2(vec.x, vec.y);
	target = player->origin + Pd(.75 * sin(yaw - .25*Pi), .75 * cos(yaw-.25*Pi), 2);
	vec = ~(camAngle * Vector<double>(0,1,0));
	if (firstPerson)
	{
		camera.lookAt(camera.origin + (vec * 5.0));
	}
	else
	{
		camera.lookAt(target);
	}
	Objects::Player * p = TO(Objects::Player,player);
	p->velocity = Vd(0,MoveSpeed,0);
}
예제 #9
0
파일: movement.cpp 프로젝트: FerryT/OGO-2.3
void Controller::lookX(double speed)
{
	speed *= -LookSpeed;
	speed *= FRATE;

	camAngle = Qd(Rd(speed, Vd(0,0,1))) * camAngle;

	Vector<double> vec = ~(camAngle * Vector<double>(0,1,0));

	if (firstPerson == true)
	{
		camera.origin = player->origin + Pd(0,0,2.5) + vec;
		camera.lookAt(camera.origin + (vec * 5.0));
	}
	else
	{
		camera.origin = target - (vec * zoom);
		camera.lookAt(target);
	}
}
예제 #10
0
void LaserBeam::draw(){
	glBegin(GL_LINES);
		glVertex3f(0.0, 0.0, 0.0);
		Vd dir = -direction*Vd(0, 1, 0);
		Vd endpoint;
		if (collision < 38.0)
		{
			endpoint = ~dir*collision;
		}
		else
		{
			endpoint = ~dir*39.5;
		}
		glVertex3f(endpoint.x, endpoint.y, endpoint.z);
	glEnd();

	if (collision < 38.0)
	{
		glPushMatrix();
		glTranslatef(endpoint.x, endpoint.y, endpoint.z);
		glutSolidSphere(0.1, 15, 15);
		glPopMatrix();
	}
}
예제 #11
0
파일: game.cpp 프로젝트: timvdalen/OGO-2.3
void Fire()
{
	if (!game.input->grabbing) return; // Ignore when not selected
	if (!NetCode::TryLock())
	{
		game.firing = true;
		return;
	}
	game.firing = false;
	switch (game.player->weapon)
	{
		case weapWrench:
			Build();
			return;
		case weapLaser:
		{
		        Camera &cam = game.controller->camera;
			Vd vec = ~(game.player->rotation * Vd(0,1,0));
			double yaw = atan2(vec.x, vec.y);
			Pd gunLoc = game.player->origin;// + game.player->model.weapon->origin;
			gunLoc.x = gunLoc.x + game.player->model.weapon->origin.x * cos(yaw)
			                    + game.player->model.weapon->origin.y * sin(yaw);
			gunLoc.y = gunLoc.y + game.player->model.weapon->origin.x * sin(yaw)
			                    + game.player->model.weapon->origin.y * cos(yaw);
			gunLoc.z = gunLoc.z + game.player->model.weapon->origin.z;
			
			Vd lookVec = (~(Vd(game.controller->target)+ -Vd(cam.origin))) * 38;
			Pd target = game.controller->target;
			ObjectHandle collision;
			if(game.controller->firstPerson){
				lookVec = (~(game.controller->camAngle * Vd(0,1,0)))*38;
				collision = game.world->trace(game.controller->camera.origin, lookVec, game.player);
			}else{
				collision = game.world->trace(game.controller->target, lookVec, game.player);
			}
			if (collision)
			{	
				Pd collisionPoint;
				if(game.controller->firstPerson){
					collisionPoint = game.controller->camera.origin + (lookVec);
				}else{
					collisionPoint = game.controller->target + (lookVec);
				}
				Qd beam = gunLoc.lookAt(collisionPoint);
				
				ObjectHandle laser = LaserBeam(gunLoc, beam, !lookVec);
				game.world->addLaserBeam(laser);
				NetCode::Fire(*TO(LaserBeam,laser));
				Player *p = TO(Player, collision);
				if(p){
					//if(p->team != game.player->team){//Precent teamkill
						p->damage(10.0, game.player->id);
						NetCode::Hit(p->id, 10.0, true);
					//}
				}else{
					Building *b = TO(Building, collision);
					if(b){
						/* Enable team kill on towers to demolish
						Player *own = NULL;
						if(Game::game.players.count(t->owner))
							own = TO(Player, Game::game.players[t->owner]); 
						if(own && own->team != game.player->team){*/
							b->damage(10.0, game.player->id);
							NetCode::Attack(b->loc, 10.0, true);
						//}
					}
				}
			}
			else{
				game.world->addLaserBeam(ObjectHandle(LaserBeam(gunLoc, cam.objective, !lookVec)));
			}
			return;
		}
		break;
	}
}
예제 #12
0
파일: world.cpp 프로젝트: FerryT/OGO-2.3
Point<double> World::getCorrectedOrigin(Qd q, Pd p){
    #define LOWERBOUND 0.25
	#define ZLEVEL 10
	#define ZLEVEL2 10
	#define INTRNBND GRID_SIZE/5.0
	#define newp (p + (v*lambda))
	Vd v = q*Vd(0,1,0);
	double lambda = 0;
	//Correctoutside
    if(p.z < LOWERBOUND && v.z != 0){
		lambda = (-(p.z-LOWERBOUND)/v.z);
	}
	if(p.x < -width/2 + LOWERBOUND && v.x != 0){
		lambda = max(lambda, (-(width/2 + p.x- LOWERBOUND)/v.x));
	}
	if(p.x > width/2 - LOWERBOUND && v.x != 0){
		lambda = max(lambda, (-(p.x + LOWERBOUND -width/2)/v.x));
	}
	if(p.y < -height/2 + LOWERBOUND && v.y != 0){
		lambda = max(lambda, (-(height/2 + p.y- LOWERBOUND)/v.y));
	}
	if(p.y > height/2 - LOWERBOUND && v.y != 0){
		lambda = max(lambda, (-(p.y + LOWERBOUND -height/2)/v.y));
	}
	map<GridPoint, ObjectHandle> *structs = &terrain->structures;
	map<GridPoint, ObjectHandle>::iterator itt;
	if(p.z < ZLEVEL2){
		for(itt = structs->begin(); itt != structs->end(); itt++){
			GridPoint gp = itt->first;
	        double worldx = GRID_SIZE*gp.x - (width)/2;
    	    double worldy = GRID_SIZE*gp.y - (height)/2;
			double sigma = 100000.0;
			double buff;
			if((worldx + INTRNBND -LOWERBOUND) < p.x && p.x < (worldx + GRID_SIZE + LOWERBOUND -  INTRNBND)
          		 && (worldy + INTRNBND- LOWERBOUND) < p.y && p.y < (worldy - INTRNBND + GRID_SIZE + LOWERBOUND)){
				buff = (-(p.z-ZLEVEL2)/v.z);
				if(0 < buff && buff < sigma){
					sigma = buff;
				}
				buff = (-(p.x-worldx - INTRNBND+ LOWERBOUND)/v.x);
				if(0 < buff && buff < sigma){
					sigma = buff;
				}
				buff = (-(p.x-worldx + INTRNBND -GRID_SIZE- LOWERBOUND)/v.x);
				if(0 < buff && buff < sigma){
					sigma = buff;
				}
				buff = (-(p.y-worldy- INTRNBND + LOWERBOUND)/v.y);
				if(0 < buff && buff < sigma){
					sigma = buff;
				}
				buff = (-(p.y-worldy+INTRNBND -GRID_SIZE-LOWERBOUND)/v.y);
				if(0 < buff && buff < sigma){
					sigma = buff;
				}
				lambda = max(lambda,sigma);
			}
			sigma = 1000000;
			if(p.z < ZLEVEL || newp.z < ZLEVEL){
				if(((worldx - LOWERBOUND) < p.x && p.x < (worldx + GRID_SIZE + LOWERBOUND)
          		 && (worldy - LOWERBOUND) < p.y && p.y < (worldy + GRID_SIZE + LOWERBOUND))
				 || 
				 ((worldx - LOWERBOUND) < newp.x && newp.x < (worldx + GRID_SIZE + LOWERBOUND)
          		 && (worldy - LOWERBOUND) < newp.y && newp.y < (worldy + GRID_SIZE + LOWERBOUND))){
					buff = (-(p.z-ZLEVEL)/v.z);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					buff = (-(p.x-worldx + LOWERBOUND)/v.x);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					buff = (-(p.x-worldx-GRID_SIZE- LOWERBOUND)/v.x);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					buff = (-(p.y-worldy+LOWERBOUND)/v.y);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					buff = (-(p.y-worldy-GRID_SIZE-LOWERBOUND)/v.y);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					if(sigma != 1000000) lambda = max(lambda,sigma);
				sigma = 100000.0;
				if((worldx + INTRNBND -LOWERBOUND) < newp.x && newp.x < (worldx + GRID_SIZE + LOWERBOUND -  INTRNBND)
          			 && (worldy + INTRNBND- LOWERBOUND) < newp.y && newp.y < (worldy - INTRNBND + GRID_SIZE + LOWERBOUND)){
					buff = (-(p.z-ZLEVEL2)/v.z);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					buff = (-(p.x-worldx - INTRNBND+ LOWERBOUND)/v.x);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					buff = (-(p.x-worldx + INTRNBND -GRID_SIZE- LOWERBOUND)/v.x);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					buff = (-(p.y-worldy- INTRNBND + LOWERBOUND)/v.y);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					buff = (-(p.y-worldy+INTRNBND -GRID_SIZE-LOWERBOUND)/v.y);
					if(lambda < buff && buff < sigma){
						sigma = buff;
					}
					if(sigma != 100000.0) lambda = max(lambda,sigma);
					}
				}
			}

		}
	}
	p = p + (v*lambda);
	return p;
	#undef newp
	#undef INTRNBND
	#undef ZLEVEL
	#undef ZLEVEL2
	#undef LOWERBOUND
}
예제 #13
0
TEST(Array, CrossConstruct1) {
    vector<int> Vi(3);
    Vi() = 3;
    vector<double> Vd(Vi);
    EXPECT_ARRAY_NEAR(Vd, Vi);
}
예제 #14
0
파일: core.cpp 프로젝트: FerryT/OGO-2.3
Rotation<double> ToRotation(const string &str) { Rotation<double> r = Rd(0, Vd(0,0,1));
	sscanf(str.c_str(), "R%lf,%lf,%lf,%lf", &r.a, &r.v.x, &r.v.y, &r.v.z); return r; }