The physics system used in fluxus is based on the ode library, which allows you to add physical properties to objects and set them in motion. Since ODE is designed for rigid-body simulations, structures are described in terms of objects, joints and forces. A much more comprehensive explanation of these concepts can be found in the ODE documentation, which you have probably downloaded if you have compiled fluxus, or can be found at @url{http://ode.org/ode-docs.html} To help with debugging joints, try calling (render-physics) every frame, which will render locators showing you positions and axes of joints that have positional information.
Returns void
Enables or disables collision detection. Defaults to off.
Example
(collisions 1)
Returns void
Create an infinite passive plane for use as the 'ground'
Example
(ground-plane (vector 0 1 0) 0)
Returns void
Enable the object to be acted upon by the physics system, using a box as the bounding volume. As an active object, it will be transformed by ode. Note: rotations only work correctly if you specify your transforms scale first, then rotate (translate doesn't matter) basically, ode can't deal with shearing transforms.
Example
(define mycube (build-cube)) (active-box mycube)
Returns void
Enable the object to be acted upon by the physics system, using a cylinder as the bounding volume. As an active object, it will be transformed by ode. Note: rotations only work correctly if you specify your transforms scale first, then rotate (translate doesn't matter) basically, ode can't deal with shearing transforms.
Example
(define mycube (build-cube)) (active-cylinder mycube)
Returns void
Enable the object to be acted upon by the physics system, using a sphere as the bounding volume. As an active object, it will be transformed by ode. Note: rotations only work correctly if you specify your transforms scale first, then rotate (translate doesn't matter) basically, ode can't deal with shearing transforms.
Example
(define mycube (build-cube)) (active-sphere mycube)
Returns void
Enable the object to be acted upon by the physics system, using the mesh as the collision volume. This function only works on indexed, triangle-list poly primitives. As an active object, it will be transformed by ode. Note: rotations only work correctly if you specify your transforms scale first, then rotate (translate doesn't matter) basically, ode can't deal with shearing transforms.
Example
(define myshape (load-primitive "bot.obj")) (active-mesh myshape)
Returns void
Enable the object to be acted upon by the physics system, using a box as the bounding volume. As a passive object, active objects will collide with it, but it will not be transformed. Note: rotations only work correctly if you specify your transforms scale first, then rotate (translate doesn't matter) basically, ode can't deal with shearing transforms.
Example
(define mycube (build-cube)) (passive-box mycube)
Returns void
Enable the object to be acted upon by the physics system, using a cylinder as the bounding volume. As a passive object, active objects will collide with it, but it will not be transformed. Note: rotations only work correctly if you specify your transforms scale first, then rotate (translate doesn't matter) basically, ode can't deal with shearing transforms.
Example
(define mycube (build-cube)) (passive-cylinder mycube)
Returns void
Enable the object to be acted upon by the physics system, using a sphere as the bounding volume. As a passive object, active objects will collide with it, but it will not be transformed. Note: rotations only work correctly if you specify your transforms scale first, then rotate (translate doesn't matter) basically, ode can't deal with shearing transforms.
Example
(define mycube (build-cube)) (passive-sphere mycube)
Returns void
Enable the object to be acted upon by the physics system, using the mesh as the collision volume. This function only works on indexed, triangle-list poly primitives. As a passive object, active objects will collide with it, but it will not be transformed. Note: rotations only work correctly if you specify your transforms scale first, then rotate (translate doesn't matter) basically, ode can't deal with shearing transforms.
Example
(define myshape (load-primitive "bot.obj")) (passive-mesh myshape)
Returns void
Remove the object from the physics system.
Example
(define mycube (build-cube)) (active-box mycube) (physics-remove mycube)
Returns void
Sets some global surface attributes that affect friction and bouncyness. see section 7.3.7 of the ODE docs for an explanation of these parameters
Example
(surface-params 0.1 0.1 0.1 0.1)
Returns void
Creates a balljoint to connect two objects (see the ode docs for a detailed description of the differences between the joint types). ODE considers joints to be a constraint that is enforced between two objects. When creating a joint, it is important to have the two primitives being joined in the desired positions before creating the joint. Joints can be created, modified and indexed in a similar way to other primitives.
Example
(clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-balljoint shape1 shape2 (vector 0 0 0)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t)
Returns void
Creates a joint to connect an object to the global environment. This locks the object in place.
Example
(clear) (define shape1 (with-state (translate (vector 0 1 0)) (build-cube))) (active-box shape1) (build-fixedjoint shape1) ; not very exciting...
Returns hingeid-number
Creates a ball joint to connect two objects (see the ode docs for a detailed description of the differences between the joint types). ODE considers joints to be a constraint that is enforced between two objects. When creating a joint, it is important to have the two primitives being joined in the desired positions before creating the joint. Joints can be created, modified and indexed in a similar way to other primitives.
Example
(clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-hingejoint shape1 shape2 (vector 0 0 0) (vector 0 0 1)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t)
Returns hingeid-number
Creates a slider joint to connect two objects (see the ode docs for a detailed description of the differences between the joint types). ODE considers joints to be a constraint that is enforced between two objects. When creating a joint, it is important to have the two primitives being joined in the desired positions before creating the joint. Joints can be created, modified and indexed in a similar way to other primitives.
Example
(clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-sliderjoint shape1 shape2 (vector 1 0 0)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t)
Returns hingeid-number
Creates a hinge2 joint to connect two objects (see the ode docs for a detailed description of the differences between the joint types). ODE considers joints to be a constraint that is enforced between two objects. When creating a joint, it is important to have the two primitives being joined in the desired positions before creating the joint. Joints can be created, modified and indexed in a similar way to other primitives.
Example
(clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-hinge2joint shape1 shape2 (vector 0 0 0) (vector 1 0 0) (vector 0 1 0)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t)
Returns hingeid-number
Creates a angular motor joint to connect two objects (see the ode docs for a detailed description of the differences between the joint types). ODE considers joints to be a constraint that is enforced between two objects. When creating a joint, it is important to have the two primitives being joined in the desired positions before creating the joint. Joints can be created, modified and indexed in a similar way to other primitives.
Example
(clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-amotorjoint shape1 shape2 (vector 1 0 0)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t)
Returns hingeid-number
Sets the joint parameter for a joint where param is one of the following: "HiStop", "Vel", "FMax", "FudgeFactor", "Bounce", "CFM", "StopERP", "StopCFM","SuspensionERP", "SuspensionCFM", "Vel2", "FMax2". see section 7.5.1 of the ODE docs for an explanation of each of these parameters, and which joint types they apply to.
Example
(clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (define j (build-hinge2joint shape1 shape2 (vector 0 0 0) (vector 1 0 0) (vector 0 1 0))) (joint-param j "Vel2" 0.1) (joint-param j "FMax2" 0.2) (joint-param j "LoStop" -0.75) (joint-param j "HiStop" 0.75) (set-physics-debug #t)
Returns void
Set a new angle for this joint, with a given velocity taken to get there
Example
(clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (define j (build-hingejoint shape1 shape2 (vector 0 0 0) (vector 0 1 0))) (joint-param j "FMax" 20) (joint-param j "LoStop" -1) (joint-param j "HiStop" 1) (set-physics-debug #t) (define (animate) (joint-angle j 0.1 (* 5 (sin (time)))))
Returns void
Applies the given force in the slider's direction. That is, it applies a force with magnitude force, in the direction slider's axis, to body1, and with the same magnitude but opposite direction to body2.
Example
(clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (define j (build-sliderjoint shape1 shape2 (vector 1 0 0))) (joint-param j "FMax" 20) (joint-param j "LoStop" -1) (joint-param j "HiStop" 1) (set-physics-debug #t) (define (animate) (joint-slide j (* 5 (sin (time)))))
Returns void
Sets the maximum number of objects the physics system can deal with. When the max level has been reached the oldest objects are automatically destroyed.
Example
(clear) (set-max-physical 200) (every-frame (with-state (translate (vector 0 5 0)) (scale (srndvec)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2)))))
Returns void
Sets the mass of an active object
Example
(clear) (ground-plane (vector 0 1 0) 0) (collisions 1) (set-max-physical 20) ; not a great example, but these boxes will have ; different mass, so behave a bit differently. (every-frame (when (> (rndf) 0.92) (with-state (translate (vector 0 5 0)) (scale (vmul (rndvec) 5)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (set-mass ob (* (rndf) 10)) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2))))))
Returns void
Sets the strength and direction of gravity.
Example
(clear) (ground-plane (vector 0 1 0) 0) (collisions 1) (set-max-physical 20) (every-frame (begin (gravity (vector 0 (sin (time)) 0)) ; change gravity! :) (when (> (rndf) 0.92) (with-state (translate (vector 0 5 0)) (scale (rndvec)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2)))))))
Returns void
Applies translation force to the object
Example
(clear) (collisions 1) (set-max-physical 20) (gravity (vector 0 0 0)) (every-frame (when (> (rndf) 0.92) (with-state (scale (rndvec)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2))))))
Returns void
Applies rotational force to the object
Example
(clear) (collisions 1) (set-max-physical 20) (gravity (vector 0 0 0)) (every-frame (when (> (rndf) 0.92) (with-state (scale (rndvec)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2))))))
Returns void
Add force to body.
Example
(clear) (collisions 1) (for ([i (in-range 15)]) (let* ([p (vmul (srndvec) 15)] [c (with-state (translate p) (build-cube))]) (active-box c) (set-gravity-mode c #f) (add-force c (vmul p -10))))
Returns void
Add torque to body.
Example
(clear) (define c (build-cube)) (active-box c) (add-torque c #(10 0 0))
Returns void
Set whether the body is influenced by the world's gravity or not.
Example
(clear) (collisions 1) (define a (with-state (translate (vector -.95 5 0)) (build-cube))) (define b (build-cube)) (active-box a) (active-box b) (set-gravity-mode b #f)
Returns void
Returns true if the grabbed object collided in the last frame
Example
(clear) (ground-plane (vector 0 1 0) 0) (collisions 1) (set-max-physical 20) (define ob (with-state (translate (vector 0 5 0)) (build-cube))) (active-box ob) (every-frame (when (has-collided ob) (with-primitive ob (colour (rndvec)))))