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.

Newcomers DBPro Corner / Rotating objects with the mouse

Author
Message
Kenny77
18
Years of Service
User Offline
Joined: 7th Oct 2006
Location:
Posted: 19th Jul 2007 23:31
I'm trying to prototype control schemes for a game in Managed DirectX, but the object only rotates 10 degrees then stops, but not 360 degrees.

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 20th Jul 2007 00:12
mousemovex() and mousemovey() gets you the mouse speeds. Use that to check if the mouse it moving.

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Kenny77
18
Years of Service
User Offline
Joined: 7th Oct 2006
Location:
Posted: 20th Jul 2007 00:30
How can I use that information to ultimately rotate the object?
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 20th Jul 2007 00:34
Something like this to start with:

rotate object 1, object angle x() + mousemovey(), object angle y() + mousemovex(), 0

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Kenny77
18
Years of Service
User Offline
Joined: 7th Oct 2006
Location:
Posted: 20th Jul 2007 00:36 Edited at: 20th Jul 2007 00:37
Oh, OK, thanks a lot.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Jul 2007 11:54
It also depends on the camera / object positions. I found the easiest way to do this was with EzRotate. Yes, I am a fan of EzRotate, but using the orbiting functions is the easiest and most reliable way to do this. You can simply orient a dummy object to the camera, at the position of the object, and you are ready to orbit.

Why orbit and not just rotate? Well, you can rotate a set of objects later on if you need to, with only a very small change to the code.

Butter fingers
18
Years of Service
User Offline
Joined: 20th Mar 2006
Location: Mecca
Posted: 20th Jul 2007 20:10
Batvink:

I know there is probably an EZ rotate post about this, but I'll drop it in here anyway (sorry kenny).

Does that mean with easy rotate I could simple rotate my ENTIRE level (all different scenery pieces) at a constant rate?

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 20th Jul 2007 21:02
That bit is possible without EZRotate

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 21st Jul 2007 00:54 Edited at: 21st Jul 2007 00:54
@Zotoaster's Response To Butter Fingers: How would you get everything to stay in position as well?

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 21st Jul 2007 02:02
Well to rotate a bunch of object around a point, all you need to do is get the X and Y angles between the object and that point, generate new angles with the rotation values added on, get the distance between the object and the point, and then reposition like this: (I always use this incase you haven't noticed )

x = px + sin(ay) * cos(ax) * dist
y = py - sin(ax) * dist
z = pz + cos(ay) * cos(ax) * dist

Woo.

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 21st Jul 2007 17:59
@Zotoaster: Oh, thanks I've been wondering about this for ages. Would you mind labeling the variables?

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 22nd Jul 2007 03:59
x, y, z is the new positions of the objects
px, py, pz is the point you wish to rotate the objects around (the center of rotation)
ax, ay are the angles
dist is the distance between the object and px, py, pz

You would get the angle between the object and the center of rotation using atanfull(), and add on the extra rotation to get a and ay.



"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 22nd Jul 2007 04:59
Thanks Zotoaster. I'll keep trying to understand that. When I do... W00t!

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 22nd Jul 2007 05:44
I didnt understand it at first, but I got used to using it, and then I started to get how it works. All you need is basic knowledge of sine and cosine waves to get it, heheh.

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers

Login to post a reply

Server time is: 2024-11-26 12:47:14
Your offset time is: 2024-11-26 12:47:14