SpriteViewMode 3 & 4

BlitzMax Forums/MiniB3D Module/SpriteViewMode 3 & 4

Bobysait(Posted 2007) [#1]
Maybe not the best way, but it seems to work

in TGlobal.bmx

	Function UpdateSprites(cam:TCamera,list:TList)

		For Local sprite:TSprite=EachIn list
		
			If sprite.view_mode=1 ' face camera
			
				Local x#=sprite.mat.grid[3,0]
				Local y#=sprite.mat.grid[3,1]
				Local z#=sprite.mat.grid[3,2]
			
				sprite.mat.Overwrite(cam.mat)
				sprite.mat.grid[3,0]=x
				sprite.mat.grid[3,1]=y
				sprite.mat.grid[3,2]=z
				sprite.mat_sp.Overwrite(sprite.mat)
				
				If sprite.angle#<>0.0
					sprite.mat_sp.RotateRoll(sprite.angle#)
				EndIf
				
				If sprite.scale_x#<>1.0 Or sprite.scale_y#<>1.0
					sprite.mat_sp.Scale(sprite.scale_x#,sprite.scale_y#,1.0)
				EndIf
				
				If sprite.handle_x#<>0.0 Or sprite.handle_y#<>0.0
					sprite.mat_sp.Translate(-sprite.handle_x#,-sprite.handle_y#,0.0)
				EndIf
				
			Else ' free view

				sprite.mat_sp.Overwrite(sprite.mat)
				
				If sprite.scale_x#<>1.0 Or sprite.scale_y#<>1.0
					sprite.mat_sp.Scale(sprite.scale_x#,sprite.scale_y#,1.0)
				EndIf
			EndIf

			If sprite.view_mode=3 ' face camera + adjust roll
				sprite.RotateEntity(cam.EntityPitch(1),cam.EntityYaw(1),sprite.EntityRoll(1),1)
			ElseIf sprite.view_mode=4 ' adjust Yaw to face camera
				sprite.RotateEntity(sprite.EntityPitch(1),cam.EntityYaw(1),sprite.EntityRoll(1),1)
			EndIf
			
		Next
	
	End Function


problem : When switching the SpriteViewMode, rotations are transformed, so initialised values are lost.
eg. turn around the sprite in viewmode 1 then switch to viewmode 2 => the sprite stay with the last transformation...
=> In Blitz3D, the sprite is always 0,0,0 pitch,yaw,roll , and the camera facing does not affect it.