loop omit a value

M

Michael

Hi Ron
sounds pretty complicated...any code I could try? I've cam x,y,z and
heading same for the car.

Now i calculate camera and car heading the same as above but as they
differ it gets messed in movements. Any hints for fixing?

Unfortunately there seems to be no good openal forum?
 
R

Ron Francis

Michael said:
Hi Ron
sounds pretty complicated...any code I could try? I've cam x,y,z and heading same for the car.

Now i calculate camera and car heading the same as above but as they differ it gets messed in
movements. Any hints for fixing?

Unfortunately there seems to be no good openal forum?

3D graphic is complicated
Here's a function that I use

double dot (double testpoint[3],double plane[3],double planenormal[3]){
// point, point on plane, normal to plane
double sum = 0;
for(int i=0;i<3;++i){
sum = sum + planenormal * (testpoint - plane);
}
return sum;
}

The above will give you the dot product. (The sign of the number determines what side the car is on,
and the number is the distance)
testpoint=position of the car
plane=camera position
planenormal=the cross product of your camera's direction and up vector.
I see these vectors as z and y, and the cross product would be x, perpendicular to z and y. So x is
the normal to the plane.

double *cross(double a[3],double b[3]){
// cross product of 2 unit vectors
double tmp[3];
tmp[0]=(a[1]*b[2])-(a[2]*b[1]);
tmp[1]=(a[2]*b[0])-(a[0]*b[2]);
tmp[2]=(a[0]*b[1])-(a[1]*b[0]);
return tmp;
}

Note that the parameters have to be unit vectors.
The result may have to be normalized as well (made into a unit vector).

And to get the distance between two points:

double hyp(double a[3],double b[3]){
//returns the distance between two points
double x,y,z;
x=powl((b[0] - a[0]),2);
y=powl((b[1] - a[1]),2);
z=powl((b[2] - a[2]),2);
double add=x+y+z;
double answer=powl(add,.5);
return answer;
}

The above code is a bit overblown because at the time I was error checking each stage.
double answer=powl(x+y+z,.5) should be enough.

I imagine that this may only serve to confuse you if you're not versed in 3d graphics, but I hope it
helps.
I would suggest finding a good book and working your way through it.

Regards
Ron Francis
www.RonaldFrancis.com
 
M

Michael

Many thanks. I should be able to use quite a bit. Now I don't seem to
have a camera up? I've those values:
view_x float 660+ no OGLcoords The location of the camera, X coordinate
(OpenGL)
view_y float 660+ no OGLcoords The location of the camera, Y coordinate
(OpenGL)
view_z float 660+ no OGLcoords The location of the camera, Z coordinate
(OpenGL)
view_elevation_m_msl float 660-840 no metersMSL The elevation of the camera
view_elevation_agl float 800-840 no ??? The elevation of the camera
view_pitch float 660+ no degrees The camera's pitch
view_roll float 660+ no degrees The camera's roll
view_heading float 660+ no degrees the camera's heading, CW frmo true north

Could I calculate the side with those?
Thanks
Michael
 
R

Ron Francis

Michael said:
Many thanks. I should be able to use quite a bit. Now I don't seem to have a camera up? I've those
values:
view_x float 660+ no OGLcoords The location of the camera, X coordinate (OpenGL)
view_y float 660+ no OGLcoords The location of the camera, Y coordinate (OpenGL)
view_z float 660+ no OGLcoords The location of the camera, Z coordinate (OpenGL)
view_elevation_m_msl float 660-840 no metersMSL The elevation of the camera
view_elevation_agl float 800-840 no ??? The elevation of the camera
view_pitch float 660+ no degrees The camera's pitch
view_roll float 660+ no degrees The camera's roll
view_heading float 660+ no degrees the camera's heading, CW frmo true north

Could I calculate the side with those?
Thanks
Michael

Well that complicates matters.
First you have would have to learn how to rotate a point around an arbitrary vector, and that isn't
an easy task I'm afraid.
This may help

void rotate(double point[3],double axis[3],double ang){
//point,axis,angle
double tx[3][3],ty[3][3],tz[3][3],ty1[3][3],tx1[3][3],temp[3];
clArr(tx);clArr(ty);clArr(tz);clArr(ty1);clArr(tx1);
double sum=0;
double v=powl((powl(axis[1],2)+powl(axis[2],2)),.5);
double l=powl(powl(axis[0],2)+powl(axis[1],2)+powl(axis[2],2),.5);
int i=0,j=0;
if(!ang)
return;
if(v){
//matrix for rotation around x axis
tx[0][0]=1;tx[1][1]=axis[2]/v;tx[2][1]=-axis[1]/v;tx[1][2]=axis[1]/v;tx[2][2]=axis[2]/v;
//and inverse
tx1[0][0]=1;tx1[1][1]=axis[2]/v;tx1[2][1]=axis[1]/v;tx1[1][2]=-axis[1]/v;tx1[2][2]=axis[2]/v;
}
//matrix for rotation around y axis
ty[1][1]=1; ty[0][0]=v/l; ty[2][0]=-axis[0]/l; ty[0][2]=axis[0]/l; ty[2][2]=v/l;
//and inverse
ty1[1][1]=1; ty1[0][0]=v/l; ty1[2][0]=axis[0]/l; ty1[0][2]=-axis[0]/l; ty1[2][2]=v/l;

//matrix for rotation around z axis
tz[2][2]=1; tz[0][0]=cosl(ang); tz[1][0]=-sinl(ang); tz[0][1]=sinl(ang); tz[1][1]=cosl(ang);

//multiply the point by the x matrix
if(v){
for(i=0;i<3;++i){
for(j=0;j<3;++j)
sum+=point[j]*tx[j];
temp=sum;
sum=0;
}
set(point,temp);
}
//multiply the point by the y matrix
sum = 0;
for(i=0;i<3;++i){
for(j=0;j<3;++j)
sum+=point[j]*ty[j];
temp = sum;
sum = 0;
}
set(point,temp);
//multiply the point by the z matrix
sum = 0;
for(i=0;i<3;++i){
for(j=0;j<3;++j)
sum+=point[j]*tz[j];
temp = sum;
sum = 0;
}
set(point,temp);
//multiply the point by the inverse y matrix
sum = 0;
for(i=0;i<3;++i){
for(j=0;j<3;++j)
sum+=point[j]*ty1[j];
temp = sum;
sum = 0;
}
set(point,temp);
//multiply the point by the inverse x matrix
if(v){
sum = 0;
for(i=0;i<3;++i){
for(j=0;j<3;++j)
sum+=point[j]*tx1[j];
temp = sum;
sum = 0;
}
set(point,temp);
}
}

I'm afraid that some lines of that code are going to be wrapped on to the next line/s, so you'll
have to splice it together.
From memory of DirectX...
pitch = rotation around the x axis
roll = rotation around the z axis
heading = rotation around the y axis.

I thought that OpenGL would give you more than that though.
I have no idea what view_elevation is as I thought that view_y would be the camera's elevation.
You should be asking these questions in an OpenGL forum.
This seems to be opening up a Pandora's box for you.

Regards
Ron Francis
www.RonaldFrancis.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,264
Latest member
FletcherDa

Latest Threads

Top