Browse Source

Got particles tracking pitch position

I encountered a strange audio problem where my input callback wasn't
being called at the desired frequency. I restarted and it went away.
RelativeDependencies
Macoy Madson 9 months ago
parent
commit
050afee420
  1. 80
      src/Ogre.cake
  2. 5
      test/src/VocalGame.cake

80
src/Ogre.cake

@ -17,7 +17,8 @@
"OgreWindowEventUtilities.h"
"Animation/OgreSkeletonInstance.h"
"Animation/OgreSkeletonAnimation.h"
"OgreParticleSystem.h")
"OgreParticleSystem.h"
"OgreParticleEmitter.h")
;; Use Ogre's GLX window
;; TODO: convert these functions to cakelisp eventually
@ -47,7 +48,8 @@
(namespace Ogre
(class Item)
(class SceneNode)
(class SkeletonAnimation)))
(class SkeletonAnimation)
(class ParticleSystem)))
;; The client of this API should not need access the internals of this structure
(defstruct mesh-handle
@ -123,8 +125,8 @@
(when root-scene-node
;; WTF - this should work, but it's almost like the root scene node's vtable is wrong
;; Ogre::SceneNode* sceneNode = root-scene-node->createChildSceneNode(Ogre::SCENE_DYNAMIC);
(var scene-node (* Ogre::SceneNode)
(type-cast (call-on-ptr createChild root-scene-node) (* Ogre::SceneNode)))
(var-cast-to scene-node (* Ogre::SceneNode)
(call-on-ptr createChild root-scene-node))
(when scene-node
(call-on-ptr attachObject scene-node (field mesh-handle mesh-item))
(set (field new-scene-node node) scene-node)))
@ -155,9 +157,9 @@
(var root-scene-node (* Ogre::SceneNode) (call-on-ptr getRootSceneNode scene-manager))
(when root-scene-node
(var light (* (in Ogre Light)) (call-on-ptr createLight scene-manager))
(var light-node (* (in Ogre SceneNode))
;; Required cast for VTable weirdness (See "WTF" comment)
(type-cast (call-on-ptr createChild root-scene-node) (* Ogre::SceneNode)))
;; Required cast for VTable weirdness (See "WTF" comment)
(var-cast-to light-node (* (in Ogre SceneNode))
(call-on-ptr createChild root-scene-node))
(set (field new-light-node node) light-node)
(call-on-ptr attachObject light-node light)
(call-on-ptr setPowerScale light 1.0f)
@ -170,31 +172,61 @@
(+ (negate (call-on-ptr getDirection light)) (* (in Ogre Vector3 UNIT_Y) 0.2f))))
(return new-light-node))
(defun ogre-create-particle-system (&return scene-node)
(defstruct particle-system-handle
node scene-node
particle-system (* (in Ogre ParticleSystem)))
(defun ogre-create-particle-system (&return particle-system-handle)
(var scene-manager (* (in Ogre SceneManager)) (ogre-get-scene-manager))
(var particle-system (* (in Ogre ParticleSystem))
(call-on-ptr createParticleSystem scene-manager "TestParticles"))
;; Not so good because it requires accessing things in ParticleFX, which is a problem when dynamically linking
;; (scope ;; Set up particle system
;; (call-on-ptr setDefaultDimensions particle-system 0.25f 0.25f)
;; (var emitter (* (in Ogre PointEmitter))
;; (type-cast (call-on-ptr addEmitter particle-system "Point") (* (in Ogre PointEmitter))))
;; ;; (var affector (* (in Ogre ParticleAffector))
;; ;; (call-on-ptr addAffector particle-system "LinearForce"))
;; ;; (var force-vector (in Ogre Vector3) (array -0.1f 0.f 0.f))
;; ;; (call-on-ptr setForceVector affector force-vector)
;; )
;; Use StringInterface::setParameter to set things up without their types
;; (scope ;; Set up particle system
;; (call-on-ptr setDefaultDimensions particle-system 0.25f 0.25f)
;; (var-cast-to emitter (* (in Ogre PointEmitter))
;; (call-on-ptr addEmitter particle-system "Point"))
;; ;; (var affector (* (in Ogre ParticleAffector))
;; ;; (call-on-ptr addAffector particle-system "LinearForce"))
;; ;; (var force-vector (in Ogre Vector3) (array -0.1f 0.f 0.f))
;; ;; (call-on-ptr setForceVector affector force-vector)
;; )
;; (when (> (call-on-ptr getNumEmitters particle-system) 0)
;; (var particle-emitter (* (in Ogre ParticleEmitter))
;; (call-on-ptr getEmitter particle-system 0))
;; (call-on-ptr setPosition particle-emitter (array 0.f -1.f 0.f)))
(var root-scene-node (* Ogre::SceneNode) (call-on-ptr getRootSceneNode scene-manager))
(var particle-system-node (* (in Ogre SceneNode))
;; Required cast for VTable weirdness (See "WTF" comment)
(type-cast (call-on-ptr createChild root-scene-node) (* Ogre::SceneNode)))
;; Required cast for VTable weirdness (See "WTF" comment)
(var-cast-to particle-system-node (* (in Ogre SceneNode))
(call-on-ptr createChild root-scene-node))
(call-on-ptr attachObject particle-system-node particle-system)
(var new-particle-system-node scene-node (array null))
(set (field new-particle-system-node node) particle-system-node)
(return new-particle-system-node))
(var new-particle-system-contained particle-system-handle (array null))
(set (field new-particle-system-contained node node) particle-system-node)
(set (field new-particle-system-contained particle-system) particle-system)
(return new-particle-system-contained))
(defun ogre-particle-emitter-set-position (particle-handle (* particle-system-handle)
x float y float z float)
;; TODO Fragile: we don't have guarantees this is the right attachment
;; TODO: Why doesn't this work?
(var particle-system (* (in Ogre ParticleSystem))
(path particle-handle > particle-system))
(when (> (call-on-ptr getNumEmitters particle-system) 0)
(var particle-emitter (* (in Ogre ParticleEmitter))
(call-on-ptr getEmitter particle-system 0))
(call-on-ptr setPosition particle-emitter (array x y z))))
(defmacro var-cast-to (var-name symbol type any expression-to-cast any)
(tokenize-push
output
(var (token-splice var-name) (token-splice type)
(type-cast (token-splice expression-to-cast)
(token-splice type))))
(return true))
;; e.g. (negate 1) outputs (-1)
(defgenerator negate (to-negate (index any))

5
test/src/VocalGame.cake

@ -17,7 +17,7 @@
(var g-monkey-node scene-node)
(var g-monkey-anim-handle OgreAnimationHandle)
(var g-light-node scene-node)
(var g-particle-node scene-node)
(var g-pitch-particles particle-system-handle)
(var g-reload-sentinel int 2)
@ -414,7 +414,7 @@
(set g-light-node (ogre-create-light))
(set g-particle-node (ogre-create-particle-system))
(set g-pitch-particles (ogre-create-particle-system))
(when g-ogre-root
(printf "Creating PBS spheres\n")
@ -629,6 +629,7 @@
(ogre-node-set-position (addr g-monkey-node) (vec-xyz final-pos))
;; This moves the entire particle system, not the emitter
;; (ogre-node-set-position (addr g-particle-node) (vec-xyz final-pos))
(ogre-particle-emitter-set-position (addr g-pitch-particles) (vec-xyz final-pos))
(ogre-animation-add-time g-monkey-anim-handle delta-time)

Loading…
Cancel
Save