the matrices are just facts so yes, "by heart", if you think its worth the effort as you will barely ever use them - at least for the course. OGL just uses them internally to do the transforms for you. Seem to remember figuring out some scheme to memorise them for them for the exam, but for most purposes you can just look them up for now. If you ever get into writing your own 3d engine they are good to know though.

AND FAR BETTER NOT TO CROSS THREADS ON FORUMS -

start a new thread and people who aren't intersted in pyramids might answer you, and info posted in them is easier to find later on.]]>

Just draw a diagram on paper and play around. Thats how I fugured all these out.

Since the due date for the assigment has passed, here are some code

to help you guys out:

(I just hope this is not agaist any rules. If it is, I am sorry.)

bool TestPtInCube( point3 pt, GLfloat ln )

{

if ((pt[0] > 1) | (pt[0] < -1) | (pt[1] > 1) | (pt[1] < -1)

| (pt[2] > 1) | (pt[2] < -1)

| ln > partLngth[partnumber]) // also check Length

return false;

else

return true;

}

bool TestPtInCylinder( point3 pt, GLfloat ln )

{

float Ax;

float Ay;

Ax = pt[0];

Ay = pt[1];

if ((sqrt((Ax * Ax) + (Ay * Ay)) > 1.0) // sqrt of the sum of sqrs of sides

| (pt[2] > 1.0) | (pt[2] < -1.0) // the end sides

| ln > partLngth[partnumber]) // also check Length

return false;

else

return true;

}

bool TestPtInPyramid( point3 pt, GLfloat ln )

{

float Ax;

float Ay;

float Az;

float yLen;

Ax = pt[0];

Ay = pt[1];

Az = pt[2];

// The base length is always the length of pt(y)

// Only in the case where height = len of side = same len sides = (for square bases)

// When we move halfway from top pt, the base at pt will also be halved.

yLen = 2 - (Ay + 1); // Calc Len of y pt away from pt(0,1,0)

yLen = yLen /2; // since zero is mid-pt - half on either side of center.

// ie. when Len y = 1, the base is x = -0.5 to 0.5 = Len 1 = Len y. Same for z.

if ((Ax < -yLen) | (Ax > yLen) |

(Az < -yLen) | (Az > yLen) |

(Ay < -1) | (Ay > 1))

return false;

else

return true;

}

bool TestPtInContainer( point3 pt, GLfloat ln )

{

if (ContainerID == 1) return TestPtInCube(pt, ln);

if (ContainerID == 2) return TestPtInCylinder(pt, ln);

if (ContainerID == 3) return TestPtInPyramid(pt, ln);

}

]]>

to get the ratio we divide maximum height by half a side length (half because we want a right angled triangle around y-axis) ie 2/1=2

(because the pyramid stays the same you might as well assign the ratio as a constant)

now shift our y-value so that we measure "height" in the pyramid from the top (point at the apex=0 and at base = 2) ie 1-yval.

now to get the maximum horizontal simply divide our "height" by the ratio ie ratio/height=max.

if the horizontal values are more than max (or less than -max) just move them back inside with a while loop decremeting by a small amount.

so say we have a point (x,0,z)

height is 1-0=1

max value is 1/2=0.5

while(x>max)x-=0.001;

while(x<-max)x+=0.001;

etc.

whole thing is 5 lines of simple code... and don't forget to massage the y value into the -1...1 range first.

]]>

You may have got it by now but I used gltranslatef()

]]>

gluCylinder(t, 1.0f, 1.0, 2, 50,1);

how do you draw so the centre of the cylinder is coord(0,0)

Gave up on the vertical viewing angle couldnt stop it from being shaky.]]>

worked out the m of the pyramid boundaries.

if the particle moved away this m value it would be out of the pyramid.

]]>

went back and checked up on my code and actually did it a bit differently - the hint above will still get you thinking in the right way though... the thing about 45 degrees might be wrong, but the principle of thinking in terms of similar triangles of different sizes is on the right track.]]>

its actually really simple - it clicked for me last year after a doodle or two - here's a hint:

thinking in 2d is the right place to start.

a pyramid has 45degree sides.

one 45 degree triangle has sides eg 1,1,hypoteneuse

another has 0.5,0.5,another hypoteneuse

any more and I may as well just give the answer. Geometry aside, the maths for the actual collision detection is nothing beyond what you learnt in primary school - forget dot products and trig.

]]>

This might help. I haven't figured out exactly how, though.]]>

What I intend to do is:

1. Bound the bottom of the pyramid (this is easy because it's a plane parallel to the xz plane).

2. Bound the top of the pyramid (again, easy, the height is all at point {0,1,0})

3. Bound on a plane parallel to the hypotenuse of each face. My thinking here is based on 2D thinking. If you were inside a right-angled triangle, you'd have to test every point to see if was on the inside of the hypotenuse. The mathematics don't appear to be that hard. Now you just have to "pretend" you're in 2D, calculate the hypotenuse, and then check whether you've crossed it or not. I hope it works.]]>

]]>