I'm trying to make a two yellow pacman (one open mouth and one plain) and also a ghost but I'm quite noob with openGL.
Could someone give me code to make them?
I'm trying to make a two yellow pacman (one open mouth and one plain) and also a ghost but I'm quite noob with openGL.
Could someone give me code to make them?
OpenGL is simply a way to draw things. You need to figure out what you want to draw. A pacman is a reasonably simple shape though: it's just a filled arc.
I assume you already know how to draw a triangle. A circle is essentially a set of triangles with a common middle point:
If you divide it into enough triangles, it will appear completely smooth on the screen. The optimal number will vary depending on your pacman's size.
Now in order to make the "mouth", simply remove some vertices at one place. A pacman's mouth forms a characteristic opening, which is aligned at the direction it's moving and opens at "both ends":
Now, assuming you draw the triangles using a simple loop (pseudocode):
for (i : (0, 360)) {
rotate(i /* degrees */); // ---------- see remark 1.
drawTriangle();
}
To make the opening animation you just need to subtract the current width divided by half from both ends (not that hard, look!):
mouthOpenPercentage = 0.5; // varies from 0 to 1
fullyOpenMouthSize = 0.1; // 10% of the circle, so around 36 deg
numberOfSegments = 360;
mouthOpenSegments = fullyOpenMouthSize * mouthOpenPercentage * numberOfSegments / 2;
for (i : (mouthOpenSegments, numberOfSegments - mouthOpenSegments)) {
rotate(i /* degrees */);
drawTriangle();
}
If it comes out e.g. on top instead of right, simply rotate first by the desired angle to "point" it in the direction you want.
1. I assumed that rotate
means "absolute rotation". Bear that in mind.