Bug???

Blitz3D Forums/Blitz3D Programming/Bug???

big10p(Posted 2007) [#1]
There seems to be a problem parenting an entity to another that has negative scale. Before posting this in bug reports, I thought I'd post it here in case anyone can shed some light.

In the example below, I expect the cone to retain it's global position/rotation/scale when parented, but this is clearly not happening:

(P.S. I know I'm randomly scaling the balls with potentially negative values, but this is a completely legitimate thing to do. It should still work! :))

	Graphics3D 800,600,32,2
	SetBuffer BackBuffer()

	cam = CreateCamera()
	PositionEntity cam,0,0,-15
	
	light = CreateLight()

	
	; Create some balls, parented together in a chain.
	ball = CreateSphere()
	For n = 1 To 5
		ball = CreateSphere(8, ball)
		ScaleEntity(ball,Rnd(-5,.5), Rnd(-5,.5), Rnd(-5,.5), True)
		PositionEntity(ball, Rnd(-10,10), Rnd(-10,10), 0, True)
		TurnEntity(ball, 0,0,Rnd(360), True)
	Next

	; Create cone.
	cone = CreateCone()
	PositionEntity cone,3,3,0
	ScaleEntity cone,.5,2,.5
	
	; Parent cone to last ball, but keep cone's global position/rotation/scale ???
	; (comment this line out to see how things should look!)
	EntityParent cone,ball,True


	While Not KeyHit(1)

		RenderWorld
		
		Text 10,10,"  Cone global pos:  x:" + EntityX(cone,True) + "  y:" + EntityX(cone,True) + "  z:" + EntityZ(cone,True)
		Text 10,30,"Cone global scale:  x:" + EntityScaleX(cone,True) + "  y:" + EntityScaleY(cone,True)+ "  z:" + EntityScaleZ(cone,True)
		Text 10,50," Cone local scale:  x:" + EntityScaleX(cone,False) + "  y:" + EntityScaleY(cone,False)+ "  z:" + EntityScaleZ(cone,False)
		
		Flip True

	Wend

	End


Function EntityScaleX#(entity, globl=False) 
	If globl Then TFormVector 1,0,0,entity,0 Else TFormVector 1,0,0,entity,GetParent(entity) 
	Return Sqr(TFormedX()*TFormedX()+TFormedY()*TFormedY()+TFormedZ()*TFormedZ()) 
End Function 

Function EntityScaleY#(entity, globl=False)
	If globl Then TFormVector 0,1,0,entity,0 Else TFormVector 0,1,0,entity,GetParent(entity)  
	Return Sqr(TFormedX()*TFormedX()+TFormedY()*TFormedY()+TFormedZ()*TFormedZ()) 
End Function 

Function EntityScaleZ#(entity, globl=False)
	If globl Then TFormVector 0,0,1,entity,0 Else TFormVector 0,0,1,entity,GetParent(entity)  
	Return Sqr(TFormedX()*TFormedX()+TFormedY()*TFormedY()+TFormedZ()*TFormedZ()) 
End Function 



Danny(Posted 2007) [#2]
I can't say I've really studied this (sorry, bit in a hurry here) but at first glance I'd say you're right!

[edit]
Yes, scale should obviously be inherited from the parent like position & rotation, but might it have to do with the fact you first scale the cone _and then_ parent it to the sphere (possibly creating a 'skewered' result)?
If instead you created the cone and parent it directly like "cone=createCone(x,x,parentBall)" and then scaling the cone locally give the same result or problem?

Danny


big10p(Posted 2007) [#3]
That's the thing, I'm specifically telling it not to inherit the parents rotation/scale, but the cone is still getting skewed.

I tried parenting the cone straight away in the CreateCone command, and then scaling it using the global flag, but the problem still exists.


Floyd(Posted 2007) [#4]
The global flag must adjust the child's position etc. so that parent and child values cancel each other.

In order for this example to work the way you want Blitz3D would have to adjust for the entire chain "parent of parent of parent...".

I don't know if that's a realistic goal.


big10p(Posted 2007) [#5]
Hmm, not sure I quite understand what you're saying, Floyd.

To find a child's global position/rotation/scale you have to iterate right up to the top of the parent chain. e.g. you can't tell what local scale to set a new child to, in order for it to keep it's global scale, just by looking at the parent's scale, as the parent's scale is just a ratio if it's parent, and so on.

Besides, the above code works fine when not using negatively scaled entities.

Also, the only reason I discovered this 'bug' was by doing some testing with B3D against my own entity system, to ensure my system behaves the same as B3D. Funnily enough, my system seems to handle this situation fine - albeit, my system is only for 2D vector entities.


big10p(Posted 2007) [#6]
Here's a version that doesn't even use negatively scaled entities!
	Graphics3D 800,600,32,2
	SetBuffer BackBuffer()

	cam = CreateCamera()
	PositionEntity cam,0,0,-15
	
	light = CreateLight()

	
	; Create some balls, parented together in a chain.
	ball = CreateSphere()
	For n = 1 To 5
		ball = CreateSphere(8, ball)
		ScaleEntity(ball, Rnd(.1,.5), Rnd(.1,.5), Rnd(.1,.5), True)
		PositionEntity(ball, Rnd(-10,10), Rnd(-10,10), 0, True)
		TurnEntity(ball, 0,0,Rnd(360), True)
	Next

	; Create cone.
	cone = CreateCone()
	ScaleEntity cone,.5,1,.5
	PositionEntity cone,3,3,0
	TurnEntity cone,0,0,90

	; Parent cone to last ball, but keep cone's global position/rotation/scale ???
	; (comment this line out to see how things should look!)
	EntityParent cone,ball,True


	While Not KeyHit(1)

		RenderWorld
		Flip True

	Wend

	End

Also, if you comment out the TurnEntity command in the ball creation loop, things look as they should. What the heck's going on?!

Think I'll post this in Bug Reports...