Archived

This topic is now archived and is closed to further replies.

Candy

How to make a dolphin model swim like a dolphin?

Recommended Posts

Hello everyone, I am now making a dolphin swim in the 3D world by OpenGL, I am now able to transform the model to any position in the world. However, the dolphin doesn''t look like swimming across the sea, it just like sliding in the sea. Therefore, how can I make the model swims in the "wave" form? If you can, please teach me with some examples or tutorials. Thanks you very much.

Share this post


Link to post
Share on other sites
Thanks static_matt13 & flegmato.

My expected output is similar to the dolphin example in directX SDK. In that example, the dolphin is swimming in a "wave" form which looks like a real dolphin.

However in my project, my dolphin just swim(translate) from one position to another position in a straight way just like a car...

Share this post


Link to post
Share on other sites
DirectX uses vertex shaders to accomplish the dolphin effect. In OpenGL, you can use vertex programs for the same thing.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
The dolphin would need to have skeletal animation sequence and you would need to play it in you code. I don thtink he is talking about moving the dolphin in a wave, he wants it to move the dolphin in a line (or whatever) and as it moves, the body will form to make it seem like it is flapping its fins.

Be more specific next time to get better answers.

IT Administrator / Software Engineere
http://drdsoftware.cjb.net

Share this post


Link to post
Share on other sites
Not too familiar with OpenGL vertex stuff, so you''ll have to find tutorials for yourself... but the OpenGL website would probably be a good place to start (it''s an extension).


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
You''re probably best off learning the techniques behind skeletal animation in software (eg do it on the cpu using matrix math) and then learn the hardware way afterwards. Otherwise you may get too bogged down in extension hell to learn anything. If you are only using one model it will make no performance difference anyway.

There''s a good turorial on skeletal animation on Brett Porter''s site. It follows on from his milkshape model loading tutorial on nehe.gamedev.net.

Dan

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites