Example #1
0
void initDoor(door_struct* d, room_struct* r, vect3D position, bool orientation)
{
	if(!d || !r)return;

	//for collisions

	rectangle_struct rec;
	rec.material=NULL;

	if(!orientation){rec.position=addVect(position,vect(-1,0,0)); rec.size=vect(2,8,0); rec.normal=vect(0,0,inttof32(1));}
	else {rec.position=addVect(position,vect(0,0,-1)); rec.size=vect(0,8,2); rec.normal=vect(inttof32(1),0,0);}

	d->rectangle[0]=addRoomRectangle(r, rec, NULL, false);
	if(d->rectangle[0])d->rectangle[0]->hide=true;

	rec.position.y+=rec.size.y;
	rec.size.y=-rec.size.y;
	d->rectangle[1]=addRoomRectangle(r, rec, NULL, false);
	if(d->rectangle[1])d->rectangle[1]->hide=true;

	initModelInstance(&d->modelInstance, &doorModel);
	d->position=convertVect(vect(position.x+r->position.x, position.y, position.z+r->position.y));
	d->orientation=orientation;
	d->active=false;
	d->used=true;
}
Example #2
0
vect3D getClosestPointRectangle(vect3D p, vect3D s, vect3D o)
{
	vect3D u1, u2;
	int32 x,y,sx,sy;
	
	// NOGBA("p: %d %d %d",p.x,p.y,p.z);
	// NOGBA("o: %d %d %d",o.x,o.y,o.z);
	
	if(s.x){sx=abs(s.x);u1=vect((s.x>0)?inttof32(1):(-inttof32(1)),0,0);}
	else{sx=abs(s.y);u1=vect(0,(s.y>0)?inttof32(1):(-inttof32(1)),0);}
	
	if(s.z){sy=abs(s.z);u2=vect(0,0,(s.z>0)?inttof32(1):(-inttof32(1)));}
	else{sy=abs(s.y);u2=vect(0,(s.y>0)?inttof32(1):(-inttof32(1)),0);}
	
	o=vectDifference(o,p);
	
	x=dotProduct(o,u1);y=dotProduct(o,u2);
	
	// NOGBA("x, y: %d %d",x,y);
	// NOGBA("sx, sy: %d %d",sx,sy);
	
	bool r=true;
	r=r&&x<sx&&x>=0;
	r=r&&y<sy&&y>=0;
	
	if(r)return addVect(p,vect(mulf32(x,u1.x)+mulf32(y,u2.x), mulf32(x,u1.y)+mulf32(y,u2.y), mulf32(x,u1.z)+mulf32(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 addVect(p,vect(mulf32(x,u1.x)+mulf32(y,u2.x), mulf32(x,u1.y)+mulf32(y,u2.y), mulf32(x,u1.z)+mulf32(y,u2.z)));
}
Example #3
0
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)));
}
Example #4
0
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;
}
Example #5
0
void drawBezierCurves()
{
	// Caractéristiques visuelles de la ligne
	glLineWidth(1.5);
	glColor4f(1.0,0,0,1);
	
	int n = nbControlPoints - 1;
	int d = curvePrecision + 1;

	glBegin(GL_LINE_STRIP);
		for (int h = 0; h <= d; h++)
		{
			float u = (float)h/(float)d;

			vect2D pu;
			pu.x = 0;
			pu.y = 0;
			for (int i = 0; i <= n; i++)
			{
				float Binu = B(i, n, u);
				vect2D Pi = ControlPointArray[i];
				vect2D temp = multScalaireVect(Binu, Pi);
				pu = addVect(pu, temp);
			}
			glVertex2f(pu.x, pu.y);
		}
	glEnd();
}
Example #6
0
void transformRay(vect3D* o, vect3D* v)
{
	int32* m=editorCamera.transformationMatrix;
	// int32 m[9]; transposeMatrix33(editorCamera.transformationMatrix,m);
	// *o=evalVectMatrix33(m,vectDifference(divideVect(*o,editorScale),editorTranslation));
	*o=addVect(evalVectMatrix33(m,divideVect(*o,editorScale)),editorCamera.position);
	*v=evalVectMatrix33(m,*v);
}
Example #7
0
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));
}
Example #8
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;
}
Example #9
0
vect3D getDragPosition(blockFace_struct* bf, vect3D o, vect3D v, vect3D los)
{
	if(!bf)return vect(0,0,0);
	vect3D n, ip;
	n=los;
	switch(bf->direction)
	{
		case 0: case 1: n.x=0; break;
		case 2: case 3: n.y=0; break;
		case 4: case 5: n.z=0; break;
	}
	n=normalize(n);
	if(!collideLinePlane(addVect(faceOrigin[bf->direction],getBlockPosition(bf->x,bf->y,bf->z)), n, o, v, &ip))return faceOrigin[bf->direction];
	return ip;
}
Example #10
0
bool solve(double vect[][N],int m,int n,double sol[],int basic[])
{
  int top=0;
  for(int i=0;i<m;i++)
    if(!addVect(vect,i,top,n+1))
      return false;
  for(int i=0;i<n;i++)basic[i]=-1,sol[i]=0.0;
  for(int i=top-1;i>=0;i--)
  {
    int ind=vindex[i];
    basic[nzero[ind]]=i;
    sol[nzero[ind]]=vect[ind][n];
    for(int j=n-1;j>nzero[ind];j--)
      sol[nzero[ind]]-=sol[j]*vect[ind][j];
  }
  return true;
}
Example #11
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;
}
void KalmanFilter::getX(double** K) {
  double* img = imgMatrix(H,X,2,3);
  double* subV = subVect(Y,img,2);

  free(img);
  img = imgMatrix(K,subV,3,2);

  free(subV);
  subV = NULL;

  double* tmp = addVect(X,img,3);

  free(img);
  img = NULL;
  free(X);
  X = tmp;

  tmp = NULL;
}
Example #13
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;
}
Example #14
0
int32 pointRectangleDistance(vect3D o, rectangle_struct* rec)
{
	if(!rec->size.x)
	{
		int32 d1=pointSegmentDistance(o, rec->position, vect(0,rec->size.y,0));
		int32 d2=pointSegmentDistance(o, rec->position, vect(0,0,rec->size.z));
		int32 d3=pointSegmentDistance(o, addVect(rec->position,vect(0,0,rec->size.z)), vect(0,rec->size.y,0));
		int32 d4=pointSegmentDistance(o, addVect(rec->position,vect(0,rec->size.y,0)), vect(0,0,rec->size.z));
		return min(d1,min(d2,min(d3,d4)));
	}else if(!rec->size.y)
	{
		int32 d1=pointSegmentDistance(o, rec->position, vect(rec->size.x,0,0));
		int32 d2=pointSegmentDistance(o, rec->position, vect(0,0,rec->size.z));
		int32 d3=pointSegmentDistance(o, addVect(rec->position,vect(0,0,rec->size.z)), vect(rec->size.x,0,0));
		int32 d4=pointSegmentDistance(o, addVect(rec->position,vect(rec->size.x,0,0)), vect(0,0,rec->size.z));
		return min(d1,min(d2,min(d3,d4)));
	}else{
		int32 d1=pointSegmentDistance(o, rec->position, vect(rec->size.x,0,0));
		int32 d2=pointSegmentDistance(o, rec->position, vect(0,rec->size.y,0));
		int32 d3=pointSegmentDistance(o, addVect(rec->position,vect(0,rec->size.y,0)), vect(rec->size.x,0,0));
		int32 d4=pointSegmentDistance(o, addVect(rec->position,vect(rec->size.x,0,0)), vect(0,rec->size.y,0));
		return min(d1,min(d2,min(d3,d4)));
	}
}
Example #15
0
void menuFrame(void)
{
	if(!d3dScreen)initProjectionMatrix(&menuCamera, 70*90, inttof32(4)/3, inttof32(2), inttof32(1000));
	else initProjectionMatrixBottom(&menuCamera, 70*90, inttof32(4)/3, inttof32(2), inttof32(1000));

	projectCamera(&menuCamera);
	glLoadIdentity();

	glLight(0, RGB15(31,31,31), cosLerp(lightAngle)>>3, 0, sinLerp(lightAngle)>>3);

	GFX_CLEAR_COLOR=RGB15(0,0,0)|(31<<16);

	scanKeys();
	touchRead(&currentTouch);

	if((keysHeld() & KEY_R) && (keysHeld() & KEY_L))changeState(&menuState);

	if(keysHeld() & KEY_R)tempState.position=addVect(tempState.position,vect(0,0,inttof32(1)/64));
	if(keysHeld() & KEY_L)tempState.position=addVect(tempState.position,vect(0,0,-inttof32(1)/64));
	if(keysHeld() & KEY_UP)tempState.position=addVect(tempState.position,vect(0,inttof32(1)/64,0));
	if(keysHeld() & KEY_DOWN)tempState.position=addVect(tempState.position,vect(0,-inttof32(1)/64,0));
	if(keysHeld() & KEY_RIGHT)tempState.position=addVect(tempState.position,vect(inttof32(1)/64,0,0));
	if(keysHeld() & KEY_LEFT)tempState.position=addVect(tempState.position,vect(-inttof32(1)/64,0,0));

	//TEMP (updateCamera stuff)
		menuCamera.viewPosition=menuCamera.position;

	// if(keysHeld() & KEY_A)lightAngle+=128;
	// else if(keysHeld() & KEY_B)lightAngle-=128;
		
	if(keysHeld() & KEY_A)tempState.angle.x+=64;
	if(keysHeld() & KEY_B)tempState.angle.x-=64;
	if(keysHeld() & KEY_X)tempState.angle.y+=64;
	if(keysHeld() & KEY_Y)tempState.angle.y-=64;
	if(keysHeld() & KEY_START)tempState.angle.z+=64;
	if(keysHeld() & KEY_SELECT)tempState.angle.z-=64;

	// if(keysUp() & KEY_TOUCH)
	// {
	// 	if(tempbool)testTransition=startCameraTransition(&cameraStates[1],&cameraStates[0],64);
	// 	else testTransition=startCameraTransition(&cameraStates[0],&cameraStates[1],64);

	// 	tempbool^=1;
	// }

	if(!(keysHeld() & KEY_TOUCH)) updateSimpleGui(-1, -1);
	else updateSimpleGui(currentTouch.px, currentTouch.py);

	// applyCameraState(&menuCamera,&tempState);
	updateCameraTransition(&menuCamera,&testTransition);

	drawMenuScene();

	switch(d3dScreen)
	{
		case true:
			drawSimpleGui();
			updateMenuScene();
			break;
		default:
			if(logoAlpha)drawLogo();
			break;
	}
	
	glFlush(0);
	swiWaitForVBlank();

	updateD3D();
}
Example #16
0
/* Note: Doesn't handle non-existant residues. */
double AlignAlignmentBlocks(int p1, int p2, int count1, int count2, WeightedResiduePositions *r1, WeightedResiduePositions *r2, int len, Matrix *m, double minScore) {
	Matrix A = {0,0,0,0,0,0,0,0,0,0,0,0};

	Matrix m1, m2, m3, m4;

	Vector com1 = {0,0,0}, com2 = {0,0,0};
	double E0 = 0;

	double rmsd;

	int i, j, k;


	double *normalized1;
	double *normalized2;

	double buffer[2000];
	/*
	 * Only malloc when needed, which isn't often.
	 */
	if (len <= 1000) {
		normalized1 = buffer;
	}
	else {
		normalized1 = (double*) malloc(len * sizeof(double) * 2);
	}
	normalized2 = normalized1+len;

	for (i=0; i<len; i++) {
		Vector v;
		Vector com1delta = {0,0,0}, com2delta = {0,0,0};
		normalized1[i] = 0;
		normalized2[i] = 0;
		for (j=0; j<count1; j++) {
			if (!r1[j].res[p1+i].exists) {
				/* Shouldn't ever happen. */
				return -5;
			}
			normalized1[i] += r1[j].weight;
			addVect(&com1delta, &com1delta, mulVect(&v, &r1[j].res[p1+i].coords, r1[j].weight));
		}
		for (j=0; j<count2; j++) {
			if (!r2[j].res[p2+i].exists) {
				/* Shouldn't ever happen. */
				return -5;
			}
			normalized2[i] += r2[j].weight;
			addVect(&com2delta, &com2delta, mulVect(&v, &r2[j].res[p2+i].coords, r2[j].weight));
		}
		addVect(&com1, &com1, divVect(&com1delta, &com1delta, normalized1[i]));
		addVect(&com2, &com2, divVect(&com2delta, &com2delta, normalized2[i]));
	}
	divVect(&com1, &com1, len);
	divVect(&com2, &com2, len);

	for (i=0; i<len;  i++) {
		if (normalized1[i] != 0 && normalized2[i] != 0) {
			Vector moved1 = {0,0,0};
			Vector moved2 = {0,0,0};

			double E0delta1 = 0;
			double E0delta2 = 0;

			for (j=0; j<count1; j++) {
				if (r1[j].res[p1+i].exists) {
					Vector temp1, temp2;
					subVect(&temp1, &r1[j].res[p1+i].coords, &com1);
					mulVect(&temp2, &temp1, r1[j].weight);

					addVect(&moved1, &moved1, &temp2);
					E0delta1 += dotVect(&temp1, &temp2);
				}
			}
			E0delta1 /= normalized1[i];
			divVect(&moved1, &moved1, normalized1[i]);

			for (j=0; j<count2; j++) {
				if (r2[j].res[p2+i].exists) {
					Vector temp1, temp2;
					subVect(&temp1, &r2[j].res[p2+i].coords, &com2);
					mulVect(&temp2, &temp1, r2[j].weight);
					addVect(&moved2, &moved2, &temp2);
					E0delta2 += dotVect(&temp1, &temp2);
				}
			}
			E0delta2 /= normalized2[i];
			divVect(&moved2, &moved2, normalized2[i]);

			E0 += E0delta1 + E0delta2;

			for (j=0; j<3; j++) {
				for (k=0; k<3; k++)
					A.M[j][k] += moved2.v[k] * moved1.v[j];
			}
		}
	}
	E0/=2;


	if (minScore > 0) {
		Matrix ATA;
		rmsd = CalcRMSD(&ATA, &A, E0, len);
		if (RMSDScoreSimple(rmsd, len) < minScore) {
			/* Don't bother with rotation. */
			return rmsd;
		}
		rmsd = CalcRotation(&m3, &A, &ATA, E0, len);
	}
	else {
		rmsd = CalcRMSDAndRotation(&m3, &A, E0, len);
	}

	m3.M[0][3] = 0;
	m3.M[1][3] = 0;
	m3.M[2][3] = 0;

	m2 = m1 = identity;

	m2.M[0][3] = -com2.v[0];
	m2.M[1][3] = -com2.v[1];
	m2.M[2][3] = -com2.v[2];

	m1.M[0][3] = com1.v[0];
	m1.M[1][3] = com1.v[1];
	m1.M[2][3] = com1.v[2];

	mulMat(&m4, &m3, &m2);
	mulMat(m, &m1, &m4);

	if (normalized1 != buffer) free(normalized1);

	return rmsd;
}
Example #17
0
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);
}
Example #18
0
int32 pointSegmentDistance(vect3D o, vect3D p, vect3D v)
{
	if(v.x>=0 && v.y>=0 && v.z>=0)return pointSegmentDistanceAbs(o, p, v);
	else return pointSegmentDistanceAbs(o, addVect(p,v), vectMultInt(v,-1));
}
Example #19
0
void roomEditorCursor(selection_struct* sel)
{
	if(!sel)sel=&editorSelection;
	if((keysDown() & KEY_TOUCH) && !(sel->entity && !sel->entity->placed))
	{
		u8 type;
		void* ptr=getBlockEntityTouch(&type);
		if(sel->entity && sel->selectingTarget)
		{
			if(type)
			{
				sel->selectingTarget=false;
				sel->entity->target=(entity_struct*)ptr;
				cleanUpContextButtons();
			}
		}else{
			if(type)
			{
				//entity
				entity_struct* e=(entity_struct*)ptr;

				undoSelection(sel);
				sel->active=true;
				sel->selecting=false;
				sel->selectingTarget=false;
				sel->entity=e;
			}else{
				//blockface
				blockFace_struct* bf=(blockFace_struct*)ptr;

				if(bf)
				{
					if(sel->active && isFaceInSelection(bf, sel))
					{
						sel->currentFace=bf;
						sel->currentPosition=vect(bf->x,bf->y,bf->z);
						sel->selecting=false;
						sel->selectingTarget=false;
					}else{
						undoSelection(sel);
						sel->firstFace=sel->secondFace=bf;
						sel->active=true;
						sel->selecting=true;
						sel->selectingTarget=false;
					}
					sel->entity=NULL;
				}else{
					undoSelection(sel);
				}
			}			
		}
	}else if(keysHeld() & KEY_TOUCH)
	{
		if(sel->active && !(sel->entity && sel->selectingTarget))
		{
			if(sel->entity)
			{
				blockFace_struct* bf=getBlockFaceTouch(NULL);
				if(bf)
				{
					sel->error=!moveEntityToBlockFace(sel->entity, bf);
				}
			}else{
				if(sel->selecting)
				{
					blockFace_struct* bf=getBlockFaceTouch(NULL);
					if(bf)sel->secondFace=bf;
				}else{
					blockFace_struct* bf=sel->currentFace;
					bool fill=true;
					vect3D p=getDragPosition(bf, lineOfTouchOrigin, lineOfTouchVector, lineOfTouchVector);
					p=vect((p.x+(ROOMARRAYSIZEX*BLOCKSIZEX+BLOCKSIZEX)/2)/BLOCKSIZEX,(p.y+(ROOMARRAYSIZEY*BLOCKSIZEY+BLOCKSIZEY)/2)/BLOCKSIZEY,(p.z+(ROOMARRAYSIZEZ*BLOCKSIZEZ+BLOCKSIZEZ)/2)/BLOCKSIZEZ);
					
					switch(bf->direction)
					{
						case 0:  p.y=bf->y; p.z=bf->z; fill=p.x>sel->currentPosition.x; break;
						case 1:  p.y=bf->y; p.z=bf->z; fill=p.x<sel->currentPosition.x; break;
						case 2:  p.x=bf->x; p.z=bf->z; fill=p.y>sel->currentPosition.y; break;
						case 3:  p.x=bf->x; p.z=bf->z; fill=p.y<sel->currentPosition.y; break;
						case 4:  p.x=bf->x; p.y=bf->y; fill=p.z>sel->currentPosition.z; break;
						default: p.x=bf->x; p.y=bf->y; fill=p.z<sel->currentPosition.z; break;
					}

					if(p.x!=sel->currentPosition.x || p.y!=sel->currentPosition.y || p.z!=sel->currentPosition.z)
					{
						blockFace_struct oldFirstFace=*sel->firstFace;
						blockFace_struct oldSecondFace=*sel->secondFace;
						blockFace_struct oldCurrentFace=*sel->currentFace;

						vect3D v=vectDifference(p, sel->currentPosition);
						vect3D o=(bf->direction%2)?(sel->origin):(adjustVectForNormal(bf->direction, sel->origin)); vect3D s=v;
						fixOriginSize(&o, &s); s=adjustVectForNormal((bf->direction%2)?(bf->direction):(oppositeDirection[bf->direction]), addVect(s,sel->size));
						vect3D oe=adjustVectForNormal(bf->direction, sel->origin); vect3D se=sel->size;

						moveEntitiesRange(oe, se, v);
						if(fill)fillBlockArrayRange(editorRoom.blockArray, &editorRoom.blockFaceList, o, s);
						else emptyBlockArrayRange(editorRoom.blockArray, &editorRoom.blockFaceList, o, s);
						getEntityBlockFacesRange(editorRoom.blockFaceList, addVect(oe,v), se, true);

						adjustSelection(&editorRoom, sel, oldFirstFace, oldSecondFace, oldCurrentFace, v);
						sel->currentPosition=p;
					}
				}
			}
		}else{
			if(abs(oldTouch.px-currentTouch.px)>2)rotateMatrixY(editorCamera.transformationMatrix, -TOUCHSPEEDX*(oldTouch.px-currentTouch.px), true);
			if(abs(oldTouch.py-currentTouch.py)>2)rotateMatrixX(editorCamera.transformationMatrix, -TOUCHSPEEDY*(oldTouch.py-currentTouch.py), false);
		}
	}else if(keysUp() & KEY_TOUCH)
	{
		if(sel->active)
		{
			if(sel->entity && sel->entity->type)
			{
				if(!sel->selectingTarget)setupContextButtons(sel->entity->type->contextButtonsArray, sel->entity->type->numButtons);
				else setupContextButtons(targetSelectionButtonArray, 2);
			}else if(sel->planar && sel->firstFace && (sel->firstFace->direction==2 || sel->firstFace->direction==3))setupContextButtons(groundSelectionButtonArray, 4);
			else if(sel->planar)setupContextButtons(planarSelectionButtonArray, 2);
			else setupContextButtons(nonplanarSelectionButtonArray, 4);
		}
	}
}
Example #20
0
void drawBSplineCurves()
{
	// Caractéristiques visuelles de la ligne
	glLineWidth(1.5);
	glColor4f(1.0,0,0,1);
	
	glBegin(GL_LINE_STRIP);


	//int n = nbControlPoints - 1;
	
	vect2D p0, p1, p2, p3;

	int iStart = (paramK == 3) ? 0 : 1;	
	for(int i = iStart ; i < nbControlPoints - 2; i++)
	{
		double incrementU =  (double)1.0 / (double)(curvePrecision + 1);
		for(double u = 0; u <= 1.0 ; u += incrementU)
		{	

			p0.x = ControlPointArray[i - 1].x;
			p0.y = ControlPointArray[i - 1].y;

			p1.x = ControlPointArray[i].x;
			p1.y = ControlPointArray[i].y;
		
			p2.x = ControlPointArray[i + 1].x;
			p2.y = ControlPointArray[i + 1].y;		

			p3.x = ControlPointArray[i + 2].x;
			p3.y = ControlPointArray[i + 2].y;		

	
			vect2D v, v1, v2, v3, v4;
		

			if(paramK == 3)
			{
			
				v1 = multScalaireVect(pow(1 - u, 2), p1);
				v2 = multScalaireVect(-2 * pow(u, 2) + 2 * u + 1, p2);
				v3 = multScalaireVect(pow(u, 2), p3);

				v = addVect(v1, v2);
				v = addVect(v, v3);

				v = multScalaireVect(0.5, v);
			
			}
			else
			{
				v1 = multScalaireVect(pow(-u, 3) + 3 * pow(u, 2) - 3 * u + 1, p0);
				v2 = multScalaireVect(3 * pow(u, 3) - 6 * pow(u, 2) + 4, p1);
				v3 = multScalaireVect(-3 * pow(u, 3) + 3 * pow(u, 2) + 3 * u + 1, p2);
				v4 = multScalaireVect(pow(u, 3), p3);

				v = addVect(v1, v2);
				v = addVect(v, v3);
				v = addVect(v, v4);


				v = multScalaireVect(UNSURSIX, v);
			}


			glVertex2f(v.x, v.y);
		}
	}

	
	glEnd();	
}
Example #21
0
/**
 * Gaxpy
 */
void gaxpy(vect_f V1, vect_f V2, matrice_f M, vect_f Res) {
    vect_f interm;
    multVect(M,V1, interm);
    addVect(interm, V2, Res);
}