예제 #1
0
void getPositionFromData(float *x, float *y, Data *data) {
	vec2 v;
	vec2Add(&v,
					&data->trails[data->trailOffset].vStart,
					&data->trails[data->trailOffset].vDirection);
	*x = v.v[0];
	*y = v.v[1];
}
예제 #2
0
Vec2 polyComputeCenter(const Polygon* P)
{
	unsigned int i;
	Vec2 Center = vxGetPosition((Vertex*)daGet(&P->Vertices, 0));
	for(i = 1; i < daGetSize(&P->Vertices); i++)
		Center = vec2Add(Center, vxGetPosition((Vertex*)daGet(&P->Vertices, i)));
	return vec2Div(Center, daGetSize(&P->Vertices));
}
예제 #3
0
파일: Player.cpp 프로젝트: posva/jump-n-run
void plCorrectPosition(Player* P, Vec2 Pos)
{
	if(P->Shape != NULL)
	{
		vxSetPosition(P->VxUL, vec2Add(vxGetPosition(P->VxUL), Pos));
		vxSetPosition(P->VxUR, vec2Add(vxGetPosition(P->VxUR), Pos));
		vxSetPosition(P->VxDL, vec2Add(vxGetPosition(P->VxDL), Pos));
		vxSetPosition(P->VxDR, vec2Add(vxGetPosition(P->VxDR), Pos));
	}

	Vec2 v = vec2Sub(vxGetPosition(P->VxUL), vxGetPosition(P->VxDL));
	P->PrevCenter = P->Center;
	P->Center = polyComputeCenter(P->Shape);
	v = vec2Normalized(v);
	vxSetPosition(P->vxBodyParts[bpBase], vec2Add(P->Center, vec2Prod(v, -15.f)));

	aniUpdateForCurrentState(P->aniStand, P);
	aniUpdate(P->aniStand, P, 1.f);
}
예제 #4
0
sequenceContainer sampleSequences::sampleRandomSequences(int seqNum)
{
	if (seqNum > _sc.numberOfSeqs())
		errorMsg::reportError("sampleSequences::sampleRandomSequences(): the number of requested seqeuences is larger than the number of sequences in the MSA");
	sequenceContainer newSc;
	Vint vec2Add(_sc.numberOfSeqs(),0);
	int n = 0;
	while (n < seqNum)
	{
		int seqPlaceToAdd = talRandom::giveIntRandomNumberBetweenZeroAndEntry(_sc.numberOfSeqs());
		if (vec2Add[seqPlaceToAdd] == 0){
			vec2Add[seqPlaceToAdd] = 1;
			n++;
		}
        
	}
	for (int i = 0; i<vec2Add.size();i++){
		if (vec2Add[i] == 1)
			newSc.add(_sc[i]);
	}
	return newSc;
}
예제 #5
0
파일: Player.cpp 프로젝트: posva/jump-n-run
void plUpdate(Player* P, s_SharedResources* SR)
{

	P->GroundVec = vec2Ortho(P->Normal);

	// Mise à jour quelques States
	Vec2 RdBottom = vec2Normalized(vec2Sub(vxGetPosition(P->VxDR), vxGetPosition(P->VxDL)));

	if(RdBottom.x < 0.f)
	{
		P->State = P->State | PL_UPSIDEDOWN;
		P->State = P->State | PL_FALLING;
	} else {
		if(RdBottom.y < -0.5f)
		{
			P->State = P->State | PL_FALLING;
			P->State = P->State | PL_FALLING_L;
		} else if(RdBottom.y > 0.5f) {
			P->State = P->State | PL_FALLING;
			P->State = P->State | PL_FALLING_R;
		}
	}

	if(P->GrabL != NULL) P->State = P->State | PL_GRABL;
	if(P->GrabR != NULL) P->State = P->State | PL_GRABR;

	Vec2 v = vec2Sub(vxGetPosition(P->VxUL), vxGetPosition(P->VxDL));
	P->PrevCenter = P->Center;
	P->Center = polyComputeCenter(P->Shape);
	v = vec2Normalized(v);
	vxSetPosition(P->vxBodyParts[bpBase], vec2Add(P->Center, vec2Prod(v, -15.f)));


	Vec2 speed = vec2Sub(P->Center, P->PrevCenter);
	//printf("speed:%f,%f\n",speed.x, speed.y);


	if (!(P->State & PL_ON_GROUND) && ABS(speed.y) > 0.1f)
	{
		if (speed.y<2.f)
			P->CurrentAnim = P->aniJump;
		else
			P->CurrentAnim = P->aniFall;
		P->timer.restart();
	}
	else
	{
		if (ABS(speed.x) > 1.f)
			P->CurrentAnim = P->aniRun, P->timer.restart();
		else if (P->timer.getElapsedTime().asSeconds() < 5.f)
			P->CurrentAnim = P->aniStand;
		else
			P->CurrentAnim = P->aniHello;
	}

	if (P->timer.getElapsedTime().asSeconds() > 20.f)
		P->timer.restart();

	unsigned int LastState;

	if (aniGetType(P->CurrentAnim) == ANIM_POSITIONS)
		LastState = P->Positions.CurrentState;
	else
		LastState = P->Angles.CurrentState;


	if (ABS(speed.x) > 1.f && P->CurrentAnim == P->aniRun)
	{
		float spp = vec2Length(speed);
		aniUpdate(P->CurrentAnim, P, MAX(0.25f, spp/10.f));
	}
	else
		aniUpdate(P->CurrentAnim, P, 1.f);
		

	if (aniGetType(P->CurrentAnim) == ANIM_POSITIONS)
	{
		if (P->CurrentAnim == P->aniRun && LastState != P->Positions.CurrentState)
			sndmPlay(shSoundManager(SR), P->SndFoot[LastState]);
	}
	else
	{
		if (P->CurrentAnim == P->aniRun && LastState != P->Angles.CurrentState)
			sndmPlay(shSoundManager(SR), P->SndFoot[LastState]);
	}

}
예제 #6
0
파일: Player.cpp 프로젝트: posva/jump-n-run
void plInit(Player* P, World *W)
{
	P->ULPos = vec2(-20.f, -70.f);
	P->URPos = vec2(20.f, -70.f);
	P->DLPos = vec2(-35.f, 70.f);
	P->DRPos = vec2(35.f, 70.f);

	strcpy(P->SndFoot[0], "snd_step1");
	strcpy(P->SndFoot[1], "snd_step2");

	P->timer.restart();

	P->VxUL = newVertex();
	vxSetPosition(P->VxUL, P->ULPos);
	P->VxUR = newVertex();
	vxSetPosition(P->VxUR, P->URPos);
	P->VxDR = newVertex();
	vxSetPosition(P->VxDR, P->DRPos);
	P->VxDL = newVertex();
	vxSetPosition(P->VxDL, P->DLPos);

	vxSetMass(P->VxUL, 0.01f);
	vxSetMass(P->VxUR, 0.01f);
	vxSetMass(P->VxDL, 1.5f);
	vxSetMass(P->VxDR, 1.5f);

	P->Shape = polyRectangle(P->VxUL, P->VxUR, P->VxDR, P->VxDL);
	wdAddVxFromPoly(W, P->Shape);

	P->GroundAngle = M_PI_2;

	P->Dir = DIR_RIGHT;

	animAnglesStatesInit(&P->Angles);
	animPositionsStatesInit(&P->Positions);

	P->aniRun = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniRun, (ResourcePath()+"data/anims/animRun.ani").c_str());
	//aniSetForce(P->aniRun, 0.65f);

	P->aniJump = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniJump, (ResourcePath()+"data/anims/animJump.ani").c_str());
	aniSetForce(P->aniJump, 0.65f);

	P->aniFall = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniFall, (ResourcePath()+"data/anims/animFall.ani").c_str());

	P->aniHello = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniHello, (ResourcePath()+"data/anims/animHello.ani").c_str());

	P->aniStand = newAnimation(ANIM_ANGLES, ANIM_ALL_TRIGGERS, TRUE);
	aniLoadFromFile(P->aniStand, (ResourcePath()+"data/anims/animStand.ani").c_str());

	unsigned int i=0;
	for (i=0; i<polyGetVxCount(P->Shape); i++)
		vxSetFixed(polyGetVertex(P->Shape, i), FALSE);

	P->GrabR = NULL;
	P->GrabL = NULL;
	P->VxULStatus = P->VxURStatus = P->VxDRStatus = P->VxDLStatus =
		P->RdUStatus = P->RdRStatus = P->RdDStatus = P->RdLStatus = nullCollisionInfo();
	P->State = PL_NOSTATE;
	plResetJump(P);

	/* On crée les vertices du personnage, pour l'animation et quand il meurt */
	for (int i=0; i<12; i++)
		P->vxBodyParts[i] = newVertex();

	vxSetPosition(P->vxBodyParts[bpBase], vec2(0.f, 100.f));
	Vec2 B = vxGetPosition(P->vxBodyParts[bpBase]);
	vxSetPosition(P->vxBodyParts[bpNeck], vec2(B.x, B.y - 60.f));
	 vxSetPosition(P->vxBodyParts[bpHeadLeft], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(-20.f, -20.f)));
	 vxSetPosition(P->vxBodyParts[bpHeadRight], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(20.f, -20.f)));
	 vxSetPosition(P->vxBodyParts[bpLeftArm1], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 25.f)));
	 vxSetPosition(P->vxBodyParts[bpLeftArm2], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 50.f)));
	 vxSetPosition(P->vxBodyParts[bpRightArm1], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 25.f)));
	 vxSetPosition(P->vxBodyParts[bpRightArm2], vec2Add(vxGetPosition(P->vxBodyParts[bpNeck]), vec2(0.f, 50.f)));
	 vxSetPosition(P->vxBodyParts[bpLeftLeg1], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 30.f)));
	vxSetPosition(P->vxBodyParts[bpLeftLeg2], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 60.f)));
	vxSetPosition(P->vxBodyParts[bpRightLeg1], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 30.f)));
	vxSetPosition(P->vxBodyParts[bpRightLeg2], vec2Add(vxGetPosition(P->vxBodyParts[bpBase]), vec2(0.f, 60.f)));

	for (int i=0; i<12; i++)
	{
		switch (i) {
			case bpNeck:
			case bpLeftLeg1:
			case bpRightLeg1:
				P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[bpBase], -1.f);
				break;
			case bpLeftArm1:
			case bpRightArm1:
			case bpHeadLeft:
			case bpHeadRight:
				P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[bpNeck], -1.f);
				break;
			case bpLeftArm2:
			case bpRightArm2:
			case bpLeftLeg2:
			case bpRightLeg2:
				P->BodyRigids[i] = newRigid(P->vxBodyParts[i], P->vxBodyParts[i-1], -1.f);
				break;
			case bpBase:
				P->BodyRigids[i] = newRigid(P->vxBodyParts[bpHeadLeft], P->vxBodyParts[bpHeadRight], -1.f);
				break;
			default:
				break;
		}
	}

	P->CurrentAnim = P->aniStand;
	aniUpdateForCurrentState(P->CurrentAnim, P);
	aniUpdate(P->CurrentAnim, P, 1.f);

}
예제 #7
0
파일: Joint.cpp 프로젝트: posva/jump-n-run
void jnResolve(Joint* J)
{
	Vec2 CM = vec2Sub(vxGetPosition(J->M), vxGetPosition(J->C));
	Vec2 CS = vec2Sub(vxGetPosition(J->S), vxGetPosition(J->C));
	Vec2 Ortho = vec2Ortho(CM);

	//Vec2 tmp = vec2Prod(vec2Rotate(vxGetPosition(J->M), vxGetPosition(J->C), DEG2RAD(170.f)), J->Factor);
	//J->MaxDot = vec2Dot(tmp, CM);

	float sc = vec2Dot(CS, Ortho), sc2 = vec2Dot(CS, CM);

	//printf("scalaire: %f\n", vec2Dot(CS, CM));
	//printf("dot: %f", sc2);

	if (sc>0.f) //mauvais cote
	{
		//On applique une rigide
		/*Vec2 Vect = vec2Sub(vxGetPosition(J->S), vxGetPosition(J->M));

		 float acLength = vec2Length(Vect);

		 float factor = (acLength - J->Length);

		 if(acLength != 0.f)
		 Vect = vec2Div(Vect, acLength);
		 else
		 Vect = vec2(1.f, 0.f);

		 if(vxIsFixe(J->M))
		 vxCorrectPosition(J->S, vec2Prod(Vect, factor));
		 else if(vxIsFixe(J->S))
		 vxCorrectPosition(J->M, vec2Prod(Vect, -factor));
		 else
		 vxCorrectPosition(J->M, vec2Prod(Vect, -factor*0.5f)),
		 vxCorrectPosition(J->S, vec2Prod(Vect, factor*0.5f));
		 */



		if (sc2>0.f) // il va falloir corriger avec une rotation
		{
			//Vec2 pos = vec2Rotate(vxGetPosition(J->M), vxGetPosition(J->C), DEG2RAD(0.f));
			Vec2 pos = vxGetPosition(J->M);
			pos = vec2Sub(pos, vxGetPosition(J->C));
			pos = vec2Prod(pos, J->Factor);
			pos = vec2Add(pos, vxGetPosition(J->C));
			vxSetPosition(J->S, pos);
			//Vec2 pos = vec2Prod(vec2Rotate(vxGetPosition(J->M), vxGetPosition(J->C), DEG2RAD(-10.f)), J->Factor);
			//printf("M pos :%f, %f, M rotated by 10º : %f, %f\n", vxGetPosition(J->M).x, vxGetPosition(J->M).y, pos.x, pos.y);

			//printf("pos: %f, %f\n", pos.x, pos.y);
		}
		else
		{
			Vec2 pos = vec2Rotate(vxGetPosition(J->M), vxGetPosition(J->C), DEG2RAD(180.f));
			//printf("pos: %f, %f; Factor: %f", pos.x, pos.y, J->Factor);
			pos = vec2Sub(pos, vxGetPosition(J->C));
			pos = vec2Prod(pos, J->Factor);
			pos = vec2Add(pos, vxGetPosition(J->C));

			vxSetPosition(J->S, pos);
		}

	}

	//pour simplifier et pour avoir un meilleur fonctionnement on ne tiens pas compte des 10º juste 0º-180º
	/*else if (0)//sc2 > J->MaxDot) // il va falloir corriger avec une rotation
	{
		//printf("dot: %f\n", sc2);

		Vec2 pos = vec2Rotate(vxGetPosition(J->M), vxGetPosition(J->C), DEG2RAD(-10.f));
		//printf("pos: %f, %f; Factor: %f", pos.x, pos.y, J->Factor);
		pos = vec2Sub(pos, vxGetPosition(J->C));
		pos = vec2Prod(pos, J->Factor);
		pos = vec2Add(pos, vxGetPosition(J->C));
		//pos.x*=J->Factor; pos.y*=J->Factor;
		vxSetPosition(J->S, pos);
		//vxSetPosition(J->S, vec2Prod(vec2Rotate(vxGetPosition(J->M), vxGetPosition(J->C), DEG2RAD(-10.f)), 1.f));
	}
	 */
}