Permalink
Browse files

Fixed sample4. box is now movable. added blank sample5

  • Loading branch information...
1 parent 110ed6b commit 73db923671033f7919912b538a620638ba58d0ef @jwoertink committed Sep 22, 2011
Showing with 89 additions and 44 deletions.
  1. +74 −44 lib/sample4.rb
  2. +15 −0 lib/sample5.rb
  3. BIN libbulletjme.jnilib
View
@@ -1,3 +1,9 @@
+=begin
+ This shows a normal blue box with fire coming out of the top. The camera can be moved like normal,
+ but in this sample, the box can be moved left with "J" and right with "K" and rotated with space.
+=end
+
+
java_import "com.jme3.app.SimpleApplication"
java_import "com.jme3.material.Material"
java_import "com.jme3.math.Vector3f"
@@ -10,21 +16,46 @@
java_import "com.jme3.input.controls.AnalogListener"
java_import "com.jme3.input.controls.KeyTrigger"
java_import "com.jme3.input.controls.MouseButtonTrigger"
+java_import "com.jme3.effect.ParticleEmitter"
+java_import "com.jme3.effect.ParticleMesh"
class Sample4 < SimpleApplication
+ field_accessor :speed
+ field_accessor :paused
+
+ class << self
+ attr_accessor :running
+ end
def initialize
- @root_node = root_node
- @is_running = true
+ $player = nil # I'm ashamed of this....
+ self.class.running = true
end
def simpleInitApp
b = Box.new(Vector3f::ZERO, 1, 1, 1)
- @player = Geometry.new("Player", b)
+ $player = Geometry.new("Player", b)
mat = Material.new(asset_manager, File.join("Common", "MatDefs", "Misc", "Unshaded.j3md"))
mat.set_color("Color", ColorRGBA::Blue)
- @player.material = mat
- root_node.attach_child(@player)
+ $player.material = mat
+ root_node.attach_child($player)
+ fire = ParticleEmitter.new("Emitter", ParticleMesh::Type::Triangle, 30)
+ mat_red = Material.new(asset_manager, File.join("Common", "MatDefs", "Misc", "Particle.j3md"))
+ mat_red.set_texture("Texture", asset_manager.load_texture(File.join("Effects", "Explosion", "flame.png")))
+ fire.material = mat_red
+ fire.images_x = 2
+ fire.images_y = 2
+ fire.end_color = ColorRGBA.new(1.0, 0.0, 0.0, 1.0)
+ fire.start_color = ColorRGBA.new(1.0, 1.0, 0.0, 0.5)
+ fire.initial_velocity = Vector3f.new(0, 2, 0)
+ fire.start_size = 0.6
+ fire.end_size = 0.1
+ fire.gravity = 0
+ fire.low_life = 0.5
+ fire.high_life = 3.0
+ fire.velocity_variation = 0.3
+ fire
+ root_node.attach_child(fire)
initKeys
end
@@ -34,48 +65,47 @@ def initKeys
input_manager.add_mapping("Right", KeyTrigger.new(KeyInput::KEY_K))
input_manager.add_mapping("Rotate", KeyTrigger.new(KeyInput::KEY_SPACE), MouseButtonTrigger.new(MouseInput::BUTTON_LEFT))
- input_manager.add_listener(action_listener, ["Pause"].to_java(:string))
- input_manager.add_listener(analog_listener, ["Left", "Right", "Rotate"].to_java(:string))
+ input_manager.add_listener(ControllerAction.new(self), ["Pause"].to_java(:string))
+ input_manager.add_listener(ControllerAnalog.new(self), ["Left", "Right", "Rotate"].to_java(:string))
end
+
+ class ControllerAction
+ include ActionListener
- def action_listener
- Class.new {
- include ActionListener
- def on_action(name, key_pressed, time_per_frame)
- if name.eql?("Pause") && !key_pressed
- @is_running = !@is_running
- end
- end
- }.new
+ def initialize(parent)
+ @parent = parent
end
- def analog_listener
- Class.new {
- include AnalogListener
-
- def initialize
- @player = @root_node.get_child("Player")
- end
-
- def on_analog(name, value, time_per_frame)
- puts "running analog #{name}"
- puts "player: #{@player.inspect}"
- if @is_running
- case name
- when "Rotate"
- @player.rotate(0, value * speed, 0)
- when "Right"
- v = @player.local_translation
- @player.set_local_translation(v.x + value * speed, v.y, v.z)
- when "Left"
- v = @player.local_translation
- @player.set_local_translation(v.x - value * speed, v.y, v.z)
- else
- puts "Press P to unpause."
- end
- end
- end
- }.new
+ def on_action(name, key_pressed, time_per_frame)
+ if name.eql?("Pause") && !key_pressed
+ Sample4.running = !Sample4.running
+ end
end
+ end
-end
+ class ControllerAnalog
+ include AnalogListener
+
+ def initialize(parent)
+ @parent = parent
+ end
+
+ def on_analog(name, value, time_per_frame)
+ if Sample4.running
+ case name
+ when "Rotate"
+ $player.rotate(0, value * @parent.speed, 0)
+ when "Right"
+ v = $player.local_translation
+ $player.set_local_translation(v.x + value * @parent.speed, v.y, v.z)
+ when "Left"
+ v = $player.local_translation
+ $player.set_local_translation(v.x - value * @parent.speed, v.y, v.z)
+ else
+ puts "Press P to unpause."
+ end
+ end
+ end
+ end
+
+end
View
@@ -0,0 +1,15 @@
+java_import "com.jme3.app.SimpleApplication"
+java_import "com.jme3.material.Material"
+java_import "com.jme3.math.Vector3f"
+java_import "com.jme3.math.ColorRGBA"
+java_import "com.jme3.effect.ParticleEmitter"
+java_import "com.jme3.effect.ParticleMesh"
+
+
+class Sample5 < SimpleApplication
+
+ def simpleInitApp
+
+ end
+
+end
View
Binary file not shown.

0 comments on commit 73db923

Please sign in to comment.