示例#1
0
文件: turrets.c 项目: Almamu/portalDS
void laserProgression(room_struct* r, vect3D* origin, vect3D* destination, vect3D dir)
{
	if(!r || !origin || !destination)return;
	vect3D ip;
	vect3D l=*origin;
	vect3D v=vectDifference(addVect(l,vectMult(dir,32)),convertSize(vect(r->position.x,0,r->position.y)));
	gridCell_struct* gc=getCurrentCell(r,l);
	while(gc && !collideGridCell(gc, NULL, v, dir, inttof32(100), &ip, NULL))
	{
		l=addVect(l,vectMult(dir,CELLSIZE*TILESIZE*2));
		gc=getCurrentCell(r,l);
	}
	if(gc)*destination=addVect(ip,convertSize(vect(r->position.x,0,r->position.y)));
}
示例#2
0
文件: polygon.c 项目: Almamu/portalDS
polygon_struct* createEllipse(vect3D po, vect3D v1, vect3D v2, int n)
{
	int i;
	polygon_struct *p, *pp;
	p=pp=createPolygon(addVect(po,v1));
	if(!p)return NULL;
	for(i=1;i<n;i++)
	{
		const u16 a1=i*32768/n;
		vect3D v=addVect(po,addVect(vectMult(v1,cosLerp(a1)),vectMult(v2,sinLerp(a1))));
		p->next=createPolygon(v);
		p=p->next;
		if(!p)return NULL;
	}
	return pp;
}
示例#3
0
文件: polygon.c 项目: Almamu/portalDS
vect3D intersectSegmentPlane(plane_struct* pl, vect3D o, vect3D v, int32 d)
{
	if(!pl)return o;
	vect3D n=vect(pl->A,pl->B,pl->C);
	int32 p1=dotProduct(v,n);

	vect3D p=pl->point;		
	int32 p2=dotProduct(vectDifference(p,o),n);
	int32 k=divf32(p2,p1);
	return addVect(o,vectMult(v,k));
}
示例#4
0
bool collideLinePlane(vect3D p, vect3D n, vect3D o, vect3D v, vect3D* ip)
{
	int32 p1=dotProduct(v,n);
	if(!equals(p1,0))
	{		
		int32 p2=dotProduct(vectDifference(p,o),n);
		int32 k=divf32(p2,p1);
		if(ip)*ip=addVect(o,vectMult(v,k));
		return true;
	}
	return false;
}
示例#5
0
bool collideLineRectangle(rectangle_struct* rec, vect3D o, vect3D v, int32 d, int32* kk, vect3D* ip)
{
	if(!rec)return false;
	vect3D n=vect(abs(rec->normal.x),abs(rec->normal.y),abs(rec->normal.z));
	int32 p1=dotProduct(v,n);
	if(!equals(p1,0))
	{
		vect3D p=convertVect(rec->position); //CHECK lightmap generation ?
		vect3D s=vect(rec->size.x*TILESIZE*2,rec->size.y*HEIGHTUNIT,rec->size.z*TILESIZE*2);
		
		int32 p2=dotProduct(vectDifference(p,o),n);

		int32 k=divf32(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;}
		vect3D i=addVect(o,vectMult(v,k));
		if(ip)*ip=i;
		i=vectDifference(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;
}
示例#6
0
bool collideLineConvertedRectangle(vect3D n, vect3D p, vect3D s, vect3D o, vect3D v, int32 d, int32* kk, vect3D* ip)
{
	int32 p1=dotProduct(v,n);
	if(!equals(p1,0))
	{
		int32 p2=dotProduct(vectDifference(p,o),n);

		int32 k=divf32(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;}
		vect3D i=addVect(o,vectMult(v,k));
		if(ip)*ip=i;
		i=vectDifference(i,p);
		NOGBA("I %d %d %d",i.x,i.y,i.z);
		NOGBA("S %d %d %d",s.x,s.y,s.z);
		
		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;
}
示例#7
0
int main (int argc, const char * argv[])
{
    printf("Hello, World!\n");
    printf("\n    MVector Version %d Test Harness\n\n",MVECTOR_VERSION_NUM);
    
    VectorH a;
    VectorH b;
    VectorH c;
    VectorH ans;
    double dans;
    
    a = vectCreate(1,2,3);
    b = vectCreate(4,5,6);
    if(vectEquals(a, a)){
        printf("vectEquals: Test passed\n");
    }else{
        printf("vectEquals: Test Failed\n");
        exit(0);
    }
    
    if(vectNotEqual(a, b)){
        printf("vectNotEqual: Test passed\n");
    }else{
        printf("vectNotEqual: Test Failed\n");
        exit(0);
    }
       
    c = vectAdd(a, b);
    ans = vectCreate(5, 7, 9);
    if(vectEquals(c, ans)){
        printf("vectEquals: Test passed\n");
    }else{
        printf("vectEquals: Test Failed\n");
        exit(0);
    }

    ans = vectCreate(11, 12, 13);
    c = vectAddScaler(a, 10);
    if(vectEquals(c, ans)){
        printf("vectAddScaler: Test passed\n");
    }else{
        printf("vectAddScaler: Test Failed\n");
        exit(0);
    }
    
    ans = vectCreate(3, 3, 3);
    c = vectSub(b, a);
    if(vectEquals(c, ans)){
        printf("vectSub: Test passed\n");
    }else{
        printf("vectSub: Test Failed\n");
        exit(0);
    }
    
    ans = vectCreate(2, 3, 4);
    c = vectSubScaler(b, 2);
    if(vectEquals(c, ans)){
        printf("vectSubScaler: Test passed\n");
    }else{
        printf("vectSubScaler: Test Failed\n");
        exit(0);
    }
    
    ans = vectCreate(8, 10, 12);
    c = vectMult(b, 2);
    if(vectEquals(c, ans)){
        printf("vectMult: Test passed\n");
    }else{
        printf("vectMult: Test Failed\n");
        exit(0);
    }
    
    ans = vectDiv(ans, 2);
    if(vectEquals(b, ans)){
        printf("vectDiv: Test passed\n");
    }else{
        printf("vectDiv: Test Failed\n");
        exit(0);
    }
    
    ans = vectCreate(-1, -2, -3);
    c = vectMinus(a);
    if(vectEquals(c, ans)){
        printf("vectMinus: Test passed\n");
    }else{
        printf("vectMinus: Test Failed\n");
        exit(0);
    }
    
    dans = sqrt(4*4+5*5+6*6);
    if ( vectMag(b) == dans){
        printf("vectMag: Test passed\n");
    }else{
        printf("vectMag: Test Failed\n");
        exit(0);
    }

    ans = vectDiv(b, dans);
    c = vectNorm(b);
    if(vectEquals(c,ans)){
        printf("vectNorm: Test passed\n");
    }else{
        printf("vectNorm: Test Failed\n");
        exit(0);
    }
    
    dans = b.x*a.x + a.y*b.y + a.z*b.z;
    if(vectDot(a, b) == dans){
        printf("vectDot: Test passed\n");
    }else{
        printf("vectDot: Test Failed\n");
        exit(0);
    }
    
    a=vectCreate(1, 0, 0);
    b=vectCreate(0, 1, 0);
    ans = vectCreate(0, 0, 1);
    c = vectCross(a, b);
    if(vectEquals(c, ans)){
        printf("vectCross: Test passed\n");
    }else{
        printf("vectCross: Test Failed\n");
        exit(0);
    }
    
    c = vectRotatex(ans, -1*PI/2);
    if(vectEquals(c, b)){
        printf("vectRotatex: Test passed\n");
    }else{
        printf("vectRotatex: Test Failed\n");
        exit(0);
    }    
    
    ans = vectCreate(0, 0, 1);
    c = vectRotatey(a, -PI/2);
    if(vectEquals(c, ans)){
        printf("vectRotatey: Test passed\n");
    }else{
        printf("vectRotatey: Test Failed\n");
        exit(0);
    } 
    
    c = vectRotatez(a, PI/2);
    if(vectEquals(c, b)){
        printf("vectRotatez: Test passed\n");
    }else{
        printf("vectRotatez: Test Failed\n");
        exit(0);
    } 
    
    c = vectRotateAxis(a, ans, PI/2);
    if(vectEquals(c, b)){
        printf("vectRotateAxis: Test passed\n");
    }else{
        printf("vectRotateAxis: Test Failed\n");
        exit(0);
    } 
    
    return 0;
}
示例#8
0
文件: turrets.c 项目: Almamu/portalDS
void updateTurret(turret_struct* t)
{
	if(!t || !t->used)return;
	
	if(!t->OBB || !t->OBB->used){t->OBB=NULL;t->used=false;return;}
	
	t->counter+=2;t->counter%=63; //TEMP
	if(t->dead)t->counter=31;
	editPalette((u16*)t->OBB->modelInstance.palette,0,RGB15(abs(31-t->counter),0,0)); //TEMP
	
	int32* m=t->OBB->transformationMatrix;
	room_struct* r=getPlayer()->currentRoom;
	if(!r)return;

	int32 angle, d;
	bool b=pointInTurretSight(t, getPlayer()->object->position, &angle, &d);
	if(b)
	{
		vect3D u=vectDifference(getPlayer()->object->position,t->laserOrigin);
		int32 d=magnitude(u);
		u=divideVect(u,d);
		if(collideLineMap(&gameRoom, NULL, t->laserOrigin, u, d, NULL, NULL))b=false;
	}

	switch(t->state)
	{
		case TURRET_CLOSED:
			changeAnimation(&t->OBB->modelInstance, 0, false);
			t->drawShot[0]=t->drawShot[1]=0;

			if(b && !t->dead){t->state=TURRET_OPENING; playSFX(turretDeploySFX);}
			break;
		case TURRET_OPENING:
			if(t->OBB->modelInstance.currentAnim==2)
			{
				t->state=TURRET_OPEN;
			}else if(t->OBB->modelInstance.currentAnim!=1)
			{
				changeAnimation(&t->OBB->modelInstance, 2, false);
				changeAnimation(&t->OBB->modelInstance, 1, true);
			}
			t->drawShot[0]=t->drawShot[1]=0;
			break;
		case TURRET_OPEN:
			{
				if(angle>mulf32(sinLerp(TURRET_SIGHTANGLE/3),d))changeAnimation(&t->OBB->modelInstance, 4, false);
				else if(angle<-mulf32(sinLerp(TURRET_SIGHTANGLE/3),d))changeAnimation(&t->OBB->modelInstance, 5, false);
				else changeAnimation(&t->OBB->modelInstance, 2, false);

				int i;
				for(i=0;i<2;i++)
				{
					if(!t->drawShot[i] && !(rand()%3))
					{
						t->drawShot[i]=rand()%8;
						t->shotAngle[i]=rand();

						shootPlayer(NULL, normalize(vectDifference(t->laserDestination,t->laserOrigin)), 6);
						playSFX(turretFireSFX);
					}

					if(t->drawShot[i])t->drawShot[i]--;
				}

				if(!b || t->dead){t->state=TURRET_CLOSING; playSFX(turretRetractSFX);}
			}
			break;
		case TURRET_CLOSING:
			if(t->OBB->modelInstance.currentAnim==0)
			{
				t->state=TURRET_CLOSED;
			}else if(t->OBB->modelInstance.currentAnim!=3)
			{
				changeAnimation(&t->OBB->modelInstance, 0, false);
				changeAnimation(&t->OBB->modelInstance, 3, true);
			}
			t->drawShot[0]=t->drawShot[1]=0;
			break;
	}

	if(!t->dead)
	{
		t->laserOrigin=addVect(vectDivInt(t->OBB->position,4),evalVectMatrix33(m,laserOrigin));
		t->laserDestination=addVect(t->laserOrigin,vect(m[2],m[5],m[8]));

		if(b)t->laserDestination=getPlayer()->object->position;

		vect3D dir=normalize(vectDifference(t->laserDestination,t->laserOrigin));
		t->laserThroughPortal=false;

		laserProgression(r, &t->laserOrigin, &t->laserDestination, dir);
		
		int32 x, y, z;
		vect3D v;
		portal_struct* portal=NULL;
		if(isPointInPortal(&portal1, t->laserDestination, &v, &x, &y, &z))portal=&portal1;
		if(abs(z)>=32)portal=NULL;
		if(!portal)
		{
			if(isPointInPortal(&portal2, t->laserDestination, &v, &x, &y, &z))portal=&portal2;
			if(abs(z)>=32)portal=NULL;
		}
		if(portal)
		{
			t->laserDestination=addVect(t->laserDestination,vectMult(dir,TILESIZE));


			t->laserThroughPortal=true;
			dir=warpVector(portal,dir);
			t->laserOrigin2=addVect(portal->targetPortal->position, warpVector(portal, vectDifference(t->laserDestination, portal->position)));
			t->laserDestination2=addVect(t->laserOrigin2,dir);
			
			laserProgression(r, &t->laserOrigin2, &t->laserDestination2, dir);
			

			t->laserOrigin2=addVect(t->laserOrigin2,vectMult(dir,-TILESIZE));
		}

		if(m[4]<sinLerp(8192/2))t->dead=true;
	}
	
	updateAnimation(&t->OBB->modelInstance);
}