void collidePortal(vect3Df_s pr, vect3Df_s sr, portal_s* p, vect3Df_s* point)
{
	vect3Df_s o;
	if(!isPortalInRectangle(pr,sr,p,&o))return;
	vect3Df_s v=vsubf(*point,p->position);

	const vect3Df_s u1=p->plane[0], u2=p->plane[1];

	float xp=vdotf(v,u1)+PORTAL_WIDTH;
	float yp=vdotf(v,u2)+PORTAL_HEIGHT;

	// printf("IN PORTAL ? %f %f\n", xp, yp);
	if(xp<0 || yp<0 || xp>=PORTAL_WIDTH*2 || yp>=PORTAL_HEIGHT*2)return;
	float d1=(xp), d2=(yp), d3=PORTAL_WIDTH*2-(xp), d4=PORTAL_HEIGHT*2-(yp);

	if(d1<d2 && d1<d3 && d1<d4)
	{
		*point=vaddf(*point,vmulf(u1,-d1));
	}else if(d2<d1 && d2<d3 && d2<d4)
	{
		*point=vaddf(*point,vmulf(u2,-d2));
	}else if(d3<d1 && d3<d2 && d3<d4)
	{
		*point=vaddf(*point,vmulf(u1,d3));
	}else{
		*point=vaddf(*point,vmulf(u2,d4));
	}
	// printf("YES %f %f %f %f\n",d1,d2,d3,d4);
}
Beispiel #2
0
void updatePlatform(platform_s* pf, player_s* p)
{
	if(!pf)return;

	if(pf->ao.active)
	{
		if(pf->touched && p->object.position.y>pf->position.y+p->object.radius)
		{
			p->object.position=vaddf(p->object.position,pf->velocity);
		}else if(pf->oldTouched){
			p->object.speed=vaddf(p->object.speed,pf->velocity);
		}

		if(pf->direction)
		{
			if(vdotf(vsubf(pf->position,pf->destination),pf->velocity)>0)
			{
				if(pf->backandforth)
				{
					pf->velocity=vmulf(pf->velocity,-1);
					pf->direction=false;
				}else{
					pf->velocity=vect3Df(0,0,0);
					pf->ao.active=false;
				}
			}
		}else{
			if(vdotf(vsubf(pf->position,pf->origin),pf->velocity)>0)
			{
				pf->velocity=vmulf(pf->velocity,-1);
				pf->direction=true;
			}
		}

		int i;
		for(i=0; i<NUMOBJECTS; i++)
		{
			if(objects[i].used && intersectOBBPlatform(pf, &objects[i]))
			{
				objects[i].position = vaddf(objects[i].position, pf->velocity);
			}
		}

		pf->position=vaddf(pf->position,pf->velocity);
	}

	if(pf->aar)
	{
		pf->aar->position = vaddf(pf->position, vect3Df(-PLATFORMSIZE, PLATFORMHEIGHT, -PLATFORMSIZE));
	}
	
	pf->ao.oldActive=pf->ao.active;
	pf->oldTouched=pf->touched;
	pf->touched=false;
}
Beispiel #3
0
void updateEnergyBall(room_s* r, energyBall_s* eb)
{
	if(!eb)return;
	
	vect3Df_s l=eb->position;
	
	vect3Df_s ip=l, normal;
	rectangle_s* col=collideGridCell(getCurrentCell(r,eb->position), eb->launcher?eb->launcher->surface:NULL, l, eb->direction, eb->speed, &ip, &normal);
	if(!col)col=collideGridCell(getCurrentCell(r,vaddf(eb->position,vmulf(eb->direction,eb->speed))), eb->launcher?eb->launcher->surface:NULL, l, eb->direction, eb->speed, &ip, &normal);
	if(col)
	{
		// printf("COL COL COL %d\n",col->collides);
		energyDevice_s* ed=isEnergyCatcherSurface(col);
		if(ed && !ed->active)
		{
			//caught
			md2InstanceChangeAnimation(&ed->modelInstance,2,false);
			md2InstanceChangeAnimation(&ed->modelInstance,1,true);
			killEnergyBall(eb);
			if(eb->launcher)eb->launcher->active=false;
			ed->active=true;
			return;
		}

		vect3Df_s v=vect3Df(0,0,0);
		float x, y, z;
		portal_s* portal=NULL;
		int i;
		for(i=0; i<NUM_PORTALS && !portal; i++)
		{
			if(isPointInPortal(&portals[i],ip,&v,&x,&y,&z))portal=&portals[i];
			if(portal && fabs(z)>=0.1f)portal=NULL;
		}
		if(portal && !portal->target)portal=NULL;
		if(!portal)
		{
			eb->position=ip;
			eb->direction=vsubf(eb->direction,vmulf(normal,2*vdotf(eb->direction,normal)));
			eb->position=vaddf(eb->position,vmulf(eb->direction,ENERGYBALLSIZE));
		}else if(portal->target && portal->open && portal->target->open){
			eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed));
			warpEnergyBall(portal,eb);
			eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed));
		}

	}else{
		eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed));
	}
	
	md2InstanceUpdate(&eb->modelInstance);
	
	if(!eb->life)killEnergyBall(eb);
	else eb->life--;
}
Beispiel #4
0
void getPortalBoundingBox(portal_s* p, camera_s* c, vect3Di_s* topleft, vect3Di_s* bottomright, float* depth)
{
	if(!p || !topleft || !bottomright || !depth)return;

	vect4Df_s v;
	float mX=1.0f, MX=-1.0f;
	float mY=1.0f, MY=-1.0f;

	*depth = 1000.0f;

	v = projectPointCamera(c, vaddf(p->position, vect3Df(p->plane[0].x*PORTAL_WIDTH+p->plane[1].x*PORTAL_HEIGHT, p->plane[0].y*PORTAL_WIDTH+p->plane[1].y*PORTAL_HEIGHT, p->plane[0].z*PORTAL_WIDTH+p->plane[1].z*PORTAL_HEIGHT)));
	if(v.x < mX) mX = v.x;
	if(v.y < mY) mY = v.y;
	if(v.x > MX) MX = v.x;
	if(v.y > MY) MY = v.y;
	if(*depth > -v.w) *depth = -v.w;

	v = projectPointCamera(c, vaddf(p->position, vect3Df(p->plane[0].x*PORTAL_WIDTH-p->plane[1].x*PORTAL_HEIGHT, p->plane[0].y*PORTAL_WIDTH-p->plane[1].y*PORTAL_HEIGHT, p->plane[0].z*PORTAL_WIDTH-p->plane[1].z*PORTAL_HEIGHT)));
	if(v.x < mX) mX = v.x;
	if(v.y < mY) mY = v.y;
	if(v.x > MX) MX = v.x;
	if(v.y > MY) MY = v.y;
	if(*depth > -v.w) *depth = -v.w;

	v = projectPointCamera(c, vaddf(p->position, vect3Df(-p->plane[0].x*PORTAL_WIDTH-p->plane[1].x*PORTAL_HEIGHT, -p->plane[0].y*PORTAL_WIDTH-p->plane[1].y*PORTAL_HEIGHT, -p->plane[0].z*PORTAL_WIDTH-p->plane[1].z*PORTAL_HEIGHT)));
	if(v.x < mX) mX = v.x;
	if(v.y < mY) mY = v.y;
	if(v.x > MX) MX = v.x;
	if(v.y > MY) MY = v.y;
	if(*depth > -v.w) *depth = -v.w;

	v = projectPointCamera(c, vaddf(p->position, vect3Df(-p->plane[0].x*PORTAL_WIDTH+p->plane[1].x*PORTAL_HEIGHT, -p->plane[0].y*PORTAL_WIDTH+p->plane[1].y*PORTAL_HEIGHT, -p->plane[0].z*PORTAL_WIDTH+p->plane[1].z*PORTAL_HEIGHT)));
	if(v.x < mX) mX = v.x;
	if(v.y < mY) mY = v.y;
	if(v.x > MX) MX = v.x;
	if(v.y > MY) MY = v.y;
	if(*depth > -v.w) *depth = -v.w;

	topleft->x = (mX+1.0f)*240/2;
	topleft->y = (mY+1.0f)*400/2;

	bottomright->x = (MX+1.0f)*240/2;
	bottomright->y = (MY+1.0f)*400/2;

	if(topleft->x < 0) topleft->x = 0;
	if(topleft->y < 0) topleft->y = 0;

	if(bottomright->x > 240) bottomright->x = 240;
	if(bottomright->y > 400) bottomright->y = 400;
}
u8 checkObjectElevatorCollision(physicalPoint_s* o, room_s* r, elevator_s* ev)
{
	if(!o || !r || !ev)return 0;

	u8 ret=0;

	if(collideRectangle(o,vaddf(ev->realPosition,vect3Df(-ELEVATOR_SIZE/2,0,-ELEVATOR_SIZE/2)),vect3Df(ELEVATOR_SIZE,0,ELEVATOR_SIZE)))ret=2;

	vect3Df_s u=vect3Df(o->position.x-ev->position.x,0,o->position.z-ev->position.z);
	float v=vmagf(u);

	if(fabs(o->position.y-ev->position.y)>ELEVATOR_HEIGHT)return ret;

	if(ev->state==ELEVATOR_OPEN)
	{
		switch(ev->direction&(~(1<<ELEVATOR_UPDOWNBIT)))
		{
			case 1:
				if(u.x<-(v*cos(ELEVATOR_ANGLE)))return ret;
				break;
			case 4:
				if(u.z>(v*cos(ELEVATOR_ANGLE)))return ret;
				break;
			case 5:
				if(u.z<-(v*cos(ELEVATOR_ANGLE)))return ret;
				break;
			default:
				if(u.x>(v*cos(ELEVATOR_ANGLE)))return ret;
				break;
		}
	}

	if(v<ELEVATOR_RADIUS_IN)
	{
		if(v+o->radius>=ELEVATOR_RADIUS_IN)
		{
			u=vdivf(vmulf(u,ELEVATOR_RADIUS_IN-o->radius-v),v);
			o->position=vaddf(o->position,u);
			ret=1;
		}
	}else if(v<o->radius+ELEVATOR_RADIUS_OUT)
	{
		u=vdivf(vmulf(u,o->radius+ELEVATOR_RADIUS_OUT-v),v);
		o->position=vaddf(o->position,u);
		ret=1;
	}

	return ret;
}
Beispiel #6
0
void initPlatform(platform_s* pf, room_s* r, vect3Di_s orig, vect3Di_s dest, u8 id, bool BAF)
{
	if(!pf || !r)return;
	
	// orig=vect3Df(orig.x+r->position.x, orig.y, orig.z+r->position.y);
	// dest=vect3Df(dest.x+r->position.x, dest.y, dest.z+r->position.y);

	pf->id=id;
	pf->origin=convertRectangleVector(orig);
	pf->destination=convertRectangleVector(dest);

	pf->position=pf->origin;
	pf->velocity=vdivf(vnormf(vsubf(pf->destination,pf->origin)),16);
	
	pf->direction=true;
	pf->touched=false;
	pf->backandforth=true;
	
	initActivatableObject(&pf->ao);
	pf->ao.active=true;

	pf->aar=createAAR(vaddf(pf->position, vect3Df(-PLATFORMSIZE, PLATFORMHEIGHT, -PLATFORMSIZE)), vect3Df(2*PLATFORMSIZE, 0.0f, 2*PLATFORMSIZE), vect3Df(0.0f, 1.0f, 0.0f));
	
	// addPlatform(id,vmulf(pf->origin,4),vmulf(pf->destination,4),BAF); //TEMP
	
	pf->used=true;
}
void collideObjectRoom(physicalPoint_s* pp, room_s* r)
{
	if(!pp || !r)return;
	vect3Df_s oldPosition = pp->position;

	// float length=vmagf(pp->speed);
	
	bool ret=false;
	
	pp->position = vaddf(pp->position,pp->speed);
	ret = checkObjectCollision(pp, r);
	
	pp->contact=ret;
	
	vect3Df_s os=pp->speed;
	pp->speed=vect3Df(pp->position.x-oldPosition.x, pp->position.y-oldPosition.y, pp->position.z-oldPosition.z);
	pp->speed=vect3Df((os.x*pp->speed.x>0)?(pp->speed.x):(0),(os.y*pp->speed.y>0)?(pp->speed.y):(0),(os.z*pp->speed.z>0)?(pp->speed.z):(0));

	if(pp->contact)
	{
		 //floor friction
		vect3Df_s s=vsubf(pp->speed,vmulf(normGravityVector,vdotf(normGravityVector,pp->speed)));
		pp->speed=vsubf(pp->speed,vdivf(s,2));
	}else{
		//air friction
		vect3Df_s s=vsubf(pp->speed,vmulf(normGravityVector,vdotf(normGravityVector,pp->speed)));
		pp->speed=vsubf(pp->speed,vdivf(s,32));
	}

	if(fabs(pp->speed.x)<0.01f)pp->speed.x=0;
	if(fabs(pp->speed.z)<0.01f)pp->speed.z=0;
}
Beispiel #8
0
void rotatePlayer(player_s* p, vect3Df_s v)
{
	if(!p)return;

	p->tempAngle = vaddf(p->tempAngle, v);
	rotateCamera(&p->camera, v);
}
bool collideRectangle(physicalPoint_s* o, vect3Df_s p, vect3Df_s s)
{
	if(!o)return false;

	vect3Df_s o2 = getClosestPointRectangle(p, s, o->position);

	int i;
	for(i=0; i < NUM_PORTALS; i++)
	{
		if(portals[i].target && portals[i].open && portals[i].target->open)collidePortal(p, s, &portals[i], &o2);
	}

	vect3Df_s v = vsubf(o2, o->position);

	float gval = vdotf(v, normGravityVector);
	vect3Df_s v2 = vsubf(v, vmulf(normGravityVector, gval));
	float sqd = (v2.x*v2.x)+(v2.y*v2.y)+(v2.z*v2.z)+((gval*gval)/ transY);

	if(sqd < o->sqRadius)
	{
		float sqd = (v2.x*v2.x)+(v2.y*v2.y)+(v2.z*v2.z)+(gval*gval)/transY;
		float d = sqrtf(sqd);
		v = vdivf(vmulf(vect3Df(v.x, v.y, v.z), -(o->radius-d)), d);
		o->position = vaddf(o->position, v);
		return true;
	}
	return false;
}
vect3Df_s getClosestPointRectangle(vect3Df_s rectOrigin, vect3Df_s rectSize, vect3Df_s o)
{
	vect3Df_s u1, u2;
	float x,y,sx,sy;
	
	if(rectSize.x){sx=fabs(rectSize.x);u1=vect3Df((rectSize.x>0)?(1.0f):(-(1.0f)),0,0);}
	else{sx=fabs(rectSize.y);u1=vect3Df(0,(rectSize.y>0)?(1.0f):(-(1.0f)),0);}
	
	if(rectSize.z){sy=fabs(rectSize.z);u2=vect3Df(0,0,(rectSize.z>0)?(1.0f):(-(1.0f)));}
	else{sy=fabs(rectSize.y);u2=vect3Df(0,(rectSize.y>0)?(1.0f):(-(1.0f)),0);}
	
	o=vsubf(o, rectOrigin);
	
	x=vdotf(o, u1);
	y=vdotf(o, u2);
	
	bool r=true;

	r=r && x<sx && x>=0;
	r=r && y<sy && y>=0;
	
	if(r)return vaddf(rectOrigin, vect3Df((x*u1.x)+(y*u2.x), (x*u1.y)+(y*u2.y), (x*u1.z)+(y*u2.z)));
	
	if(x<0)
	{
		x=0;
		if(y<0)y=0;
		else if(y>sy)y=sy;
	}else if(x>sx)
	{
		x=sx;
		if(y<0)y=0;
		else if(y>sy)y=sy;
	}else if(y<0)
	{
		y=0;
		if(x<0)x=0;
		else if(x>sx)y=sx;
	}else if(y>sy)
	{
		y=sy;
		if(x<0)x=0;
		else if(x>sx)x=sx;
	}
	
	return vaddf(rectOrigin, vect3Df((x*u1.x)+(y*u2.x), (x*u1.y)+(y*u2.y), (x*u1.z)+(y*u2.z)));
}
Beispiel #11
0
void updatePlayer(player_s* p, room_s* r)
{
	if(!p)return;

	md2InstanceUpdate(&p->gunInstance);
	md2InstanceUpdate(&p->ratmanInstance);
	if(!p->flying) p->object.speed = vaddf(p->object.speed, vmulf(normGravityVector, 0.04f));
	vect3Df_s prevPosition = p->object.position;
	collideObjectRoom(&p->object, r);

	if(p->inPortal && !p->oldInPortal)playSFX(portalEnterSFX[rand()%2]);
	else if(!p->inPortal && p->oldInPortal)playSFX(portalExitSFX[rand()%2]);

	int i;
	for(i=0; i < NUM_PORTALS; i++)
	{
		if(portals[i].target)checkPortalPlayerWarp(p, &portals[i]);
	}

	updateCamera(&p->camera);

	float alignment = -vdotf(vect3Df(p->camera.orientation[0][0],p->camera.orientation[0][1],p->camera.orientation[0][2]), normGravityVector);
	// printf("alignment : %f  \n",alignment);

	{
		if(alignment>0.001)
		{
			if(alignment>0.125)rotateMatrixZ((float*)p->camera.orientation, -0.5f*0.15f, true);
			else if(alignment>0.0625)rotateMatrixZ((float*)p->camera.orientation, -0.25f*0.15f, true);
			else if(alignment>0.03125)rotateMatrixZ((float*)p->camera.orientation, -0.125f*0.07f, true);
		}else if(alignment<-0.001)
		{
			if(alignment<-0.125)rotateMatrixZ((float*)p->camera.orientation, 0.5f*0.15f, true);
			else if(alignment<-0.0625)rotateMatrixZ((float*)p->camera.orientation, 0.25f*0.15f, true);
			else if(alignment<-0.03125)rotateMatrixZ((float*)p->camera.orientation, 0.125f*0.07f, true);
		}
	}
	
	// fixMatrix(c->orientation); //compensate floating point errors

	p->camera.position = vaddf(p->object.position, vect3Df(0.0f, cos(p->walkCnt1)*0.14f, 0.0f));

	if(vmagf(p->object.speed) < 0.03f || !p->object.contact)md2InstanceChangeAnimation(&p->ratmanInstance, 0, false);

	if(p->flying) p->object.speed = vect3Df(0,0,0); //TEMP
	p->tempAngle = vmulf(p->tempAngle, 0.65f);
}
Beispiel #12
0
bool intersectOBBPlatform(platform_s* pf, OBB_s* o)
{
	if(!pf || !o)return false;
	
	vect3Df_s s;
	getBoxAABB(o, &s);

	return intersectAABBAAR(o->position, s, vaddf(pf->position, vect3Df(-PLATFORMSIZE, 1.0f, -PLATFORMSIZE)), vect3Df(PLATFORMSIZE*2,0,PLATFORMSIZE*2));
}
void updateEmancipator(emancipator_s* e)
{
	if(!e || !e->used)return;
	
	e->counter++;
	e->angle+=0.05f;
	e->position=vaddf(e->position,e->velocity);
	if(e->counter>BLACKENINGTIME+FADINGTIME)e->used=false;
}
Beispiel #14
0
bool intersectOBBButton(bigButton_s* bb, OBB_s* o)
{
	if(!bb || !o || !bb->surface)return false;
	
	vect3Df_s s;
	getBoxAABB(o, &s);

	return intersectAABBAAR(o->position, s, vaddf(bb->position, vect3Df(-TILESIZE_FLOAT, 1.0f, -TILESIZE_FLOAT)), vect3Df(TILESIZE_FLOAT*2,0,TILESIZE_FLOAT*2));
}
Beispiel #15
0
void movePlayer(player_s* p, vect3Df_s v)
{
	if(!p)return;

	if(p->object.contact)
	{
		if(fabs(v.z)>0.0f && fabs(v.z)>fabs(v.x))md2InstanceChangeAnimation(&p->ratmanInstance, 3, false);
		else if((v.x)<0.0f)md2InstanceChangeAnimation(&p->ratmanInstance, 4, false);
		else if((v.x)>0.0f)md2InstanceChangeAnimation(&p->ratmanInstance, 5, false);
	}

	p->object.speed = vaddf(p->object.speed, moveCameraVector(&p->camera, v, p->flying));
}
bool checkObjectCollision(physicalPoint_s* o, room_s* r)
{	
	bool ret=false;

	gridCell_s* gc = getCurrentCell(r, o->position);

	// listCell_s* l = r->rectangles.first;
	// while(l)
	// {
	// 	if(l->data.collides)
	// 	{
	// 		l->data.touched = collideRectangle(o, convertRectangleVector(l->data.position), convertRectangleVector(l->data.size));
	// 		ret = l->data.touched || ret;
	// 	}
	// 	l = l->next;
	// }

	int i;
	for(i=0;i<gc->numRectangles;i++)
	{
		rectangle_s* rec=gc->rectangles[i];
		if(rec->collides)
		{
			rec->touched = collideRectangle(o, convertRectangleVector(rec->position), convertRectangleVector(rec->size));
			ret = rec->touched || ret;
		}
	}

	//platforms
	for(i=0;i<NUMPLATFORMS;i++)
	{
		if(platform[i].used && collideRectangle(o,vaddf(platform[i].position,vect3Df(-PLATFORMSIZE,0,-PLATFORMSIZE)),vect3Df(PLATFORMSIZE*2,0,PLATFORMSIZE*2))) //add culling
		{
			platform[i].touched=true;
			ret=true;
		}
	}

	//elevators
	u8 val=0;
	if((entryWallDoor.used && checkObjectElevatorCollision(o,r,&entryWallDoor.elevator)) || (exitWallDoor.used && (val=checkObjectElevatorCollision(o,r,&exitWallDoor.elevator))))ret=true;
	if(val==2)closeElevator(&exitWallDoor.elevator);
	
	//timed buttons
	if(checkObjectTimedButtonsCollision(o,r))ret=true;

	return ret;
}
Beispiel #17
0
bool collideLineRectangle(rectangle_s* rec, vect3Df_s o, vect3Df_s v, float d, float* kk, vect3Df_s* ip)
{
	if(!rec)return false;
	vect3Df_s n=vect3Df(fabs(rec->normal.x),fabs(rec->normal.y),fabs(rec->normal.z));
	float p1=vdotf(v,n);
	if(fabs(p1)>0.001f)
	{
		vect3Df_s p = convertRectangleVector(rec->position);
		vect3Df_s s = convertRectangleVector(rec->size);
		
		float p2=vdotf(vsubf(p,o),n);

		float k=p2/p1;
		s8 sign=((s.x>0)^(s.y<0)^(s.z>0)^(p1<0))?(-1):(1);
		if(kk)
		{
			*kk=k+sign;
		}
		if(k<0 || k>d){return false;}
		vect3Df_s i=vaddf(o,vmulf(v,k));
		if(ip)*ip=i;
		i=vsubf(i,p);
		
		bool r=true;
		if(s.x)
		{
			if(s.x>0)r=r&&i.x<s.x&&i.x>=0;
			else r=r&&i.x>s.x&&i.x<=0;
		}
		if(s.y)
		{
			if(s.y>0)r=r&&i.y<s.y&&i.y>=0;
			else r=r&&i.y>s.y&&i.y<=0;
		}
		if(s.z)
		{
			if(s.z>0)r=r&&i.z<s.z&&i.z>=0;
			else r=r&&i.z>s.z&&i.z<=0;
		}
		return r;
	}
	return false;
}
Beispiel #18
0
void warpPlayer(portal_s* p, player_s* pl)
{
	if(!p || !pl)return;
	camera_s* c = &pl->camera;

	camera_s new_camera = *c;

	if(gravityGunObject)gravityGunObject = NULL; // TEMP : TODO better solution

	float tmp1[4*4], tmp2[4*4];
	transposeMatrix44(p->target->matrix, tmp1);
	new_camera.position = vaddf(p->target->position, warpPortalVector(p, vsubf(c->position, p->position)));
	multMatrix44((float*)new_camera.orientation, p->matrix, tmp2);
	rotateMatrixY(tmp1, M_PI, true);
	multMatrix44(tmp2, tmp1, (float*)new_camera.orientation);

	memcpy(new_camera.modelview, new_camera.orientation, sizeof(mtx44));
	translateMatrix((float*)new_camera.modelview, -new_camera.position.x, -new_camera.position.y, -new_camera.position.z);

	pl->object.position = new_camera.position;
	pl->object.speed = warpPortalVector(p, pl->object.speed);
	*c = new_camera;
}
Beispiel #19
0
void updateEnergyDevice(energyDevice_s* ed)
{
	if(!ed)return;
	
	if(ed->type)
	{
		//launcher
		if(ed->active)
		{
			md2InstanceChangeAnimation(&ed->modelInstance,1,true);
			createEnergyBall(ed, vaddf(ed->position, vdivf(energyDeviceDirection[ed->orientation],8)), energyDeviceDirection[ed->orientation], 800);
			ed->active=false;
		}
	}else{
		//receiver
		if(ed->active)
		{
			ed->modelInstance.texture=&energyLauncherActiveTexture;
			useActivator(&ed->activator);
		}
	}
	
	md2InstanceUpdate(&ed->modelInstance);
}
Beispiel #20
0
void shootPlayerGun(player_s* p, room_s* r, portal_s* portal)
{
	if(!p)return;
	if(p->gunInstance.currentAnim == PORTALGUN_SHOOT)return;

	md2InstanceChangeAnimation(&p->gunInstance, PORTALGUN_IDLE, false);
	md2InstanceChangeAnimation(&p->gunInstance, PORTALGUN_SHOOT, true);

	vect3Df_s position;
	rectangle_s* rec = collideLineMapClosest(r, NULL, p->camera.position, vect3Df(-p->camera.orientation[2][0], -p->camera.orientation[2][1], -p->camera.orientation[2][2]), 1000.0f, &position, NULL);
	if(rec && rec->portalable)
	{
		portal_s oldPortal = *portal;
		vect3Df_s normal = rec->normal;
		vect3Df_s plane0 = vect3Df(p->camera.orientation[0][0], p->camera.orientation[0][1], p->camera.orientation[0][2]);
		plane0 = vnormf(vsubf(plane0, vmulf(normal, vdotf(normal, plane0))));

		position = vaddf(position, vmulf(normal, -0.05f));

		portal->position = position;

		updatePortalOrientation(portal, plane0, normal);
		isPortalOnWall(r, portal, true);

		portal->draw = true;
		portal->open = true;

		if(isPortalOnWall(r, portal, false))
		{
			ejectPortalOBBs(portal);
			ejectPortalOBBs(portal->target);
		}else{
			*portal = oldPortal;
		}
	}
}
Beispiel #21
0
void updateControls(player_s* p)
{
	circlePosition cpad;
	circlePosition cstick;
	
	hidCircleRead(&cpad);
	irrstCstickRead(&cstick);

	rotatePlayer(p, vect3Df((abs(cstick.dy)<5)?0:(-cstick.dy*0.001f), (abs(cstick.dx)<5)?0:(cstick.dx*0.001f), 0.0f));

	if(abs(cpad.dx) > 15 || abs(cpad.dy) > 15) //dead zone
	{
		float factor = 0.0015f;

		if(p->flying)factor*=2;
		else if(!p->object.contact)factor*=0.06f;
		else updatePlayerWalk(p, cpad.dy*factor*2, cpad.dx*factor);

		movePlayer(p, vect3Df(cpad.dx*factor, 0.0f, -cpad.dy*factor));
	}

	if(keysDown()&KEY_ZL)
	{
		// "USE" key
		vect3Df_s u = moveCameraVector(&p->camera, vect3Df(0.0f, 0.0f, -1.0f), true);
		timedButton_s* tb = collideRayTimedButtons(p->object.position, u, TILESIZE_FLOAT*2);
		if(tb)
		{
			activateTimedButton(tb);
		}else{
			OBB_s* o = collideRayBoxes(p->object.position, u, TILESIZE_FLOAT*4);
			if(o)
			{
				gravityGunObject = o;
			}
		}
	}

	if(keysDown()&KEY_ZR)
	{
		// JUMP key
		if(p->object.contact)
		{
			p->object.speed.y += 0.6f;			
		}
	}

	if(gravityGunObject)
	{
		if(!(keysHeld()&KEY_ZL))
		{
			gravityGunObject = NULL;
			md2InstanceChangeAnimation(&p->gunInstance, 0, false);
			md2InstanceChangeAnimation(&p->gunInstance, 1, true);
		}else{
			const vect3Df_s u = moveCameraVector(&p->camera, vect3Df(0.0f, 0.0f, -5.0f), true);
			const vect3Df_s t = vaddf(u, p->object.position);
			const vect3Df_s v = vmulf(vsubf(t, gravityGunObject->position), 1.75f);
			setObbVelocity(gravityGunObject, v);
			md2InstanceChangeAnimation(&p->gunInstance, 2, false);
		}
	}else if(p->gunInstance.currentAnim == 2){
		md2InstanceChangeAnimation(&p->gunInstance, 0, false);
		md2InstanceChangeAnimation(&p->gunInstance, 1, true);
	}
}
Beispiel #22
0
void warpEnergyBall(portal_s* p, energyBall_s* eb)
{
	if(!p->target)return;
	eb->position=vaddf(warpPortalVector(p,vsubf(eb->position,p->position)),p->target->position);
	eb->direction=warpPortalVector(p,eb->direction);
}