TurnEntity - B3D version
BlitzMax Forums/MiniB3D Module/TurnEntity - B3D version
| ||
Hey, how can I recreate the behaviour of B3D with minib3d? In the release notes is stated that TurnEntity is not implemented like in B3D. But I need a similiar behavior. Say, i want to create a cone like this: Graphics3D 800,600,16,2 CreateCamera Local cone = CreateCone() PositionEntity cone , 0 , 0 , 10 RotateEntity cone,90,0,0 Repeat TurnEntity cone , 0 , 1 , 0 UpdateWorld RenderWorld Flip Until KeyHit(1) End This code rolls the cone clockwise. It's counterpart in minib3d (here in BlitzMax) won't. Framework sidesign.minib3d SuperStrict Graphics3D 800,600,16,2 Collisions 1,2,2,2 CreateCamera Local cone:TMesh = CreateCone() PositionEntity cone , 0 , 0 , 10 RotateEntity cone,90,0,0 Repeat TurnEntity cone , 0 , 1 , 0 UpdateWorld RenderWorld Flip Until KeyHit(KEY_ESCAPE) Or AppTerminate() End I have got the rolling cone with assigning a parent and used the rotate pitch 90 in the init code on the parent. But this will not work well with MoveEntity. I tried the following: Global tp:TEntity=CreatePivot() Function TurnEntity_ (entity:TEntity , p# , y# , r#) Local op:TEntity = GetParent(entity) RotateEntity tp, EntityPitch(entity), EntityYaw(entity), EntityRoll(entity) EntityParent entity , tp,True RotateEntity entity, p , y , r EntityParent entity , op,True End Function I know this will not be very fast but i need like one object turned like that in the main loop. But somehow the cone flips after 90 degrees. Can somebody help me fixing the code? Greez Silver_Knee |
| ||
See above. |
| ||
The issue you are experiencing is called "gimbal lock", and it's a known issue of the algorithm used to manage rotations in MiniB3D. Blitz3D uses another method, based on quaternions, that is more accurate; you can't just "tweak" the TurnEntity command, you need a new version of it. Years ago user EdzUp wrote an alternate version (that is still somewhere in the code archive), but that version had problems when the entity was turned by 90 degrees, and didn't worked for child entities. The real solution is to replace the internal formulas with quaternions: user Warner did it in the past, building a modified version that had rotations working like Blitz3D; that fork seems to be abandoned now, but I included the changes he did in OpenB3D, so it has rotations similar to Blitz3D, too. So, my suggestion is: try replacing MiniB3D with OpenB3D, because in OpenB3D that issue has been fixed. |
| ||
It's a little bit more complex but I think this should do the trick, I use my "Turn" function in my space ship steering and it works like in Blitz3D: |
| ||
Krischan, your function seem to work well. In fact, i want to turn a spaceship as well :) angros47, changing to OpenB3D is surely the better approach for the future, but for now I'll use the "fix" of Krischan. Thanks to both of you |
| ||
See it in action here: Asteroid Fields (in the inc/turncam.bmx) |