Rework HexapodClass

Imported from 'hexapod 4.rar'.
This commit is contained in:
mangavalk committed 2014-10-13 00:49:00 +02:00
1 parent 00bf3187fe
commit 0447cb8c7a
2 files changed
+183 -60

No files matched your search

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