Topic: Sprites instead of billboard
Hi,
I am trying to make sprites similar to b3d. Since Irrlicht billboards always face the camera, we have to use another method to simulate SpriteViewMode 2 (Free), 3 and 4 (upright). I am having some problems to emulate them.
First I tried to create a quad and texture it, but it did not work (nothing appeared on screen!!). I simply used the b3d method:
local Sprite:Mesh=ib3d_CreateMesh()
Local surf:Surface= ib3d_CreateSurface(Sprite,SF_NORMAL)
surf.AddVertex(-1,-1,0, 0, 1)
surf.AddVertex(-1, 1,0, 0, 0)
surf.AddVertex( 1, 1,0, 1, 0)
surf.AddVertex( 1,-1,0, 1, 1)
surf.AddTriangle(0,1,2)
surf.AddTriangle(0,2,3)
Local tex:texture = ib3d_loadtexture(tex_filename)
ib3d_EntityTexture (sprite,tex)
After I searched on Irrlich forum I tried this (which worked!, just like a quad!)
global sprite3:iscenenode
Local sp:IAnimatedMesh = _g_ib3d_engine.smgr.addHillPlaneMesh("sprite" , _dimension2df(1.0 , 1.0) , _dimension2di(1 , 1) )
sprite3:iscenenode=_g_ib3d_engine.smgr.addmeshscenenode(sp.getmesh(0))
sprite3.setmaterialtype(EMT_TRANSPARENT_ALPHA_CHANNEL)
sprite3.setmaterialtexture(0,_g_ib3d_engine.driver.gettexture("sprite.png"))
sprite3.setscale(Vector3df.createFromVals(10,10,10))
sprite3.setposition(_vector3df(-7,7,-55))
sprite3.setRotation(_VECTOR3DF(-90,0,0)) '
ok, my problem now is to update the sprite position. I am having problems to get it right. it behaves strangely, now and then it flips and disapears. If someone could take a look on this code, and help me out, would be great:
Function updateSprite(SpriteViewMode)
Local rot_x#,rot_y#,rot_z#
Select SpriteViewMode
Case 1
rot_x#=camera.Pitch(True)
rot_y#=camera.Yaw(True)
rot_z#=0
Case 2
'FREE
Case 3
rot_x#=camera.Pitch(True)
rot_y#=camera.Yaw(True)
rot_z#=camera.Roll(True)
Case 4
rot_x#=0
rot_y#=camera.Yaw(True)
rot_z#=camera.Roll(True)
End Select
sprite3.setRotation(_VECTOR3DF((rot_x+90),rot_y,rot_z))
End Function