camera on robot arm

Blitz3D Forums/Blitz3D Programming/camera on robot arm

shawnus(Posted 2003) [#1]
(I think I put this on the wrong part of the forum before). I am trying to stick a second camera onto the end of the robot arm (Reda Borchardt’s open dna tutorial) object. I thought the best way would be to use the wrist’s global xyz co-ordinates to determine the second camera’s global xyz position, but I can’t get it to work. I would also like to be able to point the camera at the centre (0,0,0), and also free the camera to point in a specific direction. Any help would be appreciated.

Here’s the code:

; 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")
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)

camera2pivot=CreatePivot();''''''''''''''''''this''''''''''''''''''''''''''''''''''''''''''''''''''
camera2=CreateCamera(camera2pivot);''''''''''is'''''''''''''''''''''''''''''''''''''''''''''''''''
CameraViewport camera2,50,50,200,200;''''''''my'''''''''''''''''''''''''''''''''''''''''''''''''''
PointEntity camera2,horizontal_camera_pivot;'effort'''''''''''''''''''''''''''''''''''''''''''''''

; 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,0,0.3,0
If KeyDown(key_a) Then TurnEntity stand,0,-0.3,0
If KeyDown(key_w) Then TurnEntity upperarm,0,0,0.3
If KeyDown(key_s) Then TurnEntity upperarm,0,0,-0.3
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

loc_x#=EntityX#(wrist):loc_y#=EntityY#(wrist):loc_z#=EntityZ#(wrist);'''''''''i tried this

PointEntity camera,horizontal_camera_pivot
PointEntity camera2,horizontal_camera_pivot;''''''''''''''''and this

PositionEntity camera2,loc_x#,loc_y#,loc_z#;'''''''''''''to position the camera



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


TartanTangerine (was Indiepath)(Posted 2003) [#2]
Why don't you parent the Camera to the Wrist.

For example :-

camera2pivot=CreatePivot(wrist)

You can delete :-
loc_x#=EntityX#(wrist):loc_y#=EntityY#(wrist):loc_z#=EntityZ#(wrist);'''''''''i tried this PositionEntity camera2,loc_x#,loc_y#,loc_z#;'''''''''''''to position the camera

Now the camera will always move with the wrist and point at the pivot.


shawnus(Posted 2003) [#3]
I shall certainly try this. Very kind of you to reply- thanks
Shawnus