Understanding Coords

Blitz3D Forums/Blitz3D Beginners Area/Understanding Coords

YellBellzDotCom(Posted 2006) [#1]
Hello,

I was trying some things then I placed colored spheres at each edge of my 3d terrain so that I understood the coordinates. The Thing is, the results are not what I was expecting. Can someone help me understand this?

I was figuring the following would be a correct coord layout
from a camera looking down, each coord is a corner, except 0,0

(X)-100, (Z)-100----------------------------(X)100, (Z)-100
-----------------------------------------------------------
-----------------------------------------------------------
--------------------------(X)0, (Z)0-----------------------
-----------------------------------------------------------
-----------------------------------------------------------
(X)-100, (Z)100-----------------------------(X)100, (Z)100


Instead, the actual view looks like this...
(X)-100, (Z)-100----------------------------(X)-100, (Z)100
---------------------------------------------------?-------
--------------------------(X)0, (Z)0-----------------------
-----------------------------------------------------------
-----------------------------------------------------------
(X)100, (Z)-100------------------------------(X)100, (Z)100
?

The 2 question marked ones are flipped


I always figured Z was like Y in a 2d system, but instead, X is like Y.

This is really hurting my brain


Dreamora(Posted 2006) [#2]
Looks like you are looking from bottom at it.

In local coordinate space, x is toward right, y upward and z is into the screen.


YellBellzDotCom(Posted 2006) [#3]
I thought about that too, but my objects are in the positive Y, which would make it correct. Im placing the ground at 0,0,0 and the camera at 0,60,0. So Im looking down at the ground. X should go from left to right, left = negative, Right = positive. Z should go from top to bottom (Looking down at ground), top = negative, bottom = positive.

This seems accurate, but for some reason, my first post is whats happening. If the camera is 60 units above the ground, I should be looking at the ground and the coords should be showing accurately.


Stevie G(Posted 2006) [#4]
Looks like your mesh or camera has rotated 90 degrees on the yaw axis for some reason.

This works fine for me ...

Graphics3D 640,480,16,1

camera = CreateCamera() : PositionEntity camera, 0,300,0 : RotateEntity camera, 90,0,0
cube = CreateCube() : ScaleEntity cube, 100,1,100 
c1 = CreateSphere() : ScaleEntity c1, 5, 5, 5 : PositionEntity c1, -100,0,100 : EntityColor c1, 255,0,0
c2 = CreateSphere() : ScaleEntity c2, 5, 5, 5 : PositionEntity c2, 100,0,100 : EntityColor c2, 0,255,0
c3 = CreateSphere() : ScaleEntity c3, 5, 5, 5 : PositionEntity c3, 100,0,-100 : EntityColor c3, 0,0,255
c4 = CreateSphere() : ScaleEntity c4, 5, 5, 5 : PositionEntity c4, -100,0,-100 : EntityColor c4, 255,255,0

While Not KeyDown(1)

	RenderWorld()
	Flip
	
Wend


Stevie


Danny(Posted 2006) [#5]
It's called 'Gimble-lock', a serious inconveniance of using the Euler coordinate system. Google it it to find out more... http://www.google.co.uk/search?hl=en&q=3d+gimble+lock+explained&meta=
I believe there used to be an example in the code archives, but can't find it anymore..

I don't know how to explain it simply, and it can happen when you rotate around X axis more than 90 or -90 degrees so it ends up in alignment with the global Y axis, the entity then flips and starts going the other way.

Especially when you're using commands like PointEntity or AlignToVector to rotate an entity - then I believe your 'roll' angle will go crazy - That's why you don't see what you would expect looking from 'above'.

If you manually rotate it step by step then you can (almost) prevent it in some situations (that's why Stevie G's above example does work).

d.


Stevie G(Posted 2006) [#6]
I had my suspicions that it may have been the dreaded gimbal-lock - especially if pointentity was being used.

Aligntovector, however , uses quarternions internally so that would not be an issue.

S.


YellBellzDotCom(Posted 2006) [#7]
Ok, maybe this will help me understand what happened here...

Heres what I thought the coord system should be in Blitz3d


But after thinking about it, in a 2d system Y goes negative above the 0,0 coord, so maybe this is correct?


And this is what my problem is currently, in my pathfinding test program, the coords are off one way or another. It does look like I am simply upside down...


Thanks for the replies


YellBellzDotCom(Posted 2006) [#8]
Thanks for the code there Stevie G, but that still isnt making any sense for me, it still seems like the coords are off...

Heres a screenshot of what your code produced...


If this is the correct output, Ill have to get a chainsaw and open up my skull, pull my brains out, flip them on the z axis and reinsert em to understand this! :>


YellBellzDotCom(Posted 2006) [#9]
Ok, I changed the camera position to 0,-300,0 and the camera rotation to -90,0,0 this is the output...



Now this seems coorect to me, it has the same coord system as the 2nd image of my post above



So like the original post, I believe I was looking at my map from the bottom down? as long as a negative Y value goes upwards in 3d space and a positive Y value goes downwards in 3d space, lol!!


YellBellzDotCom(Posted 2006) [#10]
ok, so I use the code I stated above which puts the coords to where Im used to, then I create a cone and its default position is that the cones tip is pointing to the positive Y, which tells me that the positive Y should be going upwards. Dang it.


YellBellzDotCom(Posted 2006) [#11]
All Im trying to figure out here is the default Blitz3d Coord system, evidently I was wrong... without using anything that could cause "Gimbal Lock", someone please help me. Its hurting me.


YellBellzDotCom(Posted 2006) [#12]
I used this code to see what the default Coords are in Blitz and as I suspected, what I thought was the correct system was wrong, I think I was thinking too much 2d system where the Positive Y goes downward and trying to translate a 2d system into 3d, got me all messed up.

heres the code...
Graphics3D 1024,768,32,1
SetBuffer BackBuffer()

Cone = CreateCone()
PositionEntity Cone,0,0,0
EntityColor Cone, 255,0,0


Sphere = CreateSphere()
PositionEntity Sphere,0,0,0
EntityColor Sphere, 255,255,0

Cam = CreateCamera()
PositionEntity Cam, 0,70,-70

PointEntity Cam,Cone

While Not KeyHit(1)

	If KeyDown(200) ;up arrow
		MoveEntity Sphere,0,1,0
	EndIf

	If KeyDown(208) ;down arrow
		MoveEntity Sphere,0,-1,0
	EndIf
	
	If KeyDown(203) ;left arrow
		MoveEntity Sphere,-1,0,0	
	EndIf
	
	If KeyDown(205) ;right arrow
		MoveEntity Sphere,1,0,0
	EndIf
	
	If KeyDown(12) ;minus
		MoveEntity Sphere,0,0,-1
	EndIf
	
	If KeyDown(13) ;equals
		MoveEntity Sphere,0,0,1
	EndIf

	RenderWorld

	Text 10,10,"Camera Coords: "+EntityX(Cam,True)+", "+EntityY(Cam,True)+", "+EntityZ(Cam,True)
	Text 10,50,"Spheres X, Y, Z: "+EntityX(Sphere,True)+", "+EntityY(Sphere,True)+", "+EntityZ(Sphere,True)
	

	Flip
	
Wend


and the correct coordinate system would be...



Thanks everyone for your help there and sorry for being so confused, lol


Floyd(Posted 2006) [#13]
The system with the camera in its default position and orientation is:

X+ is to the right
Y+ is up
Z+ is into the screen.

How things look depends, of course, on the how the camera is arranged relative to the stuff you are looking at.

Imagine you have an X-Z coordinate system drawn on the floor. You ( i.e. the camera ) are initially embedded in the floor, looking in the Z+ direction. If you rise above the floor and then tilt your head to look down you will see Z+ now points up. Similarly, if you sink below the floor and look up then Z+ is now downward.


Sir Gak(Posted 2006) [#14]
Whew! Get the coords wrong and all kinds of fun (?) stuff can step in and drive you utterly mad!