Author SHA1 Message Date
mangavalk 0447cb8c7a Rework HexapodClass
Imported from 'hexapod 4.rar'.
2014-10-13 00:49:00 +02:00
2 changed files with 183 additions and 60 deletions

No files matched your search

@@ -23,9 +23,6 @@ float rotationX=0;
float rotationY=0; float rotationY=0;
float rotationZ=0; float rotationZ=0;
int animationStep=0;
int animationSubStep=0;
boolean robotStanding = false; boolean robotStanding = false;
float robotHeigth = 12; float robotHeigth = 12;
@@ -52,40 +49,111 @@ void drawTestSpot(PVector p, boolean leftLegorRight)
endShape(); endShape();
} }
/* // Animation old.
PVector Animation(int addition)
{
return animationSubSteps(walk1[((animationStep+addition)%6)], walk1[((animationStep+addition+1)%6)]);
}
PVector animationSubSteps(PVector from, PVector to)
{
PVector newStep = new PVector();
int steps=5;
if (animationSubStep < steps)
{
float differenceX = (to.x - from.x) / steps;
float differenceY = (to.y - from.y) / steps;
float differenceZ = (to.z - from.z) / steps;
newStep.x = from.x + ( differenceX * animationSubStep );
newStep.y = from.y + ( differenceY * animationSubStep );
newStep.z = from.z + ( differenceZ * animationSubStep );
} else
{
animationSubStep=0;
animationStep++;
newStep = to;
}
return newStep;
}
*/
PVector []walk1 = new PVector[6]; PVector []walk1 = new PVector[6];
PVector Animation(int addition) // Animation new
int animationStep=0;
int animationSubStep=0;
boolean animationRepeat = false;
boolean animationRepeatComplete = false;
int animationSpeed = 20;
PVector animationOld;
PVector Animation(PVector from, PVector to)
{ {
PVector[] newAnimation = new PVector[2];
PVector P = new PVector(); newAnimation[0] = from;
newAnimation[1] = to;
P = animationSubSteps(walk1[((animationStep+addition)%6)], walk1[((animationStep+addition+1)%6)]); return Animation(newAnimation, 2, 0);
return P;
} }
PVector animationSubSteps(PVector from, PVector to) PVector Animation(PVector[] animation, int animationLength, int addition)
{ {
PVector newStep = new PVector(); PVector newStep = new PVector();
int steps=5;
if (animationSubStep < steps) PVector from = animation[((animationStep+addition) % animationLength)];
{ PVector to = animation[((animationStep+addition+1) % animationLength)];
float differenceX = (to.x - from.x) / steps;
float differenceY = (to.y - from.y) / steps;
float differenceZ = (to.z - from.z) / steps;
newStep.x = from.x + ( differenceX * animationSubStep ); /*if (!((animationStep >= animationLength - 1) && !animationRepeat))
newStep.y = from.y + ( differenceY * animationSubStep ); {
newStep.z = from.z + ( differenceZ * animationSubStep ); if (timerAnimation.delay(animationSpeed))
} else {
animationSubStep++;
}
} else
{
return animationOld;
}*/
if ( (animationRepeatComplete) || ((animationStep >= animationLength - 1) && !animationRepeat) )
{ {
animationSubStep=0; return animationOld;
animationStep++; } else {
newStep = to; /*if (timerAnimation.delay(animationSpeed))
{
animationSubStep++;
}*/
int steps=5;
if (animationSubStep < steps)
{
float differenceX = (to.x - from.x) / steps;
float differenceY = (to.y - from.y) / steps;
float differenceZ = (to.z - from.z) / steps;
newStep.x = from.x + ( differenceX * animationSubStep );
newStep.y = from.y + ( differenceY * animationSubStep );
newStep.z = from.z + ( differenceZ * animationSubStep );
} else
{
animationSubStep = 0;
if ((animationStep >= animationLength - 2) && !animationRepeat)
{
animationRepeatComplete = true;
animationStep = 0;
animationOld = to;
return to;
} else if (!animationRepeatComplete)
{
animationStep++;
}
}
return newStep;
} }
return newStep;
} }
void Vertex(double x, double y, double z) void Vertex(double x, double y, double z)
@@ -137,14 +205,24 @@ void DrawFeet()
foot6.DrawFoot(); foot6.DrawFoot();
} }
void SetFeetCoordinatesUsingAnimation() void RobotWalk()
{ {
foot1.SetFootCoordinates(Animation(2)); if (robotStanding)
foot2.SetFootCoordinates(Animation(3)); {
foot3.SetFootCoordinates(Animation(4));// if (!animationRepeatComplete)
foot4.SetFootCoordinates(Animation(1));// if (timerAnimation.delay(animationSpeed))
foot5.SetFootCoordinates(Animation(0)); animationSubStep++;
foot6.SetFootCoordinates(Animation(5));
animationRepeat = true;
animationSpeed = 20;
foot1.SetFootCoordinates(Animation(walk1, 6, 2)); // BULLSHIT BUG
foot1.SetFootCoordinates(Animation(walk1, 6, 2));
foot2.SetFootCoordinates(Animation(walk1, 6, 3));
foot3.SetFootCoordinates(Animation(walk1, 6, 4));//
foot4.SetFootCoordinates(Animation(walk1, 6, 1));//
foot5.SetFootCoordinates(Animation(walk1, 6, 0));
foot6.SetFootCoordinates(Animation(walk1, 6, 5));
}
} }
void DrawGround() void DrawGround()
@@ -162,28 +240,34 @@ void DrawGround()
void DrawTestSpots() void DrawTestSpots()
{ {
drawTestSpot(new PVector((Animation(2).x + point1.x), /*drawTestSpot(new PVector((Animation(walk1, 6, 2).x + point1.x),
robotHeigth, robotHeigth,
(Animation(2).z - point1.z)), false); (Animation(walk1, 6, 2).z - point1.z)), false);
drawTestSpot(new PVector((Animation(3).x + point2.x), drawTestSpot(new PVector((Animation(walk1, 6, 3).x + point2.x),
robotHeigth, robotHeigth,
(Animation(3).z - point2.z)), false); (Animation(walk1, 6, 3).z - point2.z)), false);
drawTestSpot(new PVector((Animation(4).x + point3.x), drawTestSpot(new PVector((Animation(walk1, 6, 4).x + point3.x),
robotHeigth, robotHeigth,
(Animation(4).z - point3.z)), false); (Animation(walk1, 6, 4).z - point3.z)), false);
drawTestSpot(new PVector((Animation(1).x - point4.x), drawTestSpot(new PVector((Animation(walk1, 6, 1).x - point4.x),
robotHeigth, robotHeigth,
(Animation(1).z - point4.z)), true); (Animation(walk1, 6, 1).z - point4.z)), true);
drawTestSpot(new PVector((Animation(0).x - point5.x), drawTestSpot(new PVector((Animation(walk1, 6, 0).x - point5.x),
robotHeigth, robotHeigth,
(Animation(0).z - point5.z)), true); (Animation(walk1, 6, 0).z - point5.z)), true);
drawTestSpot(new PVector((Animation(5).x - point6.x), drawTestSpot(new PVector((Animation(walk1, 6, 5).x - point6.x),
robotHeigth, robotHeigth,
(Animation(5).z - point6.z)), true); (Animation(walk1, 6, 5).z - point6.z)), true);*/
} }
void DrawBody() void DrawBody()
{ {
if (!robotStanding)
{
rotationX = 0;
rotationY = 0;
rotationZ = 0;
}
// Rotate body // Rotate body
rotateX(radians(-1*rotationX)); rotateX(radians(-1*rotationX));
rotateY(radians(-1*rotationY)); rotateY(radians(-1*rotationY));
@@ -210,21 +294,64 @@ void DrawBody()
Vertex(point1.x, point1.y, point1.z); Vertex(point1.x, point1.y, point1.z);
endShape(); endShape();
SetFeetCoordinatesUsingAnimation(); RobotStandup();
RobotWalk();
DrawFeet(); DrawFeet();
} }
PVector []standup = new PVector[6]; PVector []standup = new PVector[2];
int standupStep = 0;
void RobotStandup() void RobotStandup()
{ {
standup[0] = new PVector(3, 5, 0); standup[0] = new PVector(5, 6, 0);
standup[1] = new PVector(12, robotHeigth, -5); standup[1] = new PVector(10, 6, 0);
standup[2] = new PVector(12, robotHeigth, -5);
if (!robotStanding) if (!robotStanding)
{ {
if (!animationRepeatComplete)
if (timerAnimation.delay(animationSpeed))
animationSubStep++;
animationRepeat = false;
animationSpeed = 250;
switch (standupStep)
{
case 0:
foot1.SetFootCoordinates(Animation(standup, 2, 0));
foot2.SetFootCoordinates(Animation(standup, 2, 0));
foot3.SetFootCoordinates(Animation(standup, 2, 0));//
foot4.SetFootCoordinates(Animation(standup, 2, 0));//
foot5.SetFootCoordinates(Animation(standup, 2, 0));
foot6.SetFootCoordinates(Animation(standup, 2, 0));
if (animationRepeatComplete)
{
animationRepeatComplete = false;
standupStep = 1;
animationStep = 0;
}
break;
case 1:
foot1.SetFootCoordinates(Animation(standup[1], walk1[2]));
foot2.SetFootCoordinates(Animation(standup[1], walk1[3]));
foot3.SetFootCoordinates(Animation(standup[1], walk1[4]));//
foot4.SetFootCoordinates(Animation(standup[1], walk1[1]));//
foot5.SetFootCoordinates(Animation(standup[1], walk1[0]));
foot6.SetFootCoordinates(Animation(standup[1], walk1[5]));
if (animationRepeatComplete)
{
robotStanding = true;
animationRepeatComplete = false;
standupStep = 2;
}
break;
}
} }
} }
@@ -52,10 +52,6 @@ void draw()
rotationZ = ( counterZRotation%(rotationRange*4) < (rotationRange*2) ? -rotationRange+counterZRotation%(rotationRange*2) : rotationRange+(-1*(counterZRotation%(rotationRange*2))) ); rotationZ = ( counterZRotation%(rotationRange*4) < (rotationRange*2) ? -rotationRange+counterZRotation%(rotationRange*2) : rotationRange+(-1*(counterZRotation%(rotationRange*2))) );
// Animation // Animation
if (timerAnimation.delay(1))
{
animationSubStep++;
}
if (timerZRotation.delay(25)) if (timerZRotation.delay(25))
{ {
counterRotation-=0.012f; counterRotation-=0.012f;