How to make a dolphin model swim like a dolphin?

Started by
11 comments, last by Candy 21 years, 3 months ago
You kind of answered your own question ;¬)

Yes, you can move the model in a sine wave as you describe. You''ll need a Z value too. Use glTranslate to position the model.

However, the dolphin in the direct3d demo you mentioned is an animated (probably skeletally - ''skinned'' in d3d terminology i think) mesh. The tail moves in relation to the rest of the body, for example.

To simulate the effect in the demo you''ll need to animate the model (I''m guessing the model and animation are tucked away in the DXsdk somewhere, so you can nick the data from there) AND translate it in the sine wave pattern.


[size="1"]
Advertisement
Thanks mrbastard~

Since I am not good at math, I still don't know how to implement the sin function into my model... sign*

[edited by - Candy on December 30, 2002 12:06:13 AM]
OK, no problem. A warning though - my maths skills leave more than a little to be desired as well, I''m still relearning the stuff I forgot after school. As such please excuse any theory errors (but feel free to point them out!) That said I''m sure some helpful person will put me right if I''m talking rubbish.

Right. In the d3d demo, the motion in the X and Z axes is circular. The motion in the Y axis is a function of sine and the x/z values. I''m mentioning the circular motion because it helps to point something out - although the sine function should operate on two axes only, it appears to be working on three here - the Y is changed by the sine func, but what combination of X and Z is fed into the sine func?

The answer is that it''s actually only operating on the Y (and some other variable we''ll get into in a minute), but is rotating/translating to a position first. EG we work out where the dolphin is for this frame (decided by it''s velocity or whatever), including any rotation and anything else - basicly everything but the sine curve. THEN we work out where on the sine curve it is.

The trick is to seperate the sine motion and the more general movement of the dolphin into two separate transformations.

The position on the sine curve is governed by the mystery variable I mentioned above. The secret here is, it''s up to you! You could vary the heght using the sine of the current X or Z of the dolphin, but then that would tie the change to movement in that direction (which you probably don''t want).

One alternative is to use a velocity vector (where the dolphin will be next frame) and use the magnitude (the total distance the vector covers) as the input for sin - this way you will get the sine pattern (change in height) no matter which way you move, but the change will still be in relation the the distance the dolphin moves. Other alternative inputs for the func could be time or even user input.

If you want to know more about the ''hierachical transformations'' used, a good way to get a basic handle on them is to get used to the OpenGL matrix stacks. Alternatively look up either "concatenating matrices" (if you use matrices) or "vector bases" if you use vectors in a maths book.

Dan
[size="1"]

This topic is closed to new replies.

Advertisement