Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

advanced ragdoll works, but has a weird bug

  • Loading branch information...
commit 25b3aa0c96b9c8cd6f604898f1cc369bedb670ac 1 parent 1923adb
Jeremy Woertink authored October 29, 2012
2  .gitignore
@@ -10,3 +10,5 @@ tmtags
10 10
 Gemfile.lock
11 11
 *.gemspec
12 12
 assets/Interface/*.xml
  13
+*.jnilib
  14
+*.dylib
62  lib/samples/sample14a.rb
@@ -7,7 +7,11 @@ module ComJme3Animation
7 7
 #java_import "com.jme3.animation.*"
8 8
 java_import "com.jme3.app.SimpleApplication"
9 9
 java_import "com.jme3.asset.TextureKey"
  10
+java_import "com.jme3.scene.shape.Box"
  11
+java_import "com.jme3.animation.AnimControl"
  12
+java_import "com.jme3.animation.AnimChannel"
10 13
 java_import "com.jme3.bullet.BulletAppState"
  14
+java_import "com.jme3.light.AmbientLight"
11 15
 java_import "com.jme3.bullet.PhysicsSpace"
12 16
 java_import "com.jme3.bullet.collision.PhysicsCollisionEvent"
13 17
 java_import "com.jme3.bullet.collision.PhysicsCollisionObject"
@@ -41,17 +45,17 @@ class Sample14a < SimpleApplication
41 45
   field_reader :cam, :settings
42 46
   field_accessor :flyCam
43 47
   
44  
-  attr_accessor :bullet_app_state, :mat_bullet, :model, :ragdoll, :bullet_size, :mat, :mat2, :bullet, :bullet_collision_shape, :anim_channel
  48
+  attr_accessor :bullet_app_state, :mat_bullet, :model, :ragdoll, :bullet_size, :mat, :mat2, :bullet, :bullet_collision_shape, :anim_channel, 
  49
+  # Not sure about these...
  50
+  :elTime, :forward, :direction, :rotate, :dance
45 51
   
46 52
   def initialize
47 53
     self.bullet_size = 1.0
48  
-    # float elTime = 0;
49  
-    # boolean forward = true;
50  
-    # AnimControl animControl;
51  
-    # AnimChannel animChannel;
52  
-    # Vector3f direction = new Vector3f(0, 0, 1);
53  
-    # Quaternion rotate = new Quaternion().fromAngleAxis(FastMath.PI / 8, Vector3f.UNIT_Y);
54  
-    # boolean dance = true;
  54
+    self.elTime = 0
  55
+    self.forward = true
  56
+    self.direction = Vector3f.new(0, 0, 1)
  57
+    self.rotate = Quaternion.new.fromAngleAxis(FastMath::PI / 8, Vector3f::UNIT_Y)
  58
+    self.dance = true
55 59
   end
56 60
   
57 61
   def simpleInitApp
@@ -122,14 +126,28 @@ def init_cross_hairs
122 126
   
123 127
   def init_material
124 128
     self.mat_bullet = Material.new(asset_manager, "Common/MatDefs/Misc/Unshaded.j3md")
125  
-    key2 = TextureKey.new("Common/MatDefs/Misc/Unshaded.j3md")
  129
+    key2 = TextureKey.new("Textures/Terrain/Rock/Rock.PNG")
126 130
     key2.generate_mips = true
127 131
     tex2 = asset_manager.load_texture(key2)
128  
-    mat_bullet.set_texture("ColorMap", text2)
  132
+    mat_bullet.set_texture("ColorMap", tex2)
129 133
   end
130 134
   
131 135
   def init_world
  136
+    light = AmbientLight.new
  137
+    light.color = ColorRGBA::LightGray
  138
+    root_node.add_light(light)
132 139
     
  140
+    material = Material.new(asset_manager, File.join("Common", "MatDefs", "Misc", "Unshaded.j3md"))
  141
+    material.set_texture("ColorMap", asset_manager.load_texture(File.join("Interface", "Logo", "Monkey.jpg")))
  142
+    
  143
+    box = Box.new(Vector3f.new(0, -5, -5), 100, 0.2, 100)
  144
+    floor = Geometry.new("the Floor", box)
  145
+    floor.material = material
  146
+    floor.set_local_translation(0, -0.1, 0)
  147
+    floor_phy = RigidBodyControl.new(0.0)
  148
+    floor.add_control(floor_phy)
  149
+    root_node.attach_child(floor)
  150
+    bullet_app_state.physics_space.add(floor)
133 151
   end
134 152
   
135 153
   def setup_light
@@ -161,11 +179,27 @@ def setup_sinbad(sinbad)
161 179
     sinbad.add_bone_name("Clavicle.R")
162 180
   end
163 181
   
164  
-  def on_anim_cycle_done(control, channel, anim_name)
  182
+  def collide(bone, obj, event)
  183
+    if obj.user_object != nil && obj.user_object.is_a?(Geometry)
  184
+      geom = obj.user_object
  185
+      return if geom.name.eql?("Floor")
  186
+    end
  187
+    ragdoll.set_ragdoll_mode
  188
+  end
  189
+  
  190
+  # This method must be defined, but doesn't need to do anything
  191
+  def onAnimChange(control, channel, anim_name)
  192
+    Waves.echo("ANIMATION CHANGE", :cyan)
  193
+    Waves.echo("Control: #{control}", :yellow)
  194
+    Waves.echo("Channel: #{channel}", :yellow)
  195
+    Waves.echo("Name: #{anim_name}", :yellow)
  196
+  end
  197
+  
  198
+  def onAnimCycleDone(control, channel, anim_name)
165 199
     if channel.animation_name.eql?("StandUpBack") || channel.animation_name.eql?("StandUpFront")
166  
-      channel.loop_mode = LoopMode::DontLoop
  200
+      channel.loop_mode = ComJme3Animation::LoopMode::DontLoop
167 201
       channel.set_anim("IdleTop", 5)
168  
-      channel.loop_mode = LoopMode::Loop
  202
+      channel.loop_mode = ComJme3Animation::LoopMode::Loop
169 203
     end
170 204
   end
171 205
   
@@ -216,7 +250,7 @@ def on_action(name, is_pressed, tpf)
216 250
         bullet_node.ccd_motion_threshold = 0.001
217 251
         bullet_node.linear_velocity = @parent.cam.direction.mult(80)
218 252
         bulletg.add_control(bullet_node)
219  
-        root_node.attach_child(bulletg)
  253
+        @parent.root_node.attach_child(bulletg)
220 254
         @parent.bullet_app_state.physics_space.add(bullet_node)
221 255
       end
222 256
       if name.eql?("boom") && !is_pressed

0 notes on commit 25b3aa0

Please sign in to comment.
Something went wrong with that request. Please try again.