# Calculating offset

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?

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.

I don’t know how to calculate.

Sorry, but this is very simple.
Please be more precise, what is you problem exactly ?

To compute the offset is a simple vector subtraction

offset = ClickedPoint-ObjectCenter;

Take a look at this flash file.

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)

Hey, if you can’t do a substraction yourself, you should probably stay on Flash for a while …

The problem is something is going wrong with that subtraction. Don’t work.

Ah, forget. Thanks.