**comp.graphics.algorithms**

## Subject: **Re: 3D camera question**

Thank you so much. that is extremely helpful.

One additional question -- I have a matrix class that has an invert method,

but it is a 4x3 matrix, not a 4x4. Do the same rules below apply if I

attempt what you outlined below using the 4x3 matrix?

Again, so much thanks for your help.

> Directly. Assuming column vectors the matrix is:

>

> [ Xx Yx Zx Px ]

> C = [ Xy Yy Zy Py ]

> [ Xz Yz Zz Pz ]

> [ 0 0 0 1 ]

>

> where the camera axes are:

> X = (Xx, Xy, Xz)

> Y = (Yx, Yy, Yz)

> Z = (Zx, Zy, Zz)

> and the camera location is:

> P = (Px, Py, Pz)

>

> If Q is of the form [Qx, Qy, Qz, 1]^T, then it represents a point and C

> transforms Q to Q' of the form [Q'x, Q'y, Q'z, 1]^T (another point).

> If V is of the form [Vx, Vy, Vz, 0]^T, then it represents a vector and C

> transforms V to V' of the form [V'x, V'y, V'z, 0]^T (another vector).

>

> > Once I have that matrix, I then invert it. Once inverted I multiply any

> > existing world matrixes of each object by the camera matrix and that

should

> > be it?

>

> Yes, but not permanently, just for the matter of vertex transforming.

>

> > Any code/psuedocode would be really helpful.

>

> Okay, the following is not tested. Assume matrices are initialized into

> identity matrices.

>

> Vector4 cubeLocal[8] = {

> Vector4(-1, -1, -1, 1), Vector4(-1, 1, -1, 1),

> Vector4(1, 1, -1, 1), Vector4(1, -1, -1, 1),

> Vector4(-1, -1, 1, 1), Vector4(-1, 1, 1, 1),

> Vector4(1, 1, 1, 1), Vector4(1, -1, 1, 1)};

>

> Matrix4 cubeWorld;

> scale(cubeWorld, 2, 3, 4);

> rotate(cubeWorld, 0.2, 0.3, 0.5);

> translate(cubeWorld, 10, 15, 100);

>

> Matrix4 view;

> // Pick your view

>

> Matrix4 viewInversion(invert(view));

> Vector4 cubeView[8];

>

> while(!ready)

> {

> // Transform from local coordinates to view coordinates

> Matrix4 localToView(viewInversion * cubeWorld);

> for (int i = 0;i < 8;++i)

> {

> cubeView[i] = localToView * cubeLocal[i];

> }

> // Transform from view coordinates to screen coordinates

> // Render

> // Animate camera and the object

> rotate(cubeWorld, 0.1, 0,2, -0.1);

> rotate(view, -0.1, 0.04, 0.07);

> }

>

> --

> Kalle Rutanen

> http://kaba.hilvi.org

Reply

View All Messages in

**comp.graphics.algorithms**

path:

3D camera question =>Re: 3D camera question =>Re: 3D camera question =>Re: 3D camera question =>

Replies:

Copyright © 2006 WatermarkFactory.com. All Rights Reserved.