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 / 3d model wrongly rotation

Author
Message
iammfa
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 18th Nov 2009 17:10
Hi,
In my example I success rotate 3d model with moving mouse cursor but it rotate wrongly not in the correct direction, i attached my source code, please I hope someone guide me..
this my code also:

Attachments

Login to view attachments
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Nov 2009 21:05
Forum advice: There is no need to create three threads about the same problem. You don't have more chance of getting an answer.

About your question: I'm afraid the code is wrong by principle. There is no such thing as "distance between mouse and 3D object" or between the mouse coordinates and a 3D axis. The mouse coordinates are measured in screen pixels and they are 2D. The object coordinates are measured in world units and they are 3D. It's no use to compare the two or try to calculate angles from them.

What you need instead is to change the rotation angle of the model according to how much the mouse has moved up/down or left/right on the screen in the last loop. For example, add the dbMouseMoveX() value to the current Z rotation angle of the object. This way you can make a more or less intuitive rotation around one axis only. I can give you an example code for that, a bit later.

However, if you want a 3D model to always "look at" where the mouse is positioned on the screen, I don't have a solution off the top of my head. I'm sure it's possible but it requires a bit more thinking.
iammfa
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 18th Nov 2009 21:53
Is the function "dbMouseMoveX()" has 3D coordinates ..?
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Nov 2009 22:24
No, it is also 2D.

Here is a very simple code which creates a box and then rotates it around two axes with the mouse. Does this look like what you wanted to do?



I'm using the dbMouseMoveX/Y functions here, which return 2D pixels, but in this case it doesn't matter because they are used as "speed" of turn, not as coordinates.
iammfa
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 18th Nov 2009 22:42 Edited at: 18th Nov 2009 22:44
Thanks Mireben for your efforts, i change some codes to make cube rotate around one axis:


but this isn't my aim, my aim is make this cube look toward mouse cursor, like game ZUMA if you played it before ..show this link:

http://www.youtube.com/watch?v=XM0oqEuRju0

i aim to make cube like frog, always look to cursor
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Nov 2009 23:14
That's a nice game, haven't seen it before.
I realized later that the above code is not what you were looking for. Maybe this is more like it:



This rotates a pointed cone around the Z axis so that its tip always looks towards the mouse cursor. You were on the right track with dbScreenWidth: the mouse coordinates are compared to the middle of the screen and the rotation angle is calculated from that.
iammfa
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 19th Nov 2009 10:21
This is what I dream..
I want some clarification about part of code:
Quote: "float XDiff = 0;"

Is "XDiff" value must be "0.0" not "0" because it's "float" ..?

Quote: "AngleZ = dbAtanFull(-XDiff, -YDiff);"

Why you used "-" operator before each variables ..?

Quote: "dbDeleteObject(1);"

Is this enough to empty memory from my data..?
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 19th Nov 2009 21:23
Quote: "Is "XDiff" value must be "0.0" not "0" because it's "float" ..?"


It's not necessary to write out the decimal part if it is zero anyway. Conversion from integer to float is automatic.

Quote: "Why you used "-" operator before each variables ..?"


Because the way I calculated the angle of the mouse cursor relative to the center of the display, the mouse rotation is clockwise. But if you rotate an object around the Z axis, it will turn counter-clockwise, so if I don't use negative, then the tip of the cone will look in the opposite direction.

If you reverse the deductions, then the negative is not needed. This will work as well:




Quote: "Is this enough to empty memory from my data..? "


In this small program yes, because only one object was created. Usually you need to delete everything that was created with dbMakeObject commands, or loaded as a resource from disk (image files, sounds) and definitely all structures for which you allocated memory with the "new" command of C++.

Maybe the 3D objects are even automatically cleared when the program exits but it's a good practice to delete them.
iammfa
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 19th Nov 2009 21:49
Thanks "Mireben" for your efforts,

regards
iammfa

Login to post a reply

Server time is: 2024-11-20 09:24:54
Your offset time is: 2024-11-20 09:24:54