Entity Angle problem
BlitzMax Forums/MiniB3D Module/Entity Angle problem
| ||
not sure if this is a bug:Import sidesign.MiniB3D Graphics3D 800,600 cube:Tentity =CreateCube() ; cam:Tentity=CreateCamera() ; MoveEntity cam,0,0,-5 Repeat TurnEntity cube,0,3,0 RenderWorld text 0,0,"EntityPitch(cube) = GLOBAL: "+EntityPitch(cube,True)+" Local: "+EntityPitch(cube) text 0,20,"EntityYAW(cube) = Global: "+EntityYaw(cube,True)+" Local: "+EntityYaw(cube) text 0,40,"EntityROLL(cube) = Global: "+EntityRoll(cube,True)+" Local: "+EntityRoll(cube) Flip Until KeyDown(KEY_ESCAPE) should the entity pitch/yaw/roll values wrap to 360? (or 180/-180) EDIT: a possible solution would be to pass the ang vals to a function like this. looking through the TEntity.bmx code I am not sure where this would/could be done. It looks like ry# is acted upon in just about every rotation/translation call. I won't even pretend to know where this should go :) : Function Wrap360:Float(angle#) If angle > 359.999 Then angle = angle - 360 If angle < 0 Then angle = 360 + angle Return angle End Function |
| ||
Strange enough ... using the global flag EntityYaw(cube,1) it returns values similar to Blitz3D. |
| ||
LAB[au], I updated the test code to reflect your observations. thanks. I did not notice that. regardless of whether you call EntityYaw or not, the ry# value increments every time turnentity is called. maybe eventually it will=NAN. |
| ||
a number that increments *might* cause an overflow error but is as likely to simply overflow and wrap round, this depends on the math libs used and sometimes on the processor a NAN (Not A Number) is something entirely different... I think you might find angle=angle mod 360 might be a little faster, but its largely a moot point, if you want to watch an object rotate till it causes an overflow error, you could be waiting a long time... |
| ||
that's a good point Chris. I just wanted to bring this to simon's attention. also, angle=angle mod 360 is not really what I am looking for. the goal is to clamp the angle value between 0-360. if a large number is added or subtracted and it wraps around zero, the new angle needs to reflect that. i.e 355+10 = 365 (out of range!) Wrap360 returns '5' as the new wrapped angle try this to see the difference: Import sidesign.MiniB3D Graphics3D 800,600 cube:Tentity =CreateCube() ; cam:Tentity=CreateCamera() ; MoveEntity cam,0,0,-5 Repeat ' Mod method angle1#:-9.3 angle1=angle1 Mod 360 ' Wrap 360 Function method angle2#:-9.3 angle2# = wrap360(angle2#) TurnEntity cube,0,3,0 RenderWorld text 0,60,"angle = angle Mod 360: "+angle1 text 0,80,"Wrap360(angle): "+angle2 text 0,120," press a key" Flip WaitKey() Until KeyDown(KEY_ESCAPE) Function Wrap360:Float(angle#) If angle > 359.999 Then angle = angle - 360 If angle < 0 Then angle = 360 + angle Return angle End Function |
| ||
Yeah thanks for pointing this out. Your function is a bit unreliable bradford as if the angle is for example 1000, simply subtracting 360 doesn't wrap the value. |
| ||
ok. I'll work on that :) *** long pause *** EDIT: ok, I'm back this seems to work. (I put Chris C's Mod Angle where he probably meant for it to go all along :) ) I did a few tests: here is one. i revved the amount up to 1006.29 with the angle at 0.0 using my trusty Google calculator I find that http://www.google.com/search?q=1006+mod+360 =286 I press the right arrow once and my new angle = 286.29 (not sure how efficient/useful this is but it was fun) Import sidesign.MiniB3D Graphics3D 800,600 cube:Tentity =CreateCube() ; cam:Tentity=CreateCamera() ; MoveEntity cam,0,0,-5 EntityColor cube,200,0,0 light = CreateLight() ; MoveEntity light,-5,5,-5 Local amount:Float = 3.1 Repeat ' Mod method angle1#=angle1# Mod 360 ' Wrap 360 Function method angle2# = wrap360(angle2#) RotateEntity cube,0,angle2#,0 RenderWorld text 0,40,"Step Amount: "+amount text 0,60,"angle = angle Mod 360: "+angle1 text 0,80,"Wrap360(angle): "+angle2 text 0,120," press left/right keys to inc/dec angle" text 0,140," press up/down keys to inc/dec step amount" Flip If Keyhit(KEY_LEFT) angle1:-amount angle2:-amount EndIf If Keyhit(KEY_RIGHT) angle1:+amount angle2:+amount EndIf If KeyDown(KEY_UP) amount:+3.3 EndIf If KeyDown(KEY_DOWN) amount:-3.3 EndIf Until KeyDown(KEY_ESCAPE) Function Wrap360:Float(angle#) angle:Mod 360 If angle > 359.999 Then angle = angle - 360 If angle < 0 Then angle = 360 + angle Return angle End Function |