Code archives/3D Graphics - Mesh/Create a ladder

This code has been declared by its author to be Public Domain code.

Download source code

Create a ladder by Boiled Sweets2005
This is a basic example of how to create a ladder. The ladder function takes 2 parameters, the first is the length and the second is the wonkyness. Try 8 and 8 for a rickerty wild west ladder for example! Creates it as a single surface too. Simply apply your favourite wood texture and off you go. Use as you see fit. Any improvements please let me know. (BTW took 8 mins to code).
; CreateCube Example
; ------------------

Graphics3D 1024,768,32
SetBuffer BackBuffer()

p = CreatePivot()

SeedRnd (MilliSecs()) 
camera=CreateCamera(p)
PositionEntity camera, 0,0, -4

light=CreateLight()
RotateEntity Light,45,0,0

height$=Input$("Ladder height?       1-100    :") 
wonky$=Input$("Ladder wonnkyness?     0-10    :") 

createLadder(Int(height), Int(wonky))

While Not KeyDown( 1 )

If KeyDown(203)
	TurnEntity p, 0, -3, 0
EndIf

If KeyDown(205)
	TurnEntity p, 0, 3, 0
EndIf

If KeyDown(200)
	TurnEntity p, -3, 0, 0
EndIf

If KeyDown(208)
	TurnEntity p, 3, 0, 0
EndIf

If KeyDown(30)
	MoveEntity camera, 0, 0, .1
EndIf

If KeyDown(44)
	MoveEntity camera, 0, 0, -.1
EndIf


RenderWorld
Text 10,10, "Cursor keys to turn, A / Z to zoom, escape to quit"
Flip
Wend

End

Function createLadder(length#, wonky#)

	rungs = length * 2
	rung_distance# = (length / (rungs+1)) 
	length = length / 2

	; legs
	
	leg_left=CreateCube()
	ScaleMesh leg_left, .1, length, .1
	PositionMesh leg_left,-.4, 0, 0
	
	leg_right=CreateCube()
	ScaleMesh leg_right, .1, length, .1
	PositionMesh leg_right, .4, 0, 0
	
	;rungs
		
	rung_start# = -(rung_distance#/2) - (((rungs-2)/2) * rung_distance#)

	For i = 1 To rungs 
		rung=CreateCube()
		ScaleMesh rung, .6, .07, 0.05
		RotateMesh rung, 0, 0, Rnd(-wonky, wonky)
		PositionMesh rung, 0, rung_start#, -0.1
		rung_start# = rung_start# + rung_distance#
		AddMesh rung, leg_left
		FreeEntity rung
	Next

	AddMesh leg_right, leg_left	
	FreeEntity leg_right
	
	;Tex = LoadTexture ("wood02.jpg")
	;EntityTexture leg_left, Tex
	
End Function

Comments

Oiduts Studios2008
nice


Yasha2009
Makes nice railway tracks...


Code Archives Forum