1. ## GLU deprecated

I heard that GLU shouldn't be used any more since it contains a lot of deprecated code now. What do you guys think?
Does anyone have other alternative to such things as gluLookAt?

2. Just do some matrix math. Matrices are fun

Needs the math unit for the CoTan function
Code:
```procedure gluPerspective(fovy, aspect, znear, zfar: single);
var res: TMatrix;
f: single;
begin
{ Oblique projection matrix - Got formulas from OpenGL docs :) }
f := CoTan(fovy/2);

FillChar(res[0], sizeof(TMatrix), 0);

res[0] := f/aspect;
res[5] := f;
res[10] := (zfar+znear)/(znear-zfar);
res[11] := (2*zfar*znear)/(znear-zfar);
res[14] := -1;

glMultMatrixf(@res[0]);
end;

procedure Cross3x3(out ox,oy,oz: single; a,b,c,x,y,z: single);
begin
{
calculate determinant - i,j,k are the new basis

i j k
a b c
x y z

i*b*z+j*c*x+k*a*y-k*x*b-i*y*c-j*z*a
}
ox := b*z-y*c;
oy := c*x-z*a;
oz := a*y-x*b;
end;

function Norm2(x,y,z: single): single;
begin
result := sqrt(x*x+y*y+z*z);
end;

procedure gluLookAt(eyeX, eyeY, eyez, centerX, centerY, centerZ, upX, upY, upZ: single);
var dx,dy,dz, sx,sy,sz, ux,uy,uz, mag: single;
res: TMatrix;
begin
{ Create projector from orthonormal basis }
FillChar(res[0], sizeof(TMatrix), 0);

{ Get direction - the new "z" basis }
dx := centerX-eyeX; dy := centerY-eyeY; dz := centerZ-eyeZ;
{ Normalize direction }
mag := Norm2(dx,dy,dz);
dx := dx/mag; dy := dy/mag; dz := dz/mag;

{ Normalize up vector }
mag := Norm2(upX,upY,upZ);
upX := upX/mag; upY := upY/mag; upZ := upZ/mag;

{ Find vector orthogonal to "z" and up - the new "x" basis
Since direction and up are normalized, the output will be normalized too }
Cross3x3(sx,sy,sz, dx,dy,dz, upX,upY,upZ);

{ Find vector orthogonal to "x" and "z" - the new "y" basis }
Cross3x3(upX,upY,upZ, sx,sy,sz, dx,dy,dz);

res[0] := dx;  res[1] := dy;  res[2] := dz;
res[4] := upX; res[5] := upY; res[6] := upZ;
res[8] := -dx; res[9] := -dy; res[10] := -dz;
res[15] := 1;

glMultMatrixf(@res[0]);
glTranslatef(eyeX,eyeY,eyeZ);
end;```

3. Writing your own gluLookAt is a standard exam question in my CG course. I don't really like gluPerspective, it makes frustum culling confusing.

But I really don't like that everything is deprecated. Replacing standard code with nonstandard, what's the point? Moving everything to shaders, I guess.

4. Hi JSoftware,
Code:
```{ Find vector orthogonal to "z" and up - the new "x" basis
Since direction and up are normalized, the output will be normalized too }
Cross3x3(sx,sy,sz, dx,dy,dz, upX,upY,upZ);```
Well, I believe a cross-product returns a vector whos length is the area (or 1/2 area?) inside of the two input vectors...so this means that the resulting vector is NOT guaranteed to be normalized even though the inputs are

Feel free to correct me if you wish, I don't mind being proven wrong

cheers,
Paul

5. Originally Posted by paul_nicholls
Hi JSoftware,
Code:
```{ Find vector orthogonal to "z" and up - the new "x" basis
Since direction and up are normalized, the output will be normalized too }
Cross3x3(sx,sy,sz, dx,dy,dz, upX,upY,upZ);```
Well, I believe a cross-product returns a vector whos length is the area (or 1/2 area?) inside of the two input vectors...so this means that the resulting vector is NOT guaranteed to be normalized even though the inputs are

Feel free to correct me if you wish, I don't mind being proven wrong

cheers,
Paul
Yes, if the two input vectors are orthonormal, orthogonal and normalized, only then you know that the cross product be a unit vector. And the three vector will then be an orthonormal base.

I always have a solid set of linear algebra functions around to do things like these. Replacing gluLookAt is particularly straight-forward, but you need these vector and matrix functions for pretty much everything. My algebra unit includes vector addition/subtraction, norm, normalization, dot and cross products, matrix-matrix and matrix-vector multiplication, vector splitting into orthogonal components, matrix inverse, making rotation matrices around arbitrary axis... OpenGL incudes much of that but I often need to do those things on the CPU too.

6. ok, cool

cheers,
Paul

7. And like you say, the length is indeed the area of a rhombus/diamond where the two vectors are two of the sides. But I rarely use that property, the direction of the cross product is what I use the most.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•