oop-labs-collection/labs/3/renderSuite/Ray.java

41 lines
1.0 KiB
Java
Raw Normal View History

2023-04-27 14:23:46 +03:00
package renderSuite;
import java.lang.Math;
import renderSuite.Vec3;
public class Ray {
// position, facing
Vec3 p, f;
public Ray(Vec3 position, Vec3 facing) {
this.p = position;
this.f = facing;
}
public void main() {}
public void rotate(char axis, double angle) {
if (axis == 'x') {
this.f = new Vec3(this.f.x,
this.f.y*Math.cos(angle) - this.f.z*Math.sin(angle),
this.f.y*Math.sin(angle) + this.f.z*Math.cos(angle));
} else if (axis == 'y') {
this.f = new Vec3(this.f.x*Math.cos(angle) + this.f.z*Math.sin(angle),
this.f.y,
this.f.z*Math.cos(angle) - this.f.x*Math.sin(angle));
}
}
public void move(Vec3 mv) {
this.p.x += mv.x;
this.p.y += mv.y;
this.p.z += mv.z;
}
public void step(double l) {
this.p.x += this.f.x * l;
this.p.y += this.f.y * l;
this.p.z += this.f.z * l;
}
}