Decals

Blitz3D Forums/Blitz3D Programming/Decals

Sunteam Software(Posted 2004) [#1]
I know this has probably been asked before but I can't seem to find just the right solution.

I'm firing objects which upon a collision with the level mesh I intend to mark it with a sprite (i.e. bullet hole). The problem I have is that I can gain the collision normals no problem but I just can't seem to get my head around the math required to rotate the sprite for the bullet hole to match that of the surface being hit.

The collision normals do seem to be being reported correctly (naturally) but I think my 3D maths is just not up to the task. If someone could briefly explain, possibly with some code it would really help :)

Thanks


Tom(Posted 2004) [#2]
Position the sprite, align it, move it slightly on +Z axis to prevent z fighting

PositionEntity sprite,px#,py#,pz#
AlignToVector sprite,nx#,ny#,nz#,3 ; align Z axis
MoveEntity sprite,0,0,.001 ; experiment with best value for you


aab(Posted 2004) [#3]
I was going to ask that, just now..... Thanks


Sunteam Software(Posted 2004) [#4]
Thanks Tom.


Sunteam Software(Posted 2004) [#5]
OK, this is very weird :/

That doesn't work as is, I had to add a rotate on it because it was facing 180 degs from where it should have been facing. So I now have this code:

;nx#,ny#,nz taken from collision normal
PositionEntity bp,x#,y#,z#
AlignToVector bp,nx#,ny#,nz#,3
MoveEntity bp,0,0,0.1
;turn entity right way around
TurnEntity bp,0,0,180,True


This works fine where the collisions Z normal (nz#) is zero however if it is not zero then it just totally disappears! My current test level was done in Maplet and all the walls are all axis aligned, so collision normals only occur at right angles (a normal of 1 or -1 on the relevant axis).

The entities are all native blitz sprites so no funny proprietory stuff is being used. Any ideas anyone?


big10p(Posted 2004) [#6]
Try removing the TurnEntity line and change the following lines:
AlignToVector bp,-nx#,-ny#,-nz#,3
MoveEntity bp,0,0,-0.1


Or:

Change the TurnEntity line to:
TurnEntity bp,0,180,0,False


Not tested any of that but think it should work. Basically, Blitz sprites 'point' in the opposite direction to how you may think.


Sunteam Software(Posted 2004) [#7]
Ahh thanks, will try it out :)