yconst,
I`ve built an ellipse with the arc() function:
Code:arc(height/2,width/2,100,50,0,TWO_PI)
and combined it with the peasyCam to try out its functions. While rotating, I`ve noticed that the arc is flat
and one other thing that struck me. As I tried to draw not a complete ellipse, but a slice of it with the following:
Code:arc(height/2,width/2,100,50,[b]30,TWO_PI[/b])
absolutely nothing was drawn ??!? Maybe it`s just my maths, that`s bugging it ?
-------------------
Cedric,
your 3D sphere is perfect, but is there a way to also draw just a slice of it and not only full 360?
I have to basic approaches now:
FIRST ONE is my skatch + camera:
Code:
class Sphere {
float ringCenterX,ringCenterY;
float ringSizeX, ringSizeY;
float radius,angle, speed, slice;
float rotation;
int nRings, dRings;
color c;
float x,y;
Sphere(float xpos, float ypos, float radius, int nRings, int dRings, float slice)
{
this.ringCenterX = xpos;
this.ringCenterY = ypos;
this.radius = radius;
this.slice = slice;
this.nRings = nRings;
this.dRings = dRings;
}
void drawSphere()
{
for(int i=1; i<nRings; i++)
{
float phase = i*1./nRings;
ringCenterY = (sin(phase*PI+HALF_PI)*.5+.5)*radius;
ringSizeX = sin(phase*PI)*radius/2;
ringSizeY = ringSizeX/4;
drawRing();
}
}
void drawRing()
{
noStroke();
for(int i=0; i<dRings; i++)
{
float phase = i*slice/dRings-rotation;
x = ringCenterX + ringSizeX*cos(phase*TWO_PI);
y = ringCenterY + ringSizeY*sin(phase*TWO_PI);
fill(100*2, 100*2,100);
ellipse(x,y, 2,2);
}
//rotation += 0.01;
}
void rotateSphere(float speed)
{
rotation +=speed;
}
void moveSphere(float moveX, float moveY)
{
ringCenterX += moveX;
ringCenterY += moveY;
}
}
import peasy.*;
PeasyCam cam;
Sphere sp, sp1,sp2,sp3;
float rotation;
void setup()
{
size(700,500,P3D);
background(0);
cam = new PeasyCam(this, 600);
cam.setMinimumDistance(50);
cam.setMaximumDistance(500);
sp = new Sphere(400,100,180.0, 30, 70,.3);
sp1 = new Sphere(100,100,100.0, 20, 50, .7);
sp2 = new Sphere(200,100,100.0, 10, 100, .7);
sp3 = new Sphere(300,400,100.0, 100, 30, .7);
}
void draw()
{
background(0);
fill(0,100);
rect(0,0,height,width);
rotation = mouseX*1./width;
sp.drawSphere();
sp1.drawSphere();
sp2.drawSphere();
sp3.drawSphere();
sp.rotateSphere(0.02);
sp1.rotateSphere(-0.03);
sp2.rotateSphere(0.2);
sp3.rotateSphere(-0.07);
}
PROBLEM: FLAT, but sphere controll is agile --> sphere slice, angle, speed;
SECOND ONE : Cedric`s 3D Sphere + Camera:
Code:import peasy.*;
PeasyCam cam;
void setup() {
size(600,400,P3D);
smooth();
background(255);
cam = new PeasyCam(this, 600);
cam.setMinimumDistance(50);
cam.setMaximumDistance(500);
}
int radius = 100;
float rotation = 10;
float speed = 5;
void draw() {
//pushMatrix();
//noStroke();
//fill(200,50); --> I wanted to simulate the leaving trace through transparency, but I couldn't use translate?
//rect(0,0,width,height);
//translate(0.0,0.0,600.0,400.0); --> why cant I use translate here?
//popMatrix();
background(20);
stroke(150);
rotateY(radians(rotation));
for (int i = 1; i < 22; i++){
for (int j = 0; j < 22; j++){
pushMatrix();
strokeWeight(2);
stroke(100*j,100*i,100);
if(i==20){
strokeWeight(4);
stroke(255,0,0);
};
if(j==20){
strokeWeight(4);
stroke(255,0,255);
};
float cx = cos(i) * sin(j)*radius ;
float cy = cos(j)*radius;
float cz = sin(i) * sin(j)*radius;
point(cx,cy,cz);
popMatrix();
}
}
rotation+=speed;
}
Thank you gyus for your further help!