Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve animation.

Signed-off-by: Paul Brook <paul@codesourcery.com>
  • Loading branch information...
commit ac30f1e66effe6e7fa636c29a9bf84400b3d6cfd 1 parent 92c2c71
@pbrook authored
Showing with 110 additions and 85 deletions.
  1. +28 −3 gl2.c
  2. +82 −82 models/duck.x3d
View
31 gl2.c
@@ -312,6 +312,7 @@ static void m_swizzle(matrix *m, int x, int y, int rot)
}
static float sprite_angle1;
+static float sprite_angle2;
static void RenderGroup(object_group *g)
{
@@ -327,6 +328,16 @@ static void RenderGroup(object_group *g)
case 'R':
m_rotate_x(&mat, -sprite_angle1);
break;
+ case 'B':
+ m_rotate_x(&mat, sprite_angle2 / 2.0f);
+ break;
+ case 'N':
+ case 'l':
+ m_rotate_x(&mat, sprite_angle2);
+ break;
+ case 'r':
+ m_rotate_x(&mat, -sprite_angle2);
+ break;
case 'U':
m_rotate_x(&mat, fabsf(sprite_angle1) / 2.0f);
break;
@@ -338,9 +349,9 @@ static void RenderGroup(object_group *g)
break;
}
+ m_translate(&mat, g->translate[0], g->translate[1], g->translate[2]);
m_mul(&eye, &prev, &mat);
- m_translate(&eye, g->translate[0], g->translate[1], g->translate[2]);
for (child = g->child; child; child = child->next) {
RenderGroup(child);
@@ -552,6 +563,11 @@ void RenderFrame(void)
} else {
sprite_angle1 = 0.0f;
}
+ if (rot == 2) {
+ sprite_angle2 = (M_PI / 2) - sprite_angle1;
+ } else {
+ sprite_angle2 = -sprite_angle1;
+ }
RenderSprite(&model_farmer, player_x + 4, player_y - 8, rot);
@@ -569,17 +585,26 @@ void RenderFrame(void)
switch (duck[n].mode) {
case DUCK_BORED:
sprite_angle1 = 0.0f;
+ sprite_angle2 = 0.0f;
break;
case DUCK_STEP:
sprite_angle1 = M_PI / 4;
if ((duck[n].x ^ duck[n].y) & 8) {
sprite_angle1 = -sprite_angle1;
}
+ sprite_angle2 = 0.0f;
+ break;
+ case DUCK_EAT2:
+ case DUCK_EAT4:
+ sprite_angle1 = 0.0f;
+ sprite_angle2 = -M_PI / 4;
break;
- default: /* DUCK_EAT[1-4] */
- rot = 0;
+ case DUCK_EAT3:
sprite_angle1 = 0.0f;
+ sprite_angle2 = -M_PI / 2;
break;
+ default:
+ abort();
}
RenderSprite(&model_duck, x + 4, duck[n].y - 12, rot);
}
View
164 models/duck.x3d
@@ -15,8 +15,8 @@
groundColor="0.0509 0.0509 0.0509"
skyColor="0.0509 0.0509 0.0509"
/>
- <Transform DEF="Neck.N"
- translation="0 -4 5"
+ <Transform DEF="Body.B"
+ translation="0 0 4"
scale="1 1 1"
rotation="1 0 0 0"
>
@@ -25,7 +25,7 @@
scale="1 1 1"
rotation="1 0 0 0"
>
- <Group DEF="group_ME_Cube.005">
+ <Group DEF="group_ME_Cube">
<Shape>
<Appearance>
<Material DEF="MA_Material"
@@ -39,15 +39,15 @@
</Appearance>
<IndexedTriangleSet solid="true"
creaseAngle="0.5236"
- index="0 1 2 0 2 3 4 5 6 4 6 7 3 2 8 3 8 9 5 10 11 5 11 6 10 12 13 10 13 11 2 6 11 3 10 5 11 13 14 13 15 16 13 16 14 8 2 17 17 2 11 17 11 14 17 14 16 17 16 18 12 10 19 20 12 19 20 19 21 3 9 22 22 19 10 22 10 3 19 22 23 19 23 21 13 12 20 13 20 15 15 20 24 15 24 25 26 17 18 27 26 18 26 8 17 28 23 22 9 28 22 28 29 23 30 31 25 30 25 24 29 30 24 31 27 25 27 31 32 27 32 26 30 29 28 30 28 33 32 31 34 32 34 35 26 32 35 31 30 36 31 36 34 8 26 35 8 35 37 9 8 37 9 37 38 0 3 5 0 5 4 6 2 1 6 1 7 25 18 16 15 25 16 25 27 18 24 21 23 29 24 23 24 20 21 33 39 36 33 36 30 28 39 33 9 38 39 9 39 28 36 39 35 36 35 34 37 35 39 37 39 38 "
+ index="0 1 2 0 2 3 0 3 4 0 4 5 5 4 6 5 6 7 7 6 8 7 8 9 1 0 10 1 10 11 11 10 9 11 9 12 3 2 13 3 13 14 15 8 14 15 14 13 11 12 16 2 1 17 2 17 18 17 1 11 16 17 11 12 9 19 12 19 16 8 15 20 8 20 21 22 23 9 22 9 8 21 22 8 23 19 9 24 25 26 24 26 27 24 28 29 30 25 31 31 25 32 24 29 33 25 24 33 25 33 32 23 22 34 23 34 35 36 37 18 36 18 17 38 39 27 38 27 26 18 37 38 18 38 20 36 17 16 36 16 39 37 36 39 37 39 38 0 5 10 4 3 14 10 5 7 10 7 9 14 8 6 14 6 4 15 13 18 2 18 13 16 27 39 20 38 26 18 20 15 19 23 29 19 28 16 19 29 28 21 31 22 21 20 30 31 21 30 20 26 25 20 25 30 16 28 24 16 24 27 32 34 22 31 32 22 33 29 23 33 23 35 32 33 35 32 35 34 "
>
- <Coordinate point="-1.16667 0 -5.96046e-08 1.16667 0 -5.96046e-08 1.16667 3 3 -1.16667 3 3 -1.16667 0 -1.5 -1.16667 4 2.5 1.16667 4 2.5 1.16667 0 -1.5 1.16667 3 3.5 -1.16667 3 3.5 -1.16667 4 3 1.16667 4 3 -1.16667 5 3.5 1.16667 5 3.5 2.16667 4 3.5 1.16667 5 4.5 2.16667 4 4.5 2.16667 3 3.5 2.16667 3 4.5 -2.16667 4 3.5 -1.16667 5 4.5 -2.16667 4 4.5 -2.16667 3 3.5 -2.16667 3 4.5 -1.16667 4 5 1.16667 4 5 1.16667 3 4 1.16667 3 5 -1.16667 3 4 -1.16667 3 5 -0.63889 3 5 0.638888 3 5 0.638888 3 4 -0.63889 3 4 0.638888 2 4.5 0.638888 2 4 -0.63889 2 4.5 0.666666 2 3.5 -0.666668 2 3.5 -0.63889 2 4 " />
+ <Coordinate point="2 3 1.5 2 3 -0.5 -2 3 -0.5 -2 3 1.5 -2 2 2 2 2 2 -2 3.57628e-07 2 2 -5.96046e-07 2 -3 -0.999999 1.5 3 -1 1.5 3 2 1.5 3 2 -0.5 3 -1 -0.5 -3 2 -0.5 -3 2 1.5 -3 -1 -0.5 2 -2 -1 2 2 -1 -2 2 -1 2 -2 1 -2 -2 -1 -2 -2 1 -1.16667 -2 1 1.16667 -2 1 1.16667 -4 -0.5 -1.16667 -4 -0.5 -1.16667 -3 -1 1.16667 -3 -1 2 -3 -0.5 1.16667 -3 1 -2 -3 -0.5 -1.16667 -3 1 -1.16667 -4 1 1.16667 -4 1 -1.16667 -2 1.5 1.16667 -2 1.5 1.16667 1 -1.5 -1.16667 1 -1.5 -1.16667 -1 -1.5 1.16667 -1 -1.5 " />
</IndexedTriangleSet>
</Shape>
</Group>
</Transform>
- <Transform DEF="Beak.U"
- translation="0 2 4.25"
+ <Transform DEF="Neck.N"
+ translation="0 -4 1"
scale="1 1 1"
rotation="1 0 0 0"
>
@@ -56,49 +56,74 @@
scale="1 1 1"
rotation="1 0 0 0"
>
- <Group DEF="group_ME_Cube.004">
+ <Group DEF="group_ME_Cube.005">
<Shape>
<Appearance>
<Material USE="MA_Material" />
</Appearance>
<IndexedTriangleSet solid="true"
creaseAngle="0.5236"
- index="0 1 2 0 2 3 4 5 6 4 6 7 0 4 7 0 7 1 1 7 6 1 6 2 2 6 5 2 5 3 4 0 3 4 3 5 "
+ index="0 1 2 0 2 3 4 5 6 4 6 7 3 2 8 3 8 9 5 10 11 5 11 6 10 12 13 10 13 11 2 6 11 3 10 5 11 13 14 13 15 16 13 16 14 8 2 17 17 2 11 17 11 14 17 14 16 17 16 18 12 10 19 20 12 19 20 19 21 3 9 22 22 19 10 22 10 3 19 22 23 19 23 21 13 12 20 13 20 15 15 20 24 15 24 25 26 17 18 27 26 18 26 8 17 28 23 22 9 28 22 28 29 23 30 31 25 30 25 24 29 30 24 31 27 25 27 31 32 27 32 26 30 29 28 30 28 33 32 31 34 32 34 35 26 32 35 31 30 36 31 36 34 8 26 35 8 35 37 9 8 37 9 37 38 0 3 5 0 5 4 6 2 1 6 1 7 25 18 16 15 25 16 25 27 18 24 21 23 29 24 23 24 20 21 33 39 36 33 36 30 28 39 33 9 38 39 9 39 28 36 39 35 36 35 34 37 35 39 37 39 38 "
>
- <Coordinate point="0.5 -5.96046e-08 0 0.5 -2 0 -0.5 -2 0 -0.5 3.57628e-07 0 0.5 -5.36442e-07 0.25 -0.5 0 0.25 -0.5 -2 0.25 0.5 -2 0.25 " />
+ <Coordinate point="-1.16667 0 -5.96046e-08 1.16667 0 -5.96046e-08 1.16667 3 3 -1.16667 3 3 -1.16667 0 -1.5 -1.16667 4 2.5 1.16667 4 2.5 1.16667 0 -1.5 1.16667 3 3.5 -1.16667 3 3.5 -1.16667 4 3 1.16667 4 3 -1.16667 5 3.5 1.16667 5 3.5 2.16667 4 3.5 1.16667 5 4.5 2.16667 4 4.5 2.16667 3 3.5 2.16667 3 4.5 -2.16667 4 3.5 -1.16667 5 4.5 -2.16667 4 4.5 -2.16667 3 3.5 -2.16667 3 4.5 -1.16667 4 5 1.16667 4 5 1.16667 3 4 1.16667 3 5 -1.16667 3 4 -1.16667 3 5 -0.63889 3 5 0.638888 3 5 0.638888 3 4 -0.63889 3 4 0.638888 2 4.5 0.638888 2 4 -0.63889 2 4.5 0.666666 2 3.5 -0.666668 2 3.5 -0.63889 2 4 " />
</IndexedTriangleSet>
</Shape>
</Group>
</Transform>
- </Transform>
- <Transform DEF="Beak.D"
- translation="0 2 4.25"
- scale="1 1 1"
- rotation="1 0 0 0"
- >
- <Transform
- translation="0 0 0"
+ <Transform DEF="Beak.U"
+ translation="0 2 4.25"
scale="1 1 1"
rotation="1 0 0 0"
>
- <Group DEF="group_ME_Cube.003">
- <Shape>
- <Appearance>
- <Material USE="MA_Material" />
- </Appearance>
- <IndexedTriangleSet solid="true"
- creaseAngle="0.5236"
- index="0 1 2 0 2 3 4 5 6 4 6 7 0 4 7 0 7 1 1 7 6 1 6 2 2 6 5 2 5 3 4 0 3 4 3 5 "
- >
- <Coordinate point="0.5 -5.96046e-08 -0.25 0.5 -2 -0.25 -0.5 -2 -0.25 -0.5 3.57628e-07 -0.25 0.5 -5.36442e-07 0 -0.5 0 0 -0.5 -2 0 0.5 -2 0 " />
- </IndexedTriangleSet>
- </Shape>
- </Group>
+ <Transform
+ translation="0 0 0"
+ scale="1 1 1"
+ rotation="1 0 0 0"
+ >
+ <Group DEF="group_ME_Cube.004">
+ <Shape>
+ <Appearance>
+ <Material USE="MA_Material" />
+ </Appearance>
+ <IndexedTriangleSet solid="true"
+ creaseAngle="0.5236"
+ index="0 1 2 0 2 3 4 5 6 4 6 7 0 4 7 0 7 1 1 7 6 1 6 2 2 6 5 2 5 3 4 0 3 4 3 5 "
+ >
+ <Coordinate point="0.5 -5.96046e-08 0 0.5 -2 0 -0.5 -2 0 -0.5 3.57628e-07 0 0.5 -5.36442e-07 0.25 -0.5 0 0.25 -0.5 -2 0.25 0.5 -2 0.25 " />
+ </IndexedTriangleSet>
+ </Shape>
+ </Group>
+ </Transform>
+ </Transform>
+ <Transform DEF="Beak.D"
+ translation="0 2 4.25"
+ scale="1 1 1"
+ rotation="1 0 0 0"
+ >
+ <Transform
+ translation="0 0 0"
+ scale="1 1 1"
+ rotation="1 0 0 0"
+ >
+ <Group DEF="group_ME_Cube.003">
+ <Shape>
+ <Appearance>
+ <Material USE="MA_Material" />
+ </Appearance>
+ <IndexedTriangleSet solid="true"
+ creaseAngle="0.5236"
+ index="0 1 2 0 2 3 4 5 6 4 6 7 0 4 7 0 7 1 1 7 6 1 6 2 2 6 5 2 5 3 4 0 3 4 3 5 "
+ >
+ <Coordinate point="0.5 -5.96046e-08 -0.25 0.5 -2 -0.25 -0.5 -2 -0.25 -0.5 3.57628e-07 -0.25 0.5 -5.36442e-07 0 -0.5 0 0 -0.5 -2 0 0.5 -2 0 " />
+ </IndexedTriangleSet>
+ </Shape>
+ </Group>
+ </Transform>
</Transform>
</Transform>
</Transform>
- <Transform DEF="Body"
- translation="0 0 4"
+ <Transform DEF="Leg.R"
+ translation="-1 0 3"
scale="1 1 1"
rotation="1 0 0 0"
>
@@ -107,69 +132,44 @@
scale="1 1 1"
rotation="1 0 0 0"
>
- <Group DEF="group_ME_Cube">
+ <Group DEF="group_ME_Cube.002">
<Shape>
<Appearance>
<Material USE="MA_Material" />
</Appearance>
<IndexedTriangleSet solid="true"
creaseAngle="0.5236"
- index="0 1 2 0 2 3 0 3 4 0 4 5 5 4 6 5 6 7 7 6 8 7 8 9 1 0 10 1 10 11 11 10 9 11 9 12 3 2 13 3 13 14 15 8 14 15 14 13 11 12 16 2 1 17 2 17 18 17 1 11 16 17 11 12 9 19 12 19 16 8 15 20 8 20 21 22 23 9 22 9 8 21 22 8 23 19 9 24 25 26 24 26 27 24 28 29 30 25 31 31 25 32 24 29 33 25 24 33 25 33 32 23 22 34 23 34 35 36 37 18 36 18 17 38 39 27 38 27 26 18 37 38 18 38 20 36 17 16 36 16 39 37 36 39 37 39 38 0 5 10 4 3 14 10 5 7 10 7 9 14 8 6 14 6 4 15 13 18 2 18 13 16 27 39 20 38 26 18 20 15 19 23 29 19 28 16 19 29 28 21 31 22 21 20 30 31 21 30 20 26 25 20 25 30 16 28 24 16 24 27 32 34 22 31 32 22 33 29 23 33 23 35 32 33 35 32 35 34 "
+ index="0 1 2 0 2 3 4 0 3 4 3 5 5 3 2 5 2 6 6 2 1 6 1 7 0 4 7 0 7 1 6 7 8 6 8 9 7 4 10 7 10 8 4 5 11 4 11 10 10 11 9 10 9 8 9 11 12 9 12 13 11 5 14 11 14 12 6 9 13 6 13 15 5 6 15 5 15 14 14 15 13 14 13 12 "
>
- <Coordinate point="2 3 1.5 2 3 -0.5 -2 3 -0.5 -2 3 1.5 -2 2 2 2 2 2 -2 3.57628e-07 2 2 -5.96046e-07 2 -3 -0.999999 1.5 3 -1 1.5 3 2 1.5 3 2 -0.5 3 -1 -0.5 -3 2 -0.5 -3 2 1.5 -3 -1 -0.5 2 -2 -1 2 2 -1 -2 2 -1 2 -2 1 -2 -2 -1 -2 -2 1 -1.16667 -2 1 1.16667 -2 1 1.16667 -4 -0.5 -1.16667 -4 -0.5 -1.16667 -3 -1 1.16667 -3 -1 2 -3 -0.5 1.16667 -3 1 -2 -3 -0.5 -1.16667 -3 1 -1.16667 -4 1 1.16667 -4 1 -1.16667 -2 1.5 1.16667 -2 1.5 1.16667 1 -1.5 -1.16667 1 -1.5 -1.16667 -1 -1.5 1.16667 -1 -1.5 " />
+ <Coordinate point="2.38419e-07 1 1.5 -1 1 1.5 -1 1.49012e-07 1.5 -3.57628e-07 -3.57628e-07 1.5 0 1 -2.5 0 2.98023e-08 -2.5 -1 8.9407e-08 -2.5 -1 1 -2.5 -1 1 -3 -1 8.9407e-08 -3 0 1 -3 0 2.98023e-08 -3 -1.19209e-07 -1 -3 -1 -1 -3 -1.19209e-07 -1 -2.5 -1 -1 -2.5 " />
</IndexedTriangleSet>
</Shape>
</Group>
</Transform>
- <Transform DEF="Leg.R"
- translation="-1 0 -1"
- scale="1 1 1"
- rotation="1 0 0 0"
- >
- <Transform
- translation="0 0 0"
- scale="1 1 1"
- rotation="1 0 0 0"
- >
- <Group DEF="group_ME_Cube.002">
- <Shape>
- <Appearance>
- <Material USE="MA_Material" />
- </Appearance>
- <IndexedTriangleSet solid="true"
- creaseAngle="0.5236"
- index="0 1 2 0 2 3 4 0 3 4 3 5 5 3 2 5 2 6 6 2 1 6 1 7 0 4 7 0 7 1 6 7 8 6 8 9 7 4 10 7 10 8 4 5 11 4 11 10 10 11 9 10 9 8 9 11 12 9 12 13 11 5 14 11 14 12 6 9 13 6 13 15 5 6 15 5 15 14 14 15 13 14 13 12 "
- >
- <Coordinate point="2.38419e-07 1 1.5 -1 1 1.5 -1 1.49012e-07 1.5 -3.57628e-07 -3.57628e-07 1.5 0 1 -2.5 0 2.98023e-08 -2.5 -1 8.9407e-08 -2.5 -1 1 -2.5 -1 1 -3 -1 8.9407e-08 -3 0 1 -3 0 2.98023e-08 -3 -1.19209e-07 -1 -3 -1 -1 -3 -1.19209e-07 -1 -2.5 -1 -1 -2.5 " />
- </IndexedTriangleSet>
- </Shape>
- </Group>
- </Transform>
- </Transform>
- <Transform DEF="Leg.L"
- translation="1 0 -1"
+ </Transform>
+ <Transform DEF="Leg.L"
+ translation="1 0 3"
+ scale="1 1 1"
+ rotation="1 0 0 0"
+ >
+ <Transform
+ translation="0 0 0"
scale="1 1 1"
rotation="1 0 0 0"
>
- <Transform
- translation="0 0 0"
- scale="1 1 1"
- rotation="1 0 0 0"
- >
- <Group DEF="group_ME_Cube.001">
- <Shape>
- <Appearance>
- <Material USE="MA_Material" />
- </Appearance>
- <IndexedTriangleSet solid="true"
- creaseAngle="0.5236"
- index="0 1 2 0 2 3 4 0 3 4 3 5 5 3 2 5 2 6 6 2 1 6 1 7 0 4 7 0 7 1 6 7 8 6 8 9 7 4 10 7 10 8 4 5 11 4 11 10 10 11 9 10 9 8 9 11 12 9 12 13 11 5 14 11 14 12 6 9 13 6 13 15 5 6 15 5 15 14 14 15 13 14 13 12 "
- >
- <Coordinate point="1 1 1.5 2.98023e-08 1 1.5 -2.38419e-07 1.49012e-07 1.5 1 -3.57628e-07 1.5 1 1 -2.5 1 2.98023e-08 -2.5 -1.19209e-07 8.9407e-08 -2.5 1.78814e-07 1 -2.5 1.78814e-07 1 -3 -1.19209e-07 8.9407e-08 -3 1 1 -3 1 2.98023e-08 -3 1 -1 -3 -1.78814e-07 -1 -3 1 -1 -2.5 -1.78814e-07 -1 -2.5 " />
- </IndexedTriangleSet>
- </Shape>
- </Group>
- </Transform>
+ <Group DEF="group_ME_Cube.001">
+ <Shape>
+ <Appearance>
+ <Material USE="MA_Material" />
+ </Appearance>
+ <IndexedTriangleSet solid="true"
+ creaseAngle="0.5236"
+ index="0 1 2 0 2 3 4 0 3 4 3 5 5 3 2 5 2 6 6 2 1 6 1 7 0 4 7 0 7 1 6 7 8 6 8 9 7 4 10 7 10 8 4 5 11 4 11 10 10 11 9 10 9 8 9 11 12 9 12 13 11 5 14 11 14 12 6 9 13 6 13 15 5 6 15 5 15 14 14 15 13 14 13 12 "
+ >
+ <Coordinate point="1 1 1.5 2.98023e-08 1 1.5 -2.38419e-07 1.49012e-07 1.5 1 -3.57628e-07 1.5 1 1 -2.5 1 2.98023e-08 -2.5 -1.19209e-07 8.9407e-08 -2.5 1.78814e-07 1 -2.5 1.78814e-07 1 -3 -1.19209e-07 8.9407e-08 -3 1 1 -3 1 2.98023e-08 -3 1 -1 -3 -1.78814e-07 -1 -3 1 -1 -2.5 -1.78814e-07 -1 -2.5 " />
+ </IndexedTriangleSet>
+ </Shape>
+ </Group>
</Transform>
</Transform>
</Scene>
Please sign in to comment.
Something went wrong with that request. Please try again.