PDA

View Full Version : Calculating offset



Fabricio
11-24-2008, 02:19 PM
i don't know exactly how to explain. :o

Well, I'm moving 3d objects using mouse, but the problem is: when I click on an object, it 'jumps' to the clicked position. And I dont want that it jumps, but i want it stay at the same position, so it go moving while mouse is moving.

ex. If i click on left side of a box, the box jumps to that clicked place. But, I want to move the object clicking at his left side without it jumps to that left side. (wow, i really dont know how explain).

I hope you can understand.

i know i need to calc an offset, but how?

ZbuffeR
11-24-2008, 03:11 PM
When a click is read, store the x,y mouse postion (global variables, whatever else depending on your coding skills).
Then, as the mouse move, compare its current x,y to the stored x,y.
Add the deltas to the object x,y.

Fabricio
11-24-2008, 04:22 PM
I don't know how to calculate. :(

ZbuffeR
11-25-2008, 02:41 AM
Sorry, but this is very simple.
Please be more precise, what is you problem exactly ?

Rosario Leonardi
11-25-2008, 06:08 PM
To compute the offset is a simple vector subtraction :-|

offset = ClickedPoint-ObjectCenter;

Fabricio
11-26-2008, 10:50 AM
Take a look at this flash file (http://www.faculdadesalesiana.edu.br/boxes.swf).

In flash file:
1. Move box #2. You can see anywhere you click on the box, you move and it doesn't jumps.

2. Move box #1. You can see anywhere you click on it, it jumps to mouse cursor.

I want to do like box #2, but in 3d.

(PS: flash got automatic function to do that)

ZbuffeR
11-26-2008, 02:19 PM
Hey, if you can't do a substraction yourself, you should probably stay on Flash for a while ...

Fabricio
11-27-2008, 02:28 AM
The problem is something is going wrong with that subtraction. Don't work.

Ah, forget. Thanks.