old robot arm sample

Blitz3D Forums/Blitz3D Programming/old robot arm sample

Kepu(Posted 2010) [#1]
I was trying to introduce Blitz3d to my son and I mention that there was (ten years ago) a small / good sample code for use of primitives and entitymovements, I think it's name was 'Robot arm'.
But i can find it. ( My machine has crashed couple times)

If somebody knows what I mean and have that simple code sample, Please , post it here or give a link where I can find it.
(It is good sample for beginner).


ZJP(Posted 2010) [#2]
; Fully Articulated Robotic Arm
; By Reda Borchardt

Include "start.bb"
Include "keyconstants.bb"
message=1
banner = LoadImage("top_banner.jpg")
MaskImage banner,255,255,0

; Load the object and assign a handle to all sub-objects
;robotarm = LoadAnimMesh("ROBOTIC_ARM.3DS")
;stand =    FindChild(robotarm,"stand")
robotarm = LoadAnimMesh("dodo.3DS")
stand =    FindChild(robotarm,"TOUR")
upperarm = FindChild(robotarm,"upperarm")
lowerarm = FindChild(robotarm,"lowerarm")
wrist =    FindChild(robotarm,"wrist")
clamp =    FindChild(robotarm,"clamp")

; Add Some Light
AmbientLight 0,0,255
light = CreateLight(1)
PositionEntity light,40,20,-30

; Load The Camera And Put It Into A Pivot With Two Axes
horizontal_camera_pivot = CreatePivot()
vertical_camera_pivot = CreatePivot(horizontal_camera_pivot)
camera = CreateCamera(vertical_camera_pivot)

; Put The Camera Somewhere And Resize The Model To A Reasonable Size
ScaleEntity robotarm,0.1,0.1,0.1
MoveEntity robotarm,0,-10,0
PositionEntity camera,0,10,-40
PointEntity camera,horizontal_camera_pivot


While Not KeyHit(1)
	
	If KeyDown(key_q) Then TurnEntity stand,1,0,0
   	If KeyDown(key_a) Then TurnEntity stand,-1,0,0	
	If KeyDown(key_w) Then TurnEntity stand,0,1,0
   	If KeyDown(key_s) Then TurnEntity stand,0,-1,0
	If KeyDown(key_e) Then TurnEntity lowerarm,0,0,-0.3
   	If KeyDown(key_d) Then TurnEntity lowerarm,0,0,0.3
	If KeyDown(key_r) Then TurnEntity wrist,0,0,0.3
   	If KeyDown(key_f) Then TurnEntity wrist,0,0,-0.3
	If KeyDown(key_t) Then TurnEntity clamp,0.3,0,0
   	If KeyDown(key_g) Then TurnEntity clamp,-0.3,0,0

	If KeyDown(key_arrowpad_up) Then TurnEntity vertical_camera_pivot,0.3,0,0
	If KeyDown(key_arrowpad_down) Then TurnEntity vertical_camera_pivot,-0.3,0,0
	If KeyDown(key_arrowpad_left) Then TurnEntity horizontal_camera_pivot,0,-0.3,0
	If KeyDown(key_arrowpad_right) Then TurnEntity horizontal_camera_pivot,0,0.3,0

	PointEntity camera,horizontal_camera_pivot

	UpdateWorld
	RenderWorld
	
	DrawImage banner,0,0
	
	If KeyHit(Key_h) Then
		If message=0 Then message =1
		If message=1 Then message =0
	End If
	
	If KeyHit(key_z) Then
		WireMode = Not WireMode
		WireFrame WireMode
	End If
	
	If message=1 Then

		Text 0,100,"Robotic Arm"
		Text 0,120,"Keys: Use Keys Q to T and A to G"
		Text 0,140,"Use The Arrow Keys To Move The Camera"
		Text 0,180,"Keys: 'Z' to toggle wireframe mode"
		Text 0,200,"Keys: H to hide this message
	End If
	
	Flip
Wend



Kepu(Posted 2010) [#3]
Thanks ZIP
That's quite sophisticated code it uses ready made .3ds stuff and so ...
What I was looking uses 'CreateCylinder' CreateCube' to create robotic arm first then other stuff.

Yours


Kepu(Posted 2010) [#4]
Ok, I could not to find it , but I had few hours on weekend to do it.
This is about similar, that I was looking , everything made in Blitz3d and animated

; Creating Robot

Graphics3D 800,600
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,0,-25

light=CreateLight()
RotateEntity light,90,0,0

;Create base for robot
base=CreateCube()
PositionEntity base,0,-0.8,0
EntityColor base,255,255,0  ; base color yellow


pivot=CreatePivot()                   ; Create pivot. This is invisible.
joint=CreateCylinder(16,True,pivot)   ; Create joint. Make the pivot the parent of the joint.
TurnEntity joint,90,0,0
ScaleEntity joint,0.8,0.7,0.8
EntityColor joint,255,0,255           ; color red
cylinder=CreateCylinder(16,joint)     ;Create first arm. Make the joint the parent of the arm (cylinder).
PositionEntity cylinder,0,2,0
ScaleEntity cylinder,0.7,2,0.7
EntityColor cylinder,255,255,0        ; color yellow


pivot1=CreatePivot()                  ; Create pivot1.
PositionEntity pivot1,0,4,0
joint1=CreateCylinder(16,True,pivot1) ; Create joint1. Make the pivot1 the parent of the joint1.
TurnEntity joint1,90,0,0
ScaleEntity joint1,0.65,0.7,0.65
EntityColor joint1,255,0,255          ; color red
cylinder1=CreateCylinder(16,joint1)   ;Create second arm. Make the joint1 the parent of the arm (cylinder1).
PositionEntity cylinder1,0,6,0
ScaleEntity cylinder1,0.6,2,0.6
EntityColor cylinder1,255,255,0       ; color yellow


pivot2=CreatePivot()                  ; Create pivot2.
PositionEntity pivot2,0,8,0
joint2=CreateCylinder(16,True,pivot2) ; Create joint2 (i.e. a cylinder). Make the pivot2 the parent of the joint2.
TurnEntity joint2,90,0,0
ScaleEntity joint2,0.6,0.6,0.6
EntityColor joint2,255,0,255          ; color red
cylinder2=CreateCylinder(16,joint2)   ;Create third arm. Make the joint2 the parent of the arm (cylinder2).
PositionEntity cylinder2,0,10,0
ScaleEntity cylinder2,0.5,2,0.5
EntityColor cylinder2,255,255,0       ; color yellow


pivot3=CreatePivot()                  ; Create pivot3.
PositionEntity pivot3,0,12,0
joint3=CreateSphere(16,pivot3)        ; Create joint3. Make the pivot3 the parent of the joint3
ScaleEntity joint3,0.6,0.6,0.6
EntityColor joint3,50,200,200         ; color red
welder3=CreateCone(16,joint3)         ;Create welder tip. Make the joint3 the parent of welder tip (welder3).
PositionEntity welder3,0,13,0
ScaleEntity welder3,0.4,1.2,0.4
EntityColor welder3,155,155,155       ; color yellow
 
;parenting pivots
EntityParent pivot1,pivot
EntityParent pivot2,pivot1
EntityParent pivot3,pivot2

;parenting entities
EntityParent cylinder,joint
EntityParent cylinder1,joint1
EntityParent cylinder2,joint2
EntityParent welder3,joint3


s=1

While Not KeyDown(1)

;A small rutine to get the robot alive
b=b+1                                ;degr. that whole asssembly rotates arround y
a=a+s:                               ;degr. used for bending arms
If a>45 Then    
 s=-1*s
ElseIf a<0 Then
 s=-1*s                              ;values turning back
EndIf

; Rotete/Turn pivots, thus making joints spin around
RotateEntity base,0,b,0              ;rotate base
RotateEntity pivot,0,b,-a+60         ;rotate whole robot
RotateEntity pivot1,0,0,a-120        ;rotate pivot1
RotateEntity pivot2,0,0,a-70         ;rotate pivot2
RotateEntity pivot3,0,0,a            ;rotate pivot3


RenderWorld
Flip

Wend

End