2 Blitz3D Bugs !: "RotateEntity" won't turn 360° !

Blitz3D Forums/Blitz3D Beginners Area/2 Blitz3D Bugs !: "RotateEntity" won't turn 360° !

etxtra(Posted 2011) [#1]
hi everyone ! I've found an annoying problem that looks like a bug ! "RotateEntity" used properly to turn a cube 360° won't turn it 360° at all ! run the following program to see that it will block at 90° ! :
Graphics3D 800, 600, 0, 2

SetBuffer BackBuffer()

cube = CreateCube ()
camera = CreateCamera()
PositionEntity camera, 0.0, 0.0, -5.0

Repeat

	; next line: Bug with "RotateEntity" : "comment" (";") the following line and "uncomment" the next to see what happens with "TurnEntity"...
	RotateEntity cube,	EntityPitch# ( cube ) + 0.8, 0.0, EntityRoll# ( cube ) ; comment (";") this line and uncomment the next to see the bug with "TurnEntity"...
	
	; next line: what happens with "TurnEntity" : "comment" (";") the following line and "uncomment" the previous to see the bug with "RotateEntity"...
	;TurnEntity cube, 0.8, 0.0, 0.0 ; comment (";") this line and uncomment the previous to see the bug with "RotateEntity"...

	UpdateWorld
	RenderWorld
	
	Locate 0,0
	Print "Escape to quit... BUG!: cube won't turn 360° ! "
	Print "code used: 'RotateEntity cube, EntityPitch# ( cube ) + 0.1, 0.0, EntityRoll# ( cube )'"
	Print "the cube sould turn 360° up ! Instead it turn only 90°"
	Print "Cube Angle X#: " + Str EntityPitch# ( cube ) + "°"

	Flip
	
Until KeyHit(1)

End

-
-there is another Bug and it is the worse ! When "TurnEntity" and "RotateEntity" are used together, it gives strange results ! run the following program to see that the cube won't turn 360° up ! instead it will turn 90° up, then 180° Down ! :
Graphics3D 800, 600, 0, 2

SetBuffer BackBuffer()

cube = CreateCube ()
camera = CreateCamera()
PositionEntity camera, 0.0, 0.0, -5.0

Repeat

	; Turn the cube up, and only up !
	TurnEntity cube, 0.8, 0.0, 0.0
	
	; Rotate the cube so that it has the same "Yaw" with camera:
 	RotateEntity cube,	EntityPitch# ( cube ), EntityYaw# ( camera ), EntityRoll# ( cube )

	UpdateWorld
	RenderWorld
	
	Locate 0,0
	Print "Escape to quit... BUG!: cube won't turn 360° ! "
	Print "code used: 'RotateEntity cube,	EntityPitch# ( cube ), 0.0, EntityRoll# ( cube )'"
	Print " + 'RotateEntity cube,	EntityPitch# ( cube ), 0.0, EntityRoll# ( cube )'"
	Print "the cube sould turn 360° up ! instead it turns 90° up, then 180° down !"
	Print "Cube Angle X#: " + Str EntityPitch# ( cube ) + "°"
	
	Flip
	
Until KeyHit(1)

End


I believe that this bug was there since more than 12 years, and I'm surprised that it hasn't blocked anyone in their Blitz3D projects ! I just want you to confirm this bug so I can post in the "Bugs report section". Please, I need your help ! Maybe you have an explanation... Or maybe you have a solution that will makes the cube turn right. I need to use both "TurnEntity" and then "RotateEntity" in my Blitz3D project, so how can I do ? I believe this need a fix !
I hope this will be fixed, maybe there is an other solution to do what I wanted to do...

PS: note that the problem seem to happen only with "X" angle ("pitch"). I haven't tested the other angles yet ....

-Cheers

Last edited 2011


GfK(Posted 2011) [#2]
Haven't used Blitz3D for years but I suspect the problem is that you're basing your RotateEntity code on the result of EntityPitch which, if memory serves, returns a value between -180 and 180, rather than the 0-360 you seem to be assuming.

I believe that this bug was there since more than 12 years
I'd be surprised if that's the case, given Blitz3D is a mere 10 years old. That aside, I think you're just doing it wrong.


etxtra(Posted 2011) [#3]
hi @Gfk ! Ok, I'm sorry for when I said "more than 12 years" because it was a mistake so I would now say "since 10 years" (according to what you said).

I believe Blitz3D needs an update or a fix because the rotation commands / values won't help anyone if they stay the same as now. Don't you think ? I mean an object has 360 degrees / angles in the 3 dimensions so why bother with values like 720° or 2500° ?

Ok, if you don't consider it is a bug, can you then suggest a solution or a method to :
-make an object turn in the "pitch" direction and roll in the "roll" direction while its "yaw" angle is the same that an other object (the camera). how ?
-prevent the camera from looking beyond a max angle and a min. angle, (in the "pitch" direction...). how ?

Please, help me.

Last edited 2011


Warner(Posted 2011) [#4]
No worries: maybe a quick workaround makes things better:
Ex1:

Ex2:

Consider this: turning something 90 degrees clockwise has the same effect as turning something 270 degrees counter clockwise.
Internally, blitz3d uses matrices. Angles are converted to matrices and back. That is why reading Pitch gives a different value than what you wrote into it. Workaround=use variables to keep track of pitch/yaw/roll.
If you want to know how these angles and stuff work, read up on Euler angles and gimbal lock.

Also, I used these functions a while ago. I got them from someone else. They were intended to avoid gimbal lock. You can find them on this page:
http://blitzbasic.com/Community/posts.php?topic=77972
Look for (ctrl+F) "GlobalEntityPitch".

Last edited 2011


Matty(Posted 2011) [#5]
There's no bug there....just a lack of understanding


Zethrax(Posted 2011) [#6]
Check my comment in the online docs for the EntityPitch command that I've linked below. It contains information which will explain how the EntityPitch, EntityYaw, and EntityRoll functions work.

http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPitch&ref=goto#comments

If you're confused about how a function works and the offline docs aren't helping you to understand it, then it's often a good idea to check the online docs. They often include comments which explain things further. It's a pity that BRL doesn't update the offline docs with this extra info.


etxtra(Posted 2011) [#7]
Hi @Warner ! it's OK now, thanks ! I'm now using variables to keep track of pitch etc... and it works ! Thank you !

I have another problem right now: I would like to limit the rotation of the camera between two angles, a min. angle and a max. angle. I've tried simple things to achieve this but even simple things don't seem to work ! see the following" program snippet" :
If EntityPitch# ( V_Main_Camera_E ) < -80 Then V_CameraX_F=-80
If EntityPitch# ( V_Main_Camera_E ) > 80 Then V_CameraX_F=80
RotateEntity V_CMain_Camera_E,V_CameraX_F,V_CameraY_F,0.0

note that in my main program, I'm using the mouse moves to move the main camera.
To me, adding this code snippet to my main program should work and limit the main camera between -80 and 80 "degrees" (If its correct to say "degrees"). In fact, it doesn't works: the camera isn't limited at all ! Please help me !

Last edited 2011


Warner(Posted 2011) [#8]
Well, same thing: don't use EntityPitch directly, but use the variable:
If V_CameraX_F < -80 Then V_CameraX_F = -80
If V_CameraX_F > 80 Then V_CameraX_F = 80



_PJ_(Posted 2011) [#9]
There's no bug.

EntityPitch can only return values from -90 to +90

Last edited 2011


etxtra(Posted 2011) [#10]
Hi @Malice ! Ok I agree, there's no bug ! Just something that I'm not familiar with...
-Thanks for the help everyone, especially @Warner, thank you, because everything works OK right now.