We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Basic Ribbon Trails? (Read 1236 times)
Basic Ribbon Trails?
Apr 19th, 2008, 2:21pm
 
Hello there, I'm trying to get some basic ribbon trails that follow these particles that I have moving about - i'm using the Traer Physics library for that by the way.

I'm guessing I need to utilise an array to store the x,y,z positions of the particles and then use vertex shape (set to QUAD_STRIP) to draw the ribbon.

I've built a small example (in 2D) thats stores x,y values in an array based on mouse position (stepping through it and updating), but i'm not sure what sort of values to give the vertices within beginShape and endShape in order to get a long trail (rather than a big square or something).

Are there any examples or code snippets or tips out there for a newbie to work from? Flight404 posted the particle emitter source examples that has some sort of trail but this is too clever for my birdbrain(!), firstly because it uses full gl vertex and seems to interact with the camera (so that it is always facing it i think). Any help is greatly appreciated.
Re: Basic Ribbon Trails?
Reply #1 - Apr 19th, 2008, 2:31pm
 
Why not just have the ribbons made of springs?

I did this with a physics example I made up myself:

http://www.robotacid.com/PBeta/physics_01/index.html

Though traer physics also has springs that are a lot more realistic than mine, so you could make them more taut.
Re: Basic Ribbon Trails?
Reply #2 - Apr 19th, 2008, 6:54pm
 
Here you go bro. As you asked i kept all the more complex stuff out. You'll need to have the java vecmath library to run it, check out my previous post on applying a matrix to a vector for installation instructions. I haven't documented it yet but if you have any questions just ask.

import javax.vecmath.*;
import processing.opengl.*;

int count = 30;
float Width = 30;
Point3f[] pos= new Point3f[count];
Vector3f[] vel= new Vector3f[count];
Vector3f[] acl= new Vector3f[count];
Point3f anchor;

void setup(){
 size(600,600,OPENGL);
 hint( ENABLE_OPENGL_4X_SMOOTH );
 for (int i=0; i< count; i++){
   pos[i] = new Point3f();
   vel[i] = new Vector3f();
   acl[i] = new Vector3f();
 }
}

void draw(){
 background(0);
 anchor= new Point3f(mouseX,mouseY,0);
 beginShape(QUAD_STRIP);
 for (int i=0; i<count; i++ ){
   if (i==0){
     vel[i].sub(anchor,pos[i]);
   }
   else{
     vel[i].sub(pos[i-1],(pos[i]));
   }
   vel[i].scale(.08*(.1*(i+1)));
   acl[i].add(vel[i]);
   pos[i].add(acl[i]);
   fill(255,0,0,100);
   vertex(pos[i].x,pos[i].y,pos[i].z);
   vertex(pos[i].x+Width,pos[i].y+Width,pos[i].z);
   acl[i].scale(.95-(.02*i));
 }
 endShape();
}


Re: Basic Ribbon Trails?
Reply #3 - Apr 19th, 2008, 6:55pm
 
Springs seem to have an effect on the movement of the particles though. Plus you need to double the number of particles.

All i'm confused with the vertex method is what sort of co-ords to give each vertex line and how to get that from an array(s) that stores the position of all the particles.
Re: Basic Ribbon Trails?
Reply #4 - Apr 19th, 2008, 7:01pm
 
Oh wow! Thankyou!

I think I could develop something from that snippet - exactly the kind of thing I was after.

As mentioned in my previous post it was creating and accessing various arrays and how to feed that to vertices that had me confused.

I'll report back here once I have a bit of time to examine this... thanks.
Re: Basic Ribbon Trails?
Reply #5 - Apr 19th, 2008, 7:08pm
 
if you don't like the springing remove the acl (acceleration)
and change
pos[i].add(acl[i]);
to
pos[i].add(vel[i]);

you'll have to change the dampening values to compensate.  The basic idea is that you derive the current position of the current particle from the previous particle in the array and then offset it by a given amount along a vector.  You create a vector using:
vector= target position - current position.
Page Index Toggle Pages: 1