- Joined
- Jul 3, 2017
- Messages
- 252
Is the entity parent system on MiniB3D broken?
I'm trying to rotate a dice using the keyboard. This is an old mesh I've used on Blitz3D and in there it works.
What I am doing:
I create a pivot and set it to parent of the 'dice entity'. Then, I rotate that pivot -90 or +90 in X or Y (pitch or yaw), the entity rotates along.
Then I REMOVE the pivot as parent, reset its rotation to 0,0,0 and add it as parent again to the dice entity.
This works flawlessly on Blitz3D. On MiniB3D on Monkey, it fails as the picture below shows: (the text is showing the dice at the top left, the pivot parent and the child 'dice entity'). Sometimes the dice won't update properly?! The weird thing is that it doesn't fail always, just sometimes on specific rotations.
I tought of gimbal lock, but forcing the pivot angles and the dice entity between 0...360 made no difference.
Using "RotateEntity" or "TurnEntity" had the same problem.
I also disabled GC, no difference.
(I'm trying this on GLFW, if it makes any difference... and I can't test it on HTML5, apparently there is something wrong with the code and it fails to compile when using no VBO)
My dice class:
Am I missing something? Its been ages since I've done anything in 3D, so it might be the case. If anyone can shed a light, please do. I'm stumped here
I'm trying to rotate a dice using the keyboard. This is an old mesh I've used on Blitz3D and in there it works.
What I am doing:
I create a pivot and set it to parent of the 'dice entity'. Then, I rotate that pivot -90 or +90 in X or Y (pitch or yaw), the entity rotates along.
Then I REMOVE the pivot as parent, reset its rotation to 0,0,0 and add it as parent again to the dice entity.
This works flawlessly on Blitz3D. On MiniB3D on Monkey, it fails as the picture below shows: (the text is showing the dice at the top left, the pivot parent and the child 'dice entity'). Sometimes the dice won't update properly?! The weird thing is that it doesn't fail always, just sometimes on specific rotations.
I tought of gimbal lock, but forcing the pivot angles and the dice entity between 0...360 made no difference.
Using "RotateEntity" or "TurnEntity" had the same problem.
I also disabled GC, no difference.
(I'm trying this on GLFW, if it makes any difference... and I can't test it on HTML5, apparently there is something wrong with the code and it fails to compile when using no VBO)

My dice class:
Cerberus:
Class Dice
Field mesh:TEntity
Field pivot:TPivot
Field state:Int
Field curAngle:Float, targetAngle:Float
Field direction:Int
Field x:Float, y:Float
Method New(x:Int, y:Int, side:Int)
mesh = CopyEntity(Resources.diceModel)
pivot = CreatePivot()
Self.x = x
Self.y = y
ShowEntity mesh
Select side
Case 1
RotateEntity mesh, 0, -90, 0, True
Case 2
RotateEntity mesh, 90, 0, 0, True
Case 3
' do nothing
Case 4
RotateEntity mesh, 180, 0, 0, True
Case 5
RotateEntity mesh, -90, 0, 0, True
Case 6
RotateEntity mesh, 0, 90, 0, True
End Select
PositionEntity mesh, x, y, 0
PositionEntity pivot, x, y, 0
EntityParent mesh, pivot
state = 0
End Method
Method update()
Local speed:Float = 10
Select state
Case 0
' do nothing
Case 1
' turning
Select direction
Case Direction.UP
If curAngle <= targetAngle - speed
curAngle+=speed
'TurnEntity pivot, speed, 0, 0, True
RotateEntity pivot, curAngle, 0, 0
Else
state = 0
End If
Case Direction.DOWN
If curAngle >= targetAngle + speed
curAngle-=speed
'TurnEntity pivot, -speed, 0, 0, True
RotateEntity pivot, curAngle, 0, 0
Else
state = 0
End If
Case Direction.LEFT
If curAngle >= targetAngle + speed
curAngle-=speed
'TurnEntity pivot, 0,-speed, 0, True
RotateEntity pivot, 0, curAngle, 0
Else
state = 0
End If
Case Direction.RIGHT
If curAngle <= targetAngle - speed
curAngle+=speed
'TurnEntity pivot, 0,speed, 0, True
RotateEntity pivot, 0, curAngle, 0
Else
state = 0
End If
End Select
If state = 0 Then
Print "::: END :::"
End If
End Select
End Method
Method turn(dir:Int)
If state = 0 Then
Self.direction = dir
EntityParent mesh, Null
RotateEntity pivot, 0, 0,0
EntityParent mesh, pivot
curAngle = 0
Select dir
Case Direction.UP
targetAngle = 90
Case Direction.DOWN
targetAngle = 90
Case Direction.LEFT
targetAngle = -90
Case Direction.RIGHT
targetAngle = 90
End Select
state = 1
End If
End Method
End Class
Am I missing something? Its been ages since I've done anything in 3D, so it might be the case. If anyone can shed a light, please do. I'm stumped here
Last edited: