Help With Spheres and Rotation
in
Programming Questions
•
1 year ago
Hello all I was wondering if anyone can help me with the following code I have created:
Here is the main tab of the sketch..............................................................................................................
Rotating myRotating; //declaring an object here.
void setup(){
size(700,700,P3D); //size of window with P3D initialized.
background(255,0,0); //color of background.
}
void draw(){
translate(width/2,height/2); //this is moving the point of origin to the center of the screen.
myRotating = new Rotating(); //creating a new object here called myRotating.
myRotating.display(); //function of displaying the myRotating.
myRotating.rotation(); //calling the function rotation.
}
-----------------------------------------------------------------------------------------------------------------------------------
Here is my Rotating class I have created------------------------------------------------------------------------
class Rotating{ //class created. ---------------------------------------------This is the data portion of the class.
color c; //color variable created; calling it "c".
float xpos; //float xpos is created.
float ypos; //float ypos is created.
float xspeed; //float xspeed is created.
Rotating(){ // creating the constructor for the class--------------------------This is the constructor of the class.
c = color(255); // c is assigned the color of white.
xpos = 100; //xpos is assigned the width/2 of my screen window.
ypos = height/2; //ypos is assigned the height/2 of my screen window.
xspeed = 10; // xspeed is assigned the value of 1.
}
void display(){ //the function "display" is created.-------------------------------------------------------functionality of the class begins.
ellipseMode(CENTER); //ellipseMode is created and centered.
fill(c); //the fill of the Sphere I have is called through "c" which is assigned the color of white for now.
sphere(200); //the actual sphere is created.
}
void rotation(){ //this is the other function I have created for the class Rotating. -------------------------------Second function of the functionality of the class begins.
xpos = xpos + xspeed; //xpos is being set equal to xpos plus xspeed. Essentially width/2 = width/2 + 1.
if(xpos>width){ //if statement saying if xpos(701) is greater than width(700) then xpos equals 0. This means that the sphere will be drawn from the top left of the screen.
xpos = 705; //xpos being declared 0.
}
}
}
-----------------------------------------------------------------------------------------------------------------
For ease of reading I have highlighted my code. I was wondering if anyone could help me rotate this sphere? I feel like I am so close I just need so guidance. My code is for a demo on Perlin Noise and I am trying to texture map an image of noise I have created onto the sphere to show how procedural texture mapping works. I just haven't gotten to that part yet because I am trying to get my sphere to rotate first. Thanks everyone.
1