Projected Texture

Blitz3D SDK Forums/Blitz3D SDK Programming/Projected Texture

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I've tried everything I can think of. Is there some elusive B3D command I have to use for the math that I'm missing? The problem is, the light makes this weird plus effect, and some of the activity I just don't understand at all...

Here's the full code...
should be able to figure it out.

Import Blitz3D.Blitz3DSDK
Import BRL.Math

'Texture Projection (beta) BlitzMax Blitz3D SDK Addon
'by ninjarat

'Thanks to FredBorg's awesome example.

Const PROJECT_CONE=1
Const PROJECT_LINE=2

Private
	Type TReceiver
		Global mesh
	End Type
	
	Type TTexProjector
		Global entity
		Global texture
		Global mode
		Global scale#
		Global r#,g#,b#
	End Type
Public

Function InitTexProjector(texfile$,blend=1)
	bbClearTextureFilters
	
	TTexProjector.texture=bbLoadTexture(texfile,1+8+16+32)
	bbTextureBlend TTexProjector.texture,blend
End Function

Function FreeTexProjector()
	If TTexProjector.texture Then bbFreeTexture TTexProjector.texture
	TTexProjector.texture=Null
End Function

Function SetTexReceiver(mesh,texlayer=1)
	TReceiver.mesh=mesh
	bbEntityTexture TReceiver.mesh,TTexProjector.texture,0,texlayer
End Function

Function SetTexProjectorParams(entity,scale#=.75,projmode=PROJECT_CONE,r#=255,g#=255,b#=255)
	TTexProjector.entity=entity
	TTexProjector.scale=scale
	TTexProjector.mode=projmode
	
	TTexProjector.r=r
	TTexProjector.g=g
	TTexProjector.b=b
End Function

Function TexProjectorUpdate()
	mesh=TReceiver.mesh
	numsurfs=bbCountSurfaces(mesh)
	For s=1 To numsurfs
		surf=bbGetSurface(mesh,s)
		numverts=bbCountVertices(surf)-1
		For vert=0 To numverts
			bbTFormPoint bbVertexX(surf,vert),bbVertexY(surf,vert),..
			 bbVertexZ(surf,vert),mesh,TTexProjector.entity
			
			x#=bbTFormedX()
			y#=bbTFormedY()
			z#=bbTFormedZ()
			
			Select TTexProjector.mode
			Case PROJECT_CONE
				dist#=Sqr(x*x+y*y+z*z)*TTexProjector.scale
				texu#=x/dist+.5
				texv#=1.5-y/dist
			Case PROJECT_LINE
				texu#=(x*TTexProjector.scale)+.5
				texv#=1.5-(y*TTexProjector.scale)
			End Select
			
			bbVertexTexCoords surf,vert,texu,texv
		Next
	Next
End Function