Normals (THEY HURT)
Blitz3D Forums/Blitz3D Programming/Normals (THEY HURT)
| ||
Why does the collision normals command report an impossible figure in this code? With the cube that the sphere collides with at its default rotation the collisions normals correctly reports x1, y0, z0. When the cube is rotated to a 45 degree angle, to my reckoning it should report x0.5, y-0.5, z0. Instead I get a physically impossible figure of x0.7, y-0.7, z0. Any ideas? Here’s the code Graphics3D 800,600 SetBuffer BackBuffer() Const WALLS=1 Const BALLS=2 camera=CreateCamera() CameraRange camera,0.1,1000 CameraZoom camera,1.4 light=CreateLight(1) PositionEntity light,0,0,-500 AmbientLight 100,100,100 ball1=CreateSphere(8) PositionEntity ball1,0,0,15 EntityType ball1,BALLS wall=CreateCube() PositionEntity wall,-3,0.5,15 RotateEntity wall,0,0,45;EDIT ME OUT EntityType wall,WALLS Collisions BALLS,WALLS,2,2 While Not KeyDown( 1 ) UpdateWorld RenderWorld MoveEntity ball1,-0.01,0,0 If CountCollisions ( Ball1 ) >0 Then Text 0,0,"x "+CollisionNX#( wall,1 ) Text 0,10,"y "+CollisionNY#( wall,1 ) Text 0,20,"z "+CollisionNZ#( wall,1 ) EndIf Flip Wend |
| ||
I get a 'Collision index out of Range' error as soon as the sphere hits the cube |
| ||
The vectors ( 0.5, -0.5, 0.0 ) and ( 0.7, -0.7, 0.0 ) point in the same direction. Normals are always scaled to have length 1.0. So the second vector is correct as Sqr(0.5) = 0.707... |
| ||
I was about to ask what is wrong with .7,-.7,0 The magnitude of the vector is irrelevant, all that matters is the direction. |
| ||
Tink of a a normal as a point that lies on a sphere with a radius of 1.0. 0.7 0.7 0 may be misleading and appear to be greater than 1, but it's NOT. You do not dtermine distance by adding the components, you have to do this equation: d = sqr(x^2 + y^2 + z^2) And as you will see if you plug in the values, if you plug in 0.7, for X and Y, you get 1. Try plotting the points on a graph. If you plotted 1,1 0,1 -1,0 0,-1 and the four variations of 0.5,0.5, then you'd get something that looks ike a diamond, not a circle. |
| ||
Yeah sorry I wasn't thinking. |
| ||
You need to do a Text 0,0,"x "+CollisionNX#( ball1,1 ) not a Text 0,0,"x "+CollisionNX#( wall,1 ) The collisions only register for the ball1. to the wall, it never had a collision. |