January 15, 2021, 05:12:22 PM

Author Topic: [bb] 3d Puppet Experiment by Mr Snidesmin [ 1+ years ago ]  (Read 1422 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] 3d Puppet Experiment by Mr Snidesmin [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : 3d Puppet Experiment
Author : Mr Snidesmin
Posted : 1+ years ago

Description : A simple puppet model that can be controlled with keyboard and mouse...  with some nicer meshes for the parts I'm sure an interesting character could be made...

Code :
Code: BlitzBasic
  1. Graphics3D 800, 600, 0, 2
  2.  
  3. Type puppet
  4.         Field body
  5.         Field head
  6.         Field armL
  7.         Field armR
  8.         Field farmL
  9.         Field farmR
  10.        
  11.         Field bodyYaw#
  12.         Field bodyDeltaYaw#
  13.         Field headYaw#
  14.         Field headPitch#
  15.         Field headDeltaPitch#
  16.        
  17.         Field armLpitch#
  18.         Field armRpitch#
  19.        
  20.         Field armLyaw#
  21.         Field armRyaw#
  22.        
  23.         Field armRoll#
  24.         Field armRollTarget#
  25.        
  26.         Field armYaw#
  27.         Field armYawTarget#    
  28. End Type
  29.  
  30.  
  31. l = CreateLight(1)
  32. RotateEntity l, 45,0,0
  33.  
  34. Global pup.puppet = quickpuppet()
  35.  
  36. Global mainCamera = CreateCamera()
  37. PositionEntity mainCamera, 5, 2.5, -5
  38. PointEntity mainCamera, pupody
  39.  
  40. ;CameraClsColor mainCamera, 180, 170, 150
  41. CameraClsColor mainCamera, 50, 70, 120
  42.  
  43. Global lookAtCamera = False
  44.  
  45. Global livemode = True
  46.  
  47. HidePointer()  
  48. While Not KeyHit(1)
  49.         If KeyHit(28) Then     
  50.                 livemode = Not livemode
  51.                 If livemode Then
  52.                         MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
  53.                         FlushMouse()
  54.                         pupheadYaw = 0
  55.                         pupheadPitch = 0
  56.                         pupodyYaw = 0
  57.                         HidePointer()                  
  58.                 End If
  59.         End If
  60.  
  61.         mx# = MouseXSpeed()
  62.         my# = MouseYSpeed()
  63.         mz# = MouseZSpeed()
  64.        
  65.         If livemode Then
  66.                 MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
  67.         Else
  68.                 ShowPointer()
  69.         End If
  70.                
  71.         If KeyHit(59) Then puparmRollTarget = 0.0
  72.         If KeyHit(60) Then puparmRollTarget = 0.5
  73.         If KeyHit(61) Then puparmRollTarget = 1.0
  74.         If KeyHit(62) Then puparmRollTarget = 2.0
  75.        
  76.         If KeyHit(63) Then puparmYawTarget = 0.0
  77.         If KeyHit(64) Then puparmYawTarget = 0.5
  78.         If KeyHit(65) Then puparmYawTarget = 1.0
  79.         If KeyHit(66) Then puparmYawTarget = 2.0
  80.        
  81.         If (KeyHit(208)) Then
  82.                 lookAtCamera = Not lookAtCamera
  83.         End If
  84.        
  85.         If (KeyDown(200)) Then
  86.                 pupheadYaw = pupheadYaw + mx
  87.                 pupheadDeltaPitch = my
  88.         Else
  89.                 If lookAtCamera Then
  90.                         ;pupheadYaw = pupheadYaw * 0.9
  91.                         ;pupheadPitch = pupheadPitch * 0.9
  92.                         dx# = EntityX(mainCamera, True) - EntityX(puphead, True)
  93.                         dy# = EntityY(mainCamera, True) - EntityY(puphead, True)
  94.                         dz# = EntityZ(mainCamera, True) - EntityZ(puphead, True)
  95.                        
  96.                         AlignToVector puphead, dx, dy, dz, 1, 0.2
  97.                         pupheadYaw = EntityYaw(puphead)
  98.                         pupheadPitch = EntityRoll(puphead)
  99.                 End If
  100.                
  101.                 pupheadDeltaPitch = pupheadDeltaPitch - mz * 4
  102.                 pupheadDeltaPitch = pupheadDeltaPitch * 0.8
  103.                
  104.                 If Not MouseDown(1) Then
  105.                         puparmLpitch = puparmLpitch + my
  106.                         puparmLyaw = puparmLyaw + mx
  107.                 End If
  108.                 If Not MouseDown(2) Then
  109.                         puparmRpitch = puparmRpitch - my
  110.                         puparmRyaw = puparmRyaw - mx
  111.                 End If
  112.         End If
  113.        
  114.         puparmRoll = puparmRoll + 0.1 * (puparmRollTarget - puparmRoll)
  115.         puparmYaw = puparmYaw + 0.1 * (puparmYawTarget - puparmYaw)
  116.  
  117.        
  118.         If MouseDown(1) Then
  119.                 puparmLyaw = puparmLyaw * 0.9
  120.                 puparmLpitch = puparmLpitch * 0.9
  121.         End If
  122.         If MouseDown(2) Then
  123.                 puparmRyaw = puparmRyaw * 0.9
  124.                 puparmRpitch = puparmRpitch * 0.9      
  125.         End If
  126.  
  127.  
  128.         pupodyDeltaYaw = pupodyDeltaYaw * 0.9
  129.         pupodyDeltaYaw = pupodyDeltaYaw + 1.0 * (KeyDown(205) - KeyDown(203))
  130.         pupodyYaw = pupodyYaw + pupodyDeltaYaw
  131.         pupheadPitch = pupheadPitch - pupheadDeltaPitch
  132.        
  133.         minArmPitch# = 25
  134.         maxArmPitch# = 120
  135.        
  136.         minArmYaw# = 0
  137.         maxArmYaw# = 100
  138.        
  139.         ;Limits
  140.         If (puparmLPitch < -maxArmPitch) puparmLPitch = -maxArmPitch
  141.         If (puparmRPitch > maxArmPitch) puparmRPitch = maxArmPitch
  142.         If (puparmLPitch > minArmPitch) puparmLPitch = minArmPitch
  143.         If (puparmRPitch < -minArmPitch) puparmRPitch = -minArmPitch
  144.                
  145.         If (puparmLYaw < -maxArmYaw) puparmLYaw = -maxArmYaw
  146.         If (puparmRYaw > maxArmYaw) puparmRYaw = maxArmYaw
  147.         If (puparmLYaw > minArmYaw) puparmLYaw = minArmYaw
  148.         If (puparmRYaw < -minArmYaw) puparmRYaw = -minArmYaw
  149.        
  150.         ;limit to make sure arms do not cross
  151.         ;EntityColor pupfarmL, 255, 255, 255
  152.         ;EntityColor pupfarmR, 255, 255, 255
  153.        
  154.         critArmYaw# = 85
  155.         If (puparmRYaw > critArmYaw And puparmLYaw < -critArmYaw) Then
  156.                 dPitch# = puparmRPitch + puparmLPitch
  157.                 If Abs(dPitch) < 20 Then
  158.                         ;EntityColor pupfarmL, 255, 50, 50
  159.                         ;EntityColor pupfarmR, 255, 50, 50
  160.                        
  161.                         If (dPitch < 0) Then
  162.                                 puparmRPitch = puparmRPitch - 0.5
  163.                                 puparmLPitch = puparmLPitch - 0.5
  164.                                
  165.                                 puparmRYaw = puparmRYaw - 0.5
  166.                                 puparmLYaw = puparmLYaw - 0.5
  167.                         Else
  168.                                 puparmRPitch = puparmRPitch + 0.5
  169.                                 puparmLPitch = puparmLPitch + 0.5
  170.                                
  171.                                 puparmRYaw = puparmRYaw + 0.5
  172.                                 puparmLYaw = puparmLYaw + 0.5
  173.                         End If
  174.                 End If
  175.         End If
  176.        
  177.         maxHeadYaw# = 80
  178.         maxHeadPitch# = 50
  179.         minHeadPitch# = 30
  180.                
  181.         If (pupheadYaw < -maxHeadYaw) pupheadYaw = -maxHeadYaw
  182.         If (pupheadYaw > maxHeadYaw) pupheadYaw = maxHeadYaw
  183.        
  184.         If (pupheadPitch < -minHeadPitch) pupheadPitch = -minHeadPitch
  185.         If (pupheadPitch > maxHeadPitch) pupheadPitch = maxHeadPitch
  186.        
  187.        
  188.         RotateEntity pupody, 0, pupodyYaw, 0
  189.         RotateEntity puphead, 0, pupheadYaw, pupheadPitch
  190.         RotateEntity puparmL, puparmLPitch, puparmLyaw+40, -puparmLyaw * puparmRoll
  191.         RotateEntity puparmR, puparmRPitch, puparmRyaw-40, puparmRyaw * puparmRoll
  192.         RotateEntity pupfarmL, puparmLPitch, puparmLyaw*puparmYaw+20, 0
  193.         RotateEntity pupfarmR, puparmRPitch, puparmRyaw*puparmYaw-20, 0
  194.        
  195.         SetBuffer BackBuffer()
  196.         RenderWorld()
  197.         Color 255,100,0
  198.         y = GraphicsHeight() - 160
  199.         x = 10
  200.         dy = 16
  201.         Text x, y+0*dy, "F1-F4: Set arm roll extent"
  202.         Text x, y+1*dy, "F5-F8: Set arm yaw extent"
  203.         If (KeyDown(200)) Then
  204.                 Text x, y+2*dy, "Mouse X/Y: Look around"
  205.         Else
  206.                 Text x, y+2*dy, "Mouse X/Y: Move Arms"
  207.         End If
  208.         Text x, y+3*dy, "Mouse Wheel: Look up/down"
  209.         Text x, y+4*dy, "Mouse LB: Relax Left Arm"
  210.         Text x, y+5*dy, "Mouse RB: Relax Right Arm"    
  211.         Text x, y+6*dy, "Left+Right Arrows: Rotate"    
  212.         Text x, y+7*dy, "Down Arrow: Look at camera"   
  213.         Text x, y+8*dy, "Up Arrow: Switch to look mode"
  214.        
  215.         Flip
  216. Wend
  217. End
  218.  
  219.  
  220. Function quickpuppet.puppet()
  221.         p.puppet = New puppet
  222.         pody = CreateCube()
  223.         phead = CreateSphere(8, pody)
  224.        
  225.         ScaleMesh pody, 0.5, 1.4, 1
  226.         ScaleMesh phead, 0.8, 1, 0.7
  227.         PositionMesh phead, 0, 0.3, 0
  228.        
  229.         eye1 = CreateSphere(4, phead)
  230.         ScaleEntity eye1, 0.3, 0.3, 0.3
  231.         PositionEntity eye1, 0.55,0.3,-0.3
  232.         eye2 = CreateSphere(4, phead)
  233.         ScaleEntity eye2, 0.3, 0.3, 0.3
  234.         PositionEntity eye2, 0.55,0.3,0.3
  235.         PositionEntity phead, 0,2,0
  236.        
  237.         parmL = CreateCylinder(6, True, pody)
  238.         RotateMesh parmL, 90,0,0
  239.         FitMesh parmL, -0.3, -0.3, 0, 0.6, 0.6, 2.0
  240.         RotateMesh parmL, 45,0,0
  241.         PositionEntity parmL, 0, 1, 1
  242.                
  243.         parmR = CopyMesh(parmL, pody)
  244.         RotateMesh parmR, 0, 180, 0
  245.         PositionEntity parmR, 0, 1, -1
  246.                
  247.         pfarmL = CopyMesh(parmL, parmL)
  248.         PositionEntity pfarmL, 0, -1.5, 1.5
  249.         RotateMesh pfarmL, 20, 0, 30
  250.        
  251.         pfarmR = CopyMesh(parmR, parmR)
  252.         PositionEntity pfarmR, 0, -1.5, -1.5
  253.         RotateMesh pfarmR, -20, 10, 30
  254.        
  255.         parmRollTarget = 0.5
  256.         parmYawTarget = 1.0
  257.        
  258.         Return p
  259. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal