View Full Version : Move an object
06-05-2007, 02:51 AM
My goal is to creat a demo with a md2 file.
I have load a md2 file and creat a camera with glulookat.
The md2 object is a gun (M16) and I have put the camera behind the gun (first person view)
I can move the "look at" of the camera with the mouse as if a man moves his head but now I want move the gun as if the man walks and I don't know how do that.
If the eyes are the camera when the man moves the position of the camera change and the gun is behind the man but I want the gun moves with the man.
Can you give me a solution ?
I must use glTranslate and glRotate ?
06-16-2007, 11:37 AM
MD2 models don't have bones or hard bind points, so this'll probably amount to defining some attack points yourself to track the weapon position and orientation.
As I recall, the Quake2 models have all the key-frame animation info for weapons built-in, but you could probably derive it with some clever analysis of the frames (don't think I'd want to try it).
You might want to try the Quake3 models (MD3), since they have well defined tags for mounting weapons and flags and so forth. I actually tinkered with a camera mounted on the head tag just as you did, but it didn't work so hot, wobbled and shimmied like all get out, kinda made me sea sick ;)
06-26-2007, 02:11 AM
Before paypal, before youtube, there was....
This accompanied a Dr Dobbs Article.
The MD2 file has exchangable weapons for players so it probably has some kind of information in there to animate it unless it's implicit. Not used in Jawed's code AFAIK.
If you know where to stick the gun then the rest is simple, that's the only tricky part. It's not really about the gun it's about the transform to hand position...
THAT IS ALL WAY MORE COMPLEX THAN YOUR EXERCISE I THINK....
NOW if your goal is JUST to draw the own gun in an FPS then it's really simple. This is an exercise to teach you about eyespace vs. world space.
You need an FPS kind of an animation where yu can run around. When you have this you simply load the gun while identity in son the modelview stack, pushmatrix, transform to the position relative to the eye, popmatrix and draw everything as normal including the viewing transformation. Simple really.
The links I supplied should help you with the basics of loading and drawing the gun model.
06-26-2007, 02:17 AM
P.S. so in conclusion this is not really about moving an object, it's about positioning an object relative to eyespace on the transformation stack. You can use glTranslate and rotate to position the gun relative to the eye. You Can also use it to run around (inverse and in reverse order since eye transforms are the inverse of model transforms on the modelview).
FWIW it's a very good lesson IMHO.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.