Given a U and V value, transform that to 3D coordinates

Blitz3D Forums/Blitz3D Programming/Given a U and V value, transform that to 3D coordinates

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.

It mostly comes down to a pointintriangle() function. Something like this...

Function TFormTextureCoords(u#,v#,mesh)
For s=1 To CountSurfaces(mesh)
	surf=GetSurface(mesh,1)
	For t=0 To CountTriangles(surf)-1
		a=TriangleVertex(surf,t,0)
		b=TriangleVertex(surf,t,1)
		c=TriangleVertex(surf,t,2)
		au#=VertexU(surf,a)
		av#=VertexV(surf,a)
		bu#=VertexU(surf,b)
		bv#=VertexV(surf,b)
		cu#=VertexU(surf,c)
		cv#=VertexV(surf,c)
		If PointInTriangle(u,v,au,av,bu,bv,cu,cv)
			TFormPoint x#,y#,z#,0,0
			Return True
			EndIf
		Next
	Next
Return False
End Function

Function PointInTriangle(x#,y#,Ax#,Ay#,Bx#,By#,Cx#,Cy#)

End Function