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

## Recommended Posts

Hey, I am totally new to all of this, and at work i was assigned to do something, which confuses me quite a bunch, although this should be easy for anyone who knows.. by the way, I use java and JOGL. I have a vector that I need to display, it has its origin point, and direction, for example: position (100,100,100) direction(1,2,1) so, i will need to draw a line from 100,100,100 to 101,102,101. the trick is, that I need to have a few viewports of that line. the first one, a front view vector, where I need to look right into the vector given, it being located on the center of my viewport. this I managed to do. the second one, would be a side window, where I need to see the beginning of this vector on the center of my viewport (100,100,100) and y axis is up. I need to be in exactly 90 degrees of the vector's direction (i guess on the xz plane).. This I didnt manage to do.. what I tried to do, was to make a plane from the vector (1,2,1) and my up vector (0,1,0), and find the normal of that plane, but that doesnt work that well.. whats the correct way to look at my vector from the side having the y axis pointing up? by the way, I made a little camera class, that later i use glu.gluLookAt to set my looking direction. please help me out.. Vadali [Edited by - vadali on June 19, 2008 6:50:48 AM]

##### Share on other sites
I think it helps if you imagine this to be a 2D problem.

Imagine a 3D point declared with its position in space as (x,y,z)

from the front view point, you only need to display the x & y values of this point.

 |y| |_____    x

from the side view only the z & y values.

 |y| |_____    z

from the top view only the x & z values.

 |z| |_____    x

if you imagine your vector as (1,0,0) (x,y,z), originating from your 3D point, from the side view this is going to be represented as a single dot. From the front view it will be a horizontal line.

And for the vector (0,1,0) from the top view it will be represented also as a dot, but from the front view, a vertical line.

does this help any? or I have completely misunderstood what you're trying to accomplish?

##### Share on other sites

what you say is very true, though I dont really know how to apply it to vectors that are not on the world's xyz axis set.
In the example you gave (1,0,0) (x,y,z), a front view and side view are quite trivial, (horizontal line, and a dot), but what happens when this line has some angles to it?

lets take a simple example (1,4,2)(x,y,z)
in a front view, I set the camera to the inverted vector (-1,-4,-2)(x,y,z) and then I go backward a bit to show it.

in a side view, what should I do to get the camera vector?

Thanks,

##### Share on other sites
Alright!

managed to solve the trouble!

My direction was correct, here is what I have done:
say we have a vector that we want to follow Vec, the vector consist of x,y,z as the base of the vector, and vx,vy,vz as the end of the vector.

another vector up will help us make the proper plane that we want to view.

float dx = Vec.vx - Vec.x;float dy = Vec.vy - Vec.y;float dz = Vec.vz - Vec.z;// This means that we want Y to be up - a side viewfloat upx = 0;float upy = 1; float upz = 0;// calculate cross product to find the normalfloat nx = dy*upz-dz*upy;float ny = dz*upx-dz*upz;float nz = dx*upy-dz*upx;// Set the camera positioncamera.x = Vec.x - nx;camera.y = Vec.y - ny;camera.z = Vec.z - nz;// Set the camera targetcamera.vx = Vec.x;camera.vy = Vec.y;camera.vz = Vec.z;

The concept is rather simple, using the up vector, we make a plane, then we find its normal, and set the camera to this normal.
We can change up vector to show us also top view, bottom view etc..

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631433
• Total Posts
3000046
×

## Important Information

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

Sign me up!