Processing 迫使球体旋转
我正在制作一个简化太阳系的动画,并希望将旋转应用于太阳。这似乎是一项简单的任务,但不知何故它不会起作用。我尝试使用面向对象的范例来编写我的程序,因此每个行星、月亮和太阳都是天体类的对象。 我试着将Processing 迫使球体旋转,processing,Processing,我正在制作一个简化太阳系的动画,并希望将旋转应用于太阳。这似乎是一项简单的任务,但不知何故它不会起作用。我尝试使用面向对象的范例来编写我的程序,因此每个行星、月亮和太阳都是天体类的对象。 我试着将旋转(角度)行放在下面的CelestialBody类摘录中,如下所示: if(Type == 4){ emissive(255, 255, 255); pointLight(255, 255, 255, 0, 0, 0); //for the normal beh
旋转(角度)
行放在下面的CelestialBody类摘录中,如下所示:
if(Type == 4){
emissive(255, 255, 255);
pointLight(255, 255, 255, 0, 0, 0); //for the normal behaviour of the sun light
lightFalloff(0, 0, 0.00020); //light falls off right behind the surface of the sun
ambientLight(255, 255, 255, 0, 0, 0); //ambientLight in the center of the sun
rotate(angle);
}
可悲的是,它什么也没做。如何修复此问题并使太阳旋转,例如沿x轴旋转?
这是我的密码:
主文件:
import peasy.*; //<>//
PImage bg;
float angle = 0;
CelestialBody planet1;
CelestialBody planet2;
CelestialBody planet3;
CelestialBody planet4;
CelestialBody planet5;
CelestialBody sun;
PImage sunTexture;
PImage rocketTexture;
PShape rocket;
PeasyCam cam;
void setup() {
fullScreen(P3D);
bg = loadImage("background.jpg");
sunTexture = loadImage("sun.jpg");
cam = new PeasyCam(this, 1200);
rocket = loadShape("rocket.obj");
noStroke();
sun = new CelestialBody(70, 0, 0, 255, 200, 50, 4);//4 - type: sun
sun.planet.setTexture(sunTexture);
//noStroke();
//emissive(0, 0, 0);
planet1 = new CelestialBody(16, 150, 0.01, 150, 50, 255, 1);
planet1.spawnMoon(2);
planet2 = new CelestialBody(25, 300, 0.014, 50, 100, 255, 1);
planet2.spawnMoon(3);
planet3 = new CelestialBody(35, 450, -0.015, 255, 100, 40, 2);
planet3.spawnMoon(1);
planet4 = new CelestialBody(50, 650, 0.011, 50, 200, 255, 1);
planet4.spawnMoon(2);
planet5 = new CelestialBody(65, 900, -0.014, 0, 100, 0, 1);
planet5.planet = rocket;
planet5.planet.scale(0.9);
}
void makeOrbit(int a, int r){
for(int i=0; i<a; i++){
stroke(255, 10);
ellipse(height/2,width/2,r,r);
r-=180;
}
noStroke();
}
void draw() {
background(bg);
//lights();
noFill();
//translate(width/2, height/2);
stroke(#FFFFFF);
//ellipse(0,0,300,300);
//ellipse(0,0,600,600);
//ellipse(0,0,900,900);
//ellipse(0,0,planet4.distance,planet4.distance
// int z = 100;
//for (int i = 0; i<2; i++){
// z = -z;
// pointLight(255, 255, 255, -100, -100, z);
// pointLight(255, 255, 255, 100, -100, z);
// pointLight(255, 255, 255, 100, 100, z);
// pointLight(255, 255, 255, -100, 100, z);
//}
//emissive(255, 255, 255);
//pointLight(255, 255, 255, 0, 0, 0); //for the normal behaviour of the sun light
//lightFalloff(0, 0, 0.00025); //light falls off right behind the surface of the sun
//ambientLight(255, 255, 255, 0, 0, 0); //ambientLight in the center of the sun
sun.show();
planet1.show();
planet1.orbit();
planet2.show();
planet2.orbit();
planet3.show();
planet3.orbit();
planet4.show();
planet4.orbit();
planet5.show();
planet5.orbit();
}
导入豌豆。*////
皮马杰bg;
浮动角度=0;
天星体平面1;
天星体平面2;
天星体平面3;
天星体平面4;
天星体平面5;
天体太阳;
皮美奇太阳纹理;
PImage火箭结构;
形状火箭;
豌豆凸轮;
无效设置(){
全屏(P3D);
bg=loadImage(“background.jpg”);
sunTexture=loadImage(“sun.jpg”);
cam=新的PeasyCam(这是1200);
rocket=loadShape(“rocket.obj”);
仰泳();
sun=新天体(70,0,0,255,200,50,4);//4-类型:sun
太阳。行星。太阳纹理;
//仰泳();
//发射(0,0,0);
planet1=新天体(16150,0.01150,50255,1);
1号行星,2号卫星;
planet2=新天体(25300,0.014,50100255,1);
行星2.卫星(3);
planet3=新天体(35450,-0.015,255,100,40,2);
行星3.卫星(1);
planet4=新天体(50650,0.01150200255,1);
行星4.卫星(2);
planet5=新天体(65900,-0.014,01000,0,1);
行星=火箭;
行星5.行星比例尺(0.9);
}
void makeOrbit(int a,int r){
对于(int i=0;i这是什么语言?我在处理项目中使用Java。@Rager处理是一种编程语言(在JVM上运行)。这个问题已正确标记
class CelestialBody {
float radius;
float angle = random(TWO_PI);
float distance;
float orbitSpeed;
PShape planet;
CelestialBody[] moons;
int red;
int green;
int blue;
PVector v;
//PShape globe;
int Type;
CelestialBody(float _radius, float _distance, float _orbitSpeed, int _red, int _green, int _blue, int type) {
v = PVector.random3D();
radius = _radius;
distance = _distance;
v.mult(distance);
orbitSpeed = _orbitSpeed;
red = _red;
green = _green;
blue = _blue;
//stroke(red, green, blue);
fill(red, green, blue);
if(type == 1 || type == 4){
planet = createShape(SPHERE, _radius);
}
else if(type == 2){
planet = createShape(BOX, _radius);
}
Type = type;
}
void orbit() {
angle += orbitSpeed;
if (moons != null) {
for (int i = 0; i < moons.length; i++) {
moons[i].orbit();
}
}
}
void spawnMoon(int total){
moons = new CelestialBody[total];
for(int i = 0; i < moons.length; i++){
float r = radius / random(2,5);
float d = random((radius + r), (radius + r)*2);
float o = random(0.01, 0.05);
moons[i] = new CelestialBody(r, d, o, (int)random(0, 256), (int)random(0, 256), (int)random(0, 256), 1);
}
}
void show() {
pushMatrix();
PVector v2 = new PVector(1,0,1);
PVector p = v.cross(v2);
rotate(angle,p.x, p.y, p.z);
translate(v.x, v.y, v.z);
if(Type == 4){
emissive(255, 255, 255);
pointLight(255, 255, 255, 0, 0, 0); //for the normal behaviour of the sun light
lightFalloff(0, 0, 0.00020); //light falls off right behind the surface of the sun
ambientLight(255, 255, 255, 0, 0, 0); //ambientLight in the center of the sun
}
//shape(globe);
shape(planet);
if (moons != null) {
for (int i = 0; i < moons.length; i++) {
moons[i].show();
}
}
noStroke();
popMatrix();
}
}