Browse Source

WIP Particles experimentation

RelativeDependencies
Macoy Madson 9 months ago
parent
commit
ef44f0fc62
  1. 29
      src/Ogre.cake
  2. 7
      src/OgreInitialize.cake
  3. 38
      test/data/Particles/TestParticles.particle
  4. 27
      test/src/VocalGame.cake

29
src/Ogre.cake

@ -16,7 +16,8 @@
"OgreSceneManager.h"
"OgreWindowEventUtilities.h"
"Animation/OgreSkeletonInstance.h"
"Animation/OgreSkeletonAnimation.h")
"Animation/OgreSkeletonAnimation.h"
"OgreParticleSystem.h")
;; Use Ogre's GLX window
;; TODO: convert these functions to cakelisp eventually
@ -169,6 +170,32 @@
(+ (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)
(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)
;; )
(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)))
(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))
;; e.g. (negate 1) outputs (-1)
(defgenerator negate (to-negate (index any))
(var negate-statement (const ([] CStatementOperation))

7
src/OgreInitialize.cake

@ -223,6 +223,13 @@
(call-on addResourceLocation resource-group-manager
"data/Materials/Textures" "FileSystem" "Textures")
(scope ;; Particles
(call-on addResourceLocation resource-group-manager
"data/Particles" "FileSystem" "Particles")
(call-on initialiseResourceGroup resource-group-manager "Particles"
true) ;; changeLocaleTemporarily: See comment above initialiseResourceGroup
(call-on loadResourceGroup resource-group-manager "Particles"))
(scope ;; Materials
;; I had to read https://forums.ogre3d.org/viewtopic.php?f=5&t=94769 before figuring out
;; groups needed to be initialized and loaded in order to work (at least, materials do)

38
test/data/Particles/TestParticles.particle

@ -0,0 +1,38 @@
// A sparkly purple fountain
particle_system TestParticles
{
/* material MonkeyFur */
particle_width 0.20
particle_height 0.20
// cull_each false
quota 500
/* billboard_type oriented_self */
// Area emitter
emitter Point
{
angle 0
emission_rate 90
time_to_live 3
direction 0 -1 0
velocity_min 0.1
velocity_max 0.1
colour_range_start 1 0 0
colour_range_end 0 0 1
}
// Gravity
affector LinearForce
{
force_vector -10 0 0
force_application average
}
// Fader
/* affector ColourFader */
/* { */
/* red -0.25 */
/* green -0.25 */
/* blue -0.25 */
/* } */
}

27
test/src/VocalGame.cake

@ -11,6 +11,18 @@
(c-import "SDL.h" "SDL_syswm.h" "SDL_timer.h"
"<math.h>" "<stdio.h>" "<string.h>")
(var g-window (* SDL_Window) null)
(var g-monkey-mesh mesh-handle)
(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-reload-sentinel int 2)
(var g-initialized bool false)
;; These are read and written to from different threads (currently, without locking)
(var g-audio-is-initialized bool false)
(var g-audio-is-recording bool false)
@ -323,17 +335,6 @@
(when (>= output-device 2) (SDL_CloseAudioDevice output-device))
(when (>= input-device 2) (SDL_CloseAudioDevice input-device)))
(var g-window (* SDL_Window) null)
(var g-monkey-mesh mesh-handle)
(var g-monkey-node scene-node)
(var g-monkey-anim-handle OgreAnimationHandle)
(var g-light-node scene-node)
(var g-reload-sentinel int 2)
(var g-initialized bool false)
(forward-declare (namespace Ogre
(class Root)
(class SceneManager)))
@ -413,6 +414,8 @@
(set g-light-node (ogre-create-light))
(set g-particle-node (ogre-create-particle-system))
(when g-ogre-root
(printf "Creating PBS spheres\n")
(ogreCreatePbsSpheres g-ogre-root (ogre-get-scene-manager))
@ -624,6 +627,8 @@
(when g-audio-is-recording
(set (vec-y final-pos) (+ (vec-y final-pos) -2.f)))
(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-animation-add-time g-monkey-anim-handle delta-time)

Loading…
Cancel
Save