Jump to content
  • Advertisement
Sign in to follow this  
MMWizard

Camera related object translation?????

This topic is 4107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm building a 3D web application and everything goes well except for 0ne thing. After i've added a object to the scene. The user can select and drag it to the proper place. But the problem is. If the user looks at the object form the opostite site. The object dragging is in reverse. So the object moves, while dragging, away from the mouse cursor. Note, that i can only retrieve the camera's viewpointWorldPosition(x,y,z) and the position of the object. There is no camera angle or viewing direction info available. so u have to asume that the object is in front of the camera. Can anybody help me please???? U can go to http://www.fictief.com/splusb/ to view my web application. Because its in Dutch language here a litle explanation. The app is an interior designer where u can alter the size off the room (Top Right). then you can select a product (Left row, in this case only the first pulldown works) and add it to the scene (left bottom button). After adding you can select and drag the obects around. The viewport navigation buttons The zoom button is the first button right under the viewport... The camera rotation button is the second The object mover is the third

Share this post


Link to post
Share on other sites
Advertisement
Looks cool :)

May I ask why you don't have access to the camera orientation? The problem would be easier to solve if this information were available.

Perhaps you could also provide a little more info about the tools being used (APIs, math libraries, etc.) for the benefit of those of us who don't have a lot of experience with web development.

Share this post


Link to post
Share on other sites
Ok, here's one way you might proceed (this is off the top of my head, so I may be missing some detail or other).

It looks like the camera is a simple orbital camera, and that the center of the scene remains constant (that is, there's no panning).

Let's say for the sake of argument that the center of the scene is (0,0,0), in which case the vector from the camera position to the center of the scene is simply the negative of the camera position. Let's also say that +z is up. You would then take the following steps:

1. Project the vector from the camera position to the center of the scene onto the ground plane by setting the z component to zero. Call this vector U.

2. Normalize U.

3. Compute an orthogonal vector V as (-U.y,U.x).

4. Map the mouse motion from the screen coordinate system to the coordinate system defined by U and V.

The only case in which this won't work is when the camera is looking directly down at the scene. You'll have to detect this case and handle it separately; I would suggest simply using the last valid UV basis until the camera moves again.

I think that should do it. Let me know if you need any help with the details.

Share this post


Link to post
Share on other sites
I was busy creating a answer to youre first post when i've been called... So, look at this as the answer at youre first post.

But Thanx I think. I have first to translate you're solution in Dutch to see if i understand you...

Hi Jyk,

Well, the program i use is Wirefusion. That's a Nodebased Java development tool based on JAVA 1.1 . Therefor they made a 3dApi as extension... To show u the posibilitys of this 3dApi you have to go to http://www.demicron.com/wirefusion/api/

As you can see at the viewpoint class there is a orientation field. But that is the representation of the initial Camera orientation from the VRML file.

I have already asked it at the wirefusion forum but it made no sense to me. Maybe you can read this forum post at the 7th post from Andrei..

Share this post


Link to post
Share on other sites
Quote:
Original post by MMWizard
I was busy creating a answer to youre first post when i've been called... So, look at this as the answer at youre first post.

But Thanx I think. I have first to translate you're solution in Dutch to see if i understand you...

Hi Jyk,

Well, the program i use is Wirefusion. That's a Nodebased Java development tool based on JAVA 1.1 . Therefor they made a 3dApi as extension... To show u the posibilitys of this 3dApi you have to go to http://www.demicron.com/wirefusion/api/

As you can see at the viewpoint class there is a orientation field. But that is the representation of the initial Camera orientation from the VRML file.

I have already asked it at the wirefusion forum but it made no sense to me. Maybe you can read this forum post at the 7th post from Andrei..
I didn't look at the thread in the other forum, but let me know if you have any specific questions regarding the solution I suggested earlier. I'll be happy to try and clarify things if I can.

Share this post


Link to post
Share on other sites
I'm sorry. i don't understand this. I have to recon that i only know elematary math. So i try to build this in numbers. Lets see..
I have a Camera C at -500,-600,750 pointing towards the origin O at 0,0,0

C(x,y,z) = (-500,-600,750);
O(x,y,z) = (0,0,0);

1. U = (-500,-600,0);// i think???

2. U(dc) = Δy/Δx = -600/-500 = 1,2;// if normalizing is the same as the direction coefficient (dc) form a line

3. V = (-U*y,U*x) = ((-1,2*-600),(1,2*-500))= (720,-600);

Whahaahahahah this is ... this can't be right... Can you explane it a bit further please

Share this post


Link to post
Share on other sites
Quote:
Original post by MMWizard
I have a Camera C at -500,-600,750 pointing towards the origin O at 0,0,0

C(x,y,z) = (-500,-600,750);
O(x,y,z) = (0,0,0);

1. U = (-500,-600,0);// i think???

2. U(dc) = Δy/Δx = -600/-500 = 1,2;// if normalizing is the same as the direction coefficient (dc) form a line

3. V = (-U*y,U*x) = ((-1,2*-600),(1,2*-500))= (720,-600);

Whahaahahahah this is ... this can't be right... Can you explane it a bit further please
Here's some pseudocode:
// Compute V from camera position (it was U in my initial example, but I'm
// switching it around for reasons that'll become clear in a bit):
vector3 V = -camera_position;
V.z = 0;

// This next step is what we mean by 'normalization':
float length = sqrt(V.x*V.x+V.y*V.y+V.z*V.z); // Could skip 'z' here...
V.x /= length;
V.y /= length;
V.z /= length; // Also unnecessary...

// Note that I'm skipping the step where we check for the degenerate
// case (looking straight down). You can worry about that once you
// get the rest working.

// Now we compute U:
vector3 U(V.y,-V.x,V.z);

// Now we get the mouse delta from some application-specific function:
float dx, dy;
get_mouse_delta(dx,dy);

// I'm assuming here that the mouse coordinates are in screen space,
// where +x is to the right and +y is up. We now map the delta vector
// to the space defined by U and V, and scale it by some constant
// (how fast you want the object to move), and dt (the
// timestep since the last update):
object_position += dx * U * move_speed * dt;
object_position += dy * V * move_speed * dt;
This does require a little knowledge of linear algebra, as well as a rudimentary vector class. I don't know what tools you have available, but it seems you should be able to whip something like this up.

Let me know if you need further help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!