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.

DarkBASIC Discussion / moving objects with a mouse

Author
Message
Bob_42
19
Years of Service
User Offline
Joined: 15th Sep 2006
Location: Guernsey
Posted: 16th Oct 2006 21:42
well to be more precise limbs, but that shouldn't change the principle, i want the limb (depending on which is selected), to be moved on the x and z axis when the left mouse button is pressed and on the y axis when the right button is pressed, now i can do the y-axis fine, but i am struggling on the x and z-axis, infact i have no idea where to start...

to be more precise on how i want the limbs to move, if you have ever used truspace (probably other 3D programs as well), when you have the object selected and the move object function selected, the object will move in the direction that the mouse is moving, however to make things more complicated, the camera position isn't fixed

thanks in advance

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Oct 2006 23:14
Hello,

If you can move it on the y axis, why can't you use the same method to move the limb on the z or x axis?

You should be using the OFFSET LIMB command to change the position of the limb. Also use MOUSEMOVEX(), MOUSEMOVEY() - I don't have a mouse with a wheel so I never use MOUSEMOVEZ() so I can't help you on that one.

Essentially, you will test if the proper button is pressed. If so, you want to test the mouse movement. If the mouse movement is < 0 then offset the limb in a direction on an axis at some increment. If the mouse movement > 0 go in the opposite direction.

As far as the camera, you can train it on the limb if you want with the SET CAMERA TO FOLLOW COMMAND. I'll leave that to you.



Enjoy your day.
Bob_42
19
Years of Service
User Offline
Joined: 15th Sep 2006
Location: Guernsey
Posted: 18th Oct 2006 01:16
maybe i wasn't clear enough, if i move the mouse right, it doesn't always mean i want it to move on x-axis, i'll try and explain through a picture, i think it will be easier



so in the top pic when i move the mouse right i want the limb (represented by a ball) to move along the x-axis, however in the second pic i want the limb to move along the z-axis...

and after drawing that pic it gave me an idea of how i might go about this, guess i should have done that first

and the reason i can't apply the other movement is because the limb can only travel in one direction when i have the right-mouse button clicked, but when i have the left clicked it can travel in two directions

anyway, thanks for trying, but its not exactly what i want, i'll give it a try and i'll post if i get anywhere

CreamPie
19
Years of Service
User Offline
Joined: 20th Jul 2006
Location:
Posted: 18th Oct 2006 02:54 Edited at: 18th Oct 2006 02:57
Bob_42,

If I am correct, an easy way to state what effect you are wanting, is to say that whatever limb you have held to drag, should drag across the screen relative to the orientation of the camera?

So, as in the image below, if the camera is facing in towards the object at a 135° and the user drags the object across the screen to the right, the object would move at a -45° outward. According to the image, is this a good example of the type of object dragging you wish for?

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Oct 2006 06:25
Ok,

Sounds like you want to move the object left-right, up-down, in-out in relation to the camera angle. If you could rotate the axes, you'd be set with the code example I gave you, but you can't so you have to calculate the rotation angle based on the current camera position and angle.

You can retrieve the camera angle with CAMERA ANGLE X() y and z.

If you rotate the camera around the object, indirectly there's an imaginary angle that the object is rotating in the opposite direction of the camera. You can use the angle of rotation from each axis to calculate a new point from the objects current position to a proposed new position based on the angle. If you rotated the camera 45 degrees on the y axis and dropped it back -x and -z some amount so that it was pointing at your object as is displayed in picture 1 of CreamPie's post, if you had originally a point (x,0,0) it would become (newx,0,-newz).

For each rotation around a specifc axis, assuming you have the rotation order set to XYZ, you have to calculate the two remaining terms (ie if you rotate around Y, the remaining terms are x and z), rotate again and calculate the next terms using any new values, then rotate again, and calculate to get your final values. You can do all of this very accurately with matrix math using a 4x4 matrix. You can also do it using polar coordinates to cartesian coordinate conversions.

In the example we're talking about here, since we only rotated the camera around y, we only need to solve for two x and z coordinates.

Assuming that we want to move the object along the x axis from (0,0,0) to (100,0,0), the new point rotated around y -45 degrees would be:



What would be happening in the main code would be to move the object relative to whatever angle the camera is facing, that is why we have to calculate the new object positions as if the object itself was being rotated.

If you adapt this approach to the code snippet I posted, it should work. I can see it in my brain, I just don't feel like typing it up right now.

Enjoy your day.

Login to post a reply

Server time is: 2026-07-08 19:19:24
Your offset time is: 2026-07-08 19:19:24