Size a Triangle in place.

Blitz3D Forums/Blitz3D Programming/Size a Triangle in place.

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.

Hey Lee, how about this. Press left and right key to scale.

Graphics3D 800,600

SetBuffer BackBuffer()

Global camera=CreateCamera()
PositionEntity camera,0,0,-10

light=CreateLight()

Global mesh=CreateMesh()

Global surf=CreateSurface(mesh)

v0=AddVertex(surf,0, 1,0)
v1=AddVertex(surf,-3,0,0)
v2=AddVertex(surf,1, 0,0)

tri=AddTriangle(surf,v0,v2,v1)

Dim p#(2,2); for scaling the vertexs

Global scale#=1.0


While Not KeyHit(1)


	If KeyDown(203) Then scale=1.01:scale_triangle(surf,0,scale); set scale to either just over 1 or just below 1.
	If KeyDown(205) Then scale=0.99:scale_triangle(surf,0,scale)
	
	
	UpdateWorld
	RenderWorld
	Text 0,0,"scale="+scale
	Flip
Wend
End

Function scale_triangle(surface,index,t_scale#)
	For loop=0 To 2; loop through vertexs x and y and store them
		p(loop,0)=VertexX(surface,index+loop)
		p(loop,1)=VertexY(surface,index+loop)
	Next

	
	centre_x#= (p(0,0)+p(1,0)+p(2,0))/3; centre calculated by averaging all three points
	centre_y#= (p(0,1)+p(1,1)+p(2,1))/3; same as above
	
	; multiply the difference between the centerx and the first vertex point x, by t_scale
	; then add it the centre point x. same for y
	For loop=0 To 2
		VertexCoords(surface,index+loop,centre_x+t_scale*(p(loop,0)-centre_x),centre_y+t_scale*(p(loop,1)-centre_y),p(loop,2))
	Next
End Function