Face scaling

Blitz3D Forums/Blitz3D Programming/Face scaling

Neo Genesis10(Posted 2003) [#1]
Hiya. Recently began remaking my World Editor from way back when. One of the features I would like to include is the ability to scale selected faces. Essentially this means moving the vertices which make up the face away from the center of the selection.

Does anyone have a way to calculate which direction each vertex would need to be moved?


Ross C(Posted 2003) [#2]
Hey, i would probably find the centre point for the mesh, then say the centre is (0,0,0) :

scale#=2
angle=45
vertexcoords(surf,index,vertexX(surf,index)*scale,vertexY(surf,index)*scale,vertexZ(surf,index)*scale )


this is assuming the centre coords are (0,0,0), it should scale out the vertexs correctly. Just loop thru the vertexs you want. Sorry but i can't test it cause i'm in college. I'll give it a test when i get home :D


Ross C(Posted 2003) [#3]
Ok, here is the code. Up and DOWN to scale the face, and LEFT and RIGHT to rotate the camera. Hope this helps a bit :)

Graphics3D 800,600
SetBuffer BackBuffer()


cam=CreatePivot()
camera=CreateCamera(cam)
PositionEntity camera,0,0,-10

light=CreateLight()

sphere=CreateSphere()

mesh = CreateMesh()
surf = CreateSurface(mesh)

scale#=1

v0 = AddVertex (surf, -1, 1, 0.5)
v1 = AddVertex (surf,  1, 1, 0.5)
v2 = AddVertex (surf, -1,-1, 0.5)
v3 = AddVertex (surf,  1,-1, 0.5)

v4 = AddVertex (surf,  0.5,8  , 0)
v5 = AddVertex (surf,  -8 ,0.5, 0)


Dim vert#(3,2)
vert(0,0)=-1
vert(0,1)=1
vert(0,2)=-0.5

vert(1,0)=1
vert(1,1)=1
vert(1,2)=-0.5

vert(2,0)=-1
vert(2,1)=-1
vert(2,2)=-0.5

vert(3,0)=1
vert(3,1)=-1
vert(3,2)=-0.5

tri = AddTriangle (surf,v0,v1,v2)
tri1= AddTriangle (surf,v1,v3,v2)
tri2= AddTriangle (surf,v0,v4,v1)
tri3= AddTriangle (surf,v0,v2,v5)

UpdateNormals(mesh)
EntityFX mesh,16
brush=CreateBrush()
BrushColor brush,200,10,200
BrushShininess brush,1
PaintEntity mesh,brush

While Not KeyHit(1)
	
	
	If KeyDown(200) Then
		scale=scale+0.1
		For loop=0 To 3
			VertexCoords(surf,loop,vert(loop,0)*scale, vert(loop,1)*scale, vert(loop,2)*scale)
		Next
	ElseIf KeyDown(208) Then
		scale=scale-0.1
		For loop=0 To 3
			VertexCoords(surf,loop,vert(loop,0)*scale, vert(loop,1)*scale, vert(loop,2)*scale)
		Next
	End If
	
	If KeyDown(203) Then TurnEntity cam,1,0,0
	If KeyDown(205) Then TurnEntity cam,-1,0,0
	
	TurnEntity light,1,1,0
	
	UpdateWorld
	RenderWorld
	Text 0,0," UP and DOWN to scale mesh. LEFT and RIGHT to rotate.
	Flip
Wend
End



Neo Genesis10(Posted 2003) [#4]
Thanks Ross, awesome stuff. Got it working perfectly now. Now to work on those annoying extrusions...


Ross C(Posted 2003) [#5]
np, and good luck :)