Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Moving an Object In 3D Space

Author
Message
ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 16th May 2009 00:38
Hi, I'm trying to move a sphere object in 3D space but for some reason it doesn't work like its supposed to.

Another problem that I'm facing is that I don't know how to make an object move based on which direction its being looked at from, for example, if its being looked at from the X axis rather than the Z axis.

I've included the code that I have below.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 16th May 2009 14:05
Some problems with this code are:

- Do not query mouse movement several times in the same loop, because the next query is already a different value. Query once, store it and check against the stored value.

- If you always add a constant value to the object position regardless of how much the mouse really moved, then the object movement will not be synchronized with mouse movement.

- It is always problematic to translate mouse movement speed into 3D space movement. Adding a constant value to the coordinates each frame makes the speed dependent on the screen update rate of the computer. If you don't want to introduce timers, at least you should have a constant which fine-tunes the mouse speed for your own computer. The value 1 you use is way too fast on my machine but it depends also on the size of the sphere and the camera distance.

Try this code, as my attempt at a solution. Substitute objectID for your object ID number or array index and tune the MouseSpeedDivider to get the right speed for your machine.



This solves your other problem as well: moving left or right regardless how the camera is facing - but at the price that the object must always be rotated to face into the same direction as the camera. If the rotation of the sphere is important in your program (for example, because the texture on one side of the planet does not look the same as on the other side), then I don't know an easy way to interpret "left" and "right" without advanced trigonometric calculations. If someone else has figured out an easy solution, I'd like to know that too. At present I'm trying to implement a way of "dragging" objects for my level editor and it's not completely working yet.

One more thing: notice that in the above code, I don't need to test separately for "left-right" and "up-down" because the return value of the MouseMove functions is signed positive or negative.

Does that help a bit?
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 16th May 2009 14:44 Edited at: 16th May 2009 14:57
OK half an hour later I found a better solution for you which does not involve rotating the object and it will still move left-right relative to the camera:



Edit: Hmm, on second thoughts that might solve my level editor problem too. Thanks for asking the question.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 16th May 2009 20:08
Here is the last version: this code will keep the sphere under the mouse cursor as you are moving it.

ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 26th May 2009 21:33
Thanks Mireben.

It works perfectly.

Login to post a reply

Server time is: 2024-11-25 10:47:03
Your offset time is: 2024-11-25 10:47:03