Hi there, I need some input here. I'm having some trouble on calculationg some coords when making orbit rotations. I've made up a simple sketch just to point what I'm trying to do:
I got a planet which can have satellites. Each of them, rotates on its orbit.
Everything ok so far.
In this sketch, you can add satellites dynamically by pressing the mouse, so it calculates the rotation angle and the orbit size based on the planet and mouse coords.
This works, but since the satellite animation coords is based on
millis(), once it starts getting drawn, it starts from a random (well, not really random) point in the orbit.
What I want to achieve is that it starts its path right from the initial position provided by the mouse input, or the closer I can get. Any ideas on how can I handle this?
I'm trying to figure out this to apply it to another app I'm playing with, where I have particles that attract other particles and transform them into their satellites, but I made this sketch to keep it simple.
import processing.opengl.*;
Planet planet;
void setup(){
size(800, 600, OPENGL);
planet = new Planet(15, width/2, height/2, 0);
sphereDetail(4);
}
void draw(){
background(0);
frame.setTitle(int(frameRate) + " fps");
planet.display();
}
void mousePressed(){
planet.addSatellite();
}
class Planet{
float size, x, y, z;
ArrayList<Satellite> satellites;
Planet(float size, float x, float y, float z){
this.size = size;
this.x = x;
this.y = y;
this.z = z;
satellites = new ArrayList<Satellite>();
}
void display(){
pushMatrix();
translate(x,y,x);
fill(150); stroke(200);
sphere(size);
for (Iterator<Satellite> it = satellites.iterator(); it.hasNext(); ) {
orbitRad = dist(sx, sy, sz, parent.x, parent.y, parent.z)/4.3; //calculate the ortbit radius, based on the distance between planet coords (parent) and mouse coords. (WHY SHOULD I DIVIDE IT?)
//calculate the angle between the planet coords and mouse coords.
float dx = sx - parent.x;
float dy = sy - parent.y;
float ang = atan2(dy,dx);
if (ang < 0) ang += TWO_PI;
rotz = ang;
}
void display(){
//calculate coords
float ang = TWO_PI * millis()/orbitDuration*-1; //*-1 -> clockwise
x = cos(ang)*orbitRad;
y = 0;
z = sin(ang)*orbitRad;
//draw
pushMatrix();
rotateZ(rotz);
translate(x,y,z);
fill(75); stroke(125);
sphere(size);
popMatrix();
}
}
Note I'm calculating the orbit size (as I mentioned before) based on the distance between the mouse coords and the planet (parent)... but I had to divide it by 4 to get a closer result... not sure why.
Any help, suggestion or tip would be really appreciated.
I'm starting with opengl and, after playing with GLGraphics, I became interested on learning a bit more about opengl.
What I'm trying to do sounds simple, but I'm getting some trouble with textures.
I'm basically computing a subdivided icosahedron, which after 3 o 4 subdivisions looks like a sphere. Then, I'm drawing this model using VBOs. This part works OK... but when i try to get it textured, the results are terrible. I'm not sure if the problem is on how I'm calculating the tex coords or the opengl calls.
This is what i got so far. Any ideas?
import processing.opengl.*; //OPENGL
import javax.media.opengl.*; // USE OF OPENGL DIRECTLY
I've playing a bit with the amazing glgraphics lib, trying to learn how to handle models, lights and stuff.
This may sound noob/silly, but, when vertices are stored in its floatBuffer (model.vertices), it stores x,y,z and a 4th value.
Whats this 4th value and what does it stands for? (it's set 1.0 by default)
I'm playing with a sphere model (in fact, it's an icosahedron i subdivide to make it look like a sphere). After it is calculated, I want to "distort" some of its vertices to get some "peaks". I've been trying this by modifying a certain model's vert, but i'm not sure which value should be modified to achieve this.
This is a basic sketch of what i'd like to achieve. Any tips? Thanks in advance!
I've been playing with traer physics, glgraphics and toxiclibs for a couple days, terrific stuff!
I'm also getting my first steps into opengl and was reading about VBOs for performance improvements, which brought me here to read a couple posts about it. So, I need a little advice/tip regarding the use of VBOs:
As far as I understood, when using VBO I need to compute/store model vertices on setup, but I was wondering if this can be used 'on the fly'. For example, I'd like to create something simple:
- I have an object called customSphere, which computes a custom sphere from scratch storing its data on floatBuffers.
- I also have a particle system. Each time a certain event is called (i.e. mousePressed) a new particle is created, and it remains alive for a short time period.
- The thing is I'd like to create a 'customSphere' for each of these particles, being able to set/modify its size, polygon detail (subsdivision), texture mapping, polygon distortion, etc, since each particle would interact with the others.
So I was wondering...
Which is the best approach for doing this (performance oriented)? Should I have each object calculated when it's created? Should I have a pre-calculated buffer and then, when the object is created, copy this into new buffers? or maybe just do operations like translate/rotate for each particle using an original pre-calculated buffer?
Any help/suggestion/advice would be really apreciated. Thanks in advance!