Code Monkey home page Code Monkey logo

ofxtraerphysics's Introduction

ofxTraerPhysics 3.0.2

Adaption from libcinder version of Traer Physics to dependencies less openframeworks version.

Introduction

Creates a easy to setup Particle System which can create particles and particle-to-particle forces. Original in Java but very popular for Processing, so many of you might used it with Processing.

Licence

Licensed under the same "do whatever you want just email Jeff" license as the Java/Processing version.

See http://murderandcreate.com/physics/ for the original Java code and examples.

See also https://github.com/bloomtime/CinderTraer for the c++ port this was based upon for cinder.

Installation

Just drop the folder into the openFrameworks/addons/ folder. Or git clone. After you have done that I've made it easier to just include the ofxTraerPhysics.h which includes all the necessary headers.

Dependencies

none

Compatibility

0.9.3

Known issues

Issue with jumpy particles & attractors have been solved via e-mail from [names left out] thank you!

Version history

Version 3.0.2 (Date): 2017-03-07

Bug update Version 3.0.1 (Date): 2013-02-25 Initial release w/ openframeworks version 0.7.4

ofxtraerphysics's People

Contributors

martinlindelof avatar

Stargazers

 avatar Alexander Green avatar ecco screen avatar Daito Manabe avatar Brett Renfer avatar Decohero avatar Johan Bichel Lindegaard avatar Tom Andreas Nærland avatar Tim Pulver avatar Studio Ijeoma avatar christian parsons avatar  avatar Akira Hayasaka avatar

Watchers

 avatar

Forkers

oampo

ofxtraerphysics's Issues

Bug in Attraction class

There's a bug in Attraction::apply()

if ( !a->fixed )a->force -= ofVec3f( -a2bX, -a2bY, -a2bZ );
should be
if ( !a->fixed )a->force += ofVec3f( -a2bX, -a2bY, -a2bZ );

This causes particle attractions to be highly unstable.

wrong math inside attraction class

Hi,

I found some issues with the math inside the attraction class. While porting some code from processing I notice that the springs were a behaving in a strange way. So by comparing attraction class from the processing library with yours I changed the apply() function to the following:

void Attraction::apply()
{
if ( on && ( !a->fixed || !b->fixed ) )
{

            float a2bX = a->position.x - b->position.x;
            float a2bY = a->position.y - b->position.y;
            float a2bZ = a->position.z - b->position.z;


            float a2bDistanceSquared = a2bX*a2bX + a2bY*a2bY + a2bZ*a2bZ;

            if ( a2bDistanceSquared < distanceMinSquared )
                a2bDistanceSquared = distanceMinSquared;

            float force = k * a->mass * b->mass / a2bDistanceSquared;

            float length = (float)sqrt( a2bDistanceSquared );

            // make unit vector

            a2bX /= length;
            a2bY /= length;
            a2bZ /= length;

            // multiply by force

            a2bX *= force;
            a2bY *= force;
            a2bZ *= force;

            // apply

            if ( !a->fixed )a->force -= ofVec3f( -a2bX, -a2bY, -a2bZ );
            if ( !b->fixed )b->force += ofVec3f( a2bX, a2bY, a2bZ );

        }
    }

Now springs behave like a charm :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.