Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package raytrace;
- import processing.core.PApplet;
- public class Raytrace extends PApplet {
- public static void main(String[] args) {
- }
- double yaw = Math.PI*-0.25;
- double pitch = Math.PI*-0.1875;
- double x;
- double y;
- double z;
- double d;
- int screenX;
- int screenY;
- int shade;
- int cont = 0;
- double distance;
- double xv;
- double yv;
- double zv;
- int frames = 0;
- double trueYaw = Math.PI*0.1;
- double truePitch = Math.PI*0.5;
- double collisionAccuracy = 0.1;
- int oldY;
- //boolean isTouching;
- int r;
- int g;
- int b;
- double plus = 0;
- int shadowY;
- public boolean check(double X, double Y, double Z) {
- //isTouching = false;
- r= 0;
- g = 0;
- b = 0;
- //System.out.println(Y);
- if (Z > 20 && Z < 30 && X > -5 && X < 5 && Y > -5 && Y < 5) {
- //System.out.println("blue");
- r = 0;
- g = 0;
- b = 1;
- //System.out.println("true");
- return true;
- }
- //System.out.println(Y);
- if (Y < -50) {
- //System.out.println("red");
- r = 1;
- g = 0;
- b = 0;
- return true;
- }
- return false;
- /* if ((Math.sqrt(Math.sin(yaw)*Math.sin(yaw)+Math.sin(pitch)*Math.sin(pitch)+Math.cos(yaw)-20*Math.cos(yaw+Math.sin(pitch)-20*Math.cos(yaw+Math.sin(pitch))))) < 5) {
- //System.out.println("green");
- r = 0;
- g = 1;
- b = 0;
- isTouching = true;
- */
- }
- public void cast(double YAW, double PITCH) {
- //yaw = 0;
- //pitch = 0;
- //speed = speed + 1;
- //System.out.println(speed);
- cont = 0;
- x = -5;
- y = 15;
- z = 25;
- //System.out.println(Math.sqrt(Math.sin(yaw)*Math.sin(yaw)+Math.sin(pitch)*Math.sin(pitch)+Math.cos(yaw)*Math.cos(yaw+Math.sin(pitch)*Math.cos(yaw+Math.sin(pitch)))));
- /*
- xv = (Math.sin(YAW)*collisionAccuracy);
- yv = (Math.sin(PITCH)*collisionAccuracy*(Math.cos(YAW-Math.PI*trueYaw)));
- zv = (Math.cos(YAW)*collisionAccuracy);
- */
- xv = (Math.sin(YAW)*collisionAccuracy)*Math.cos(PITCH);
- yv = (Math.sin(PITCH)*collisionAccuracy);
- zv = (Math.cos(YAW)*collisionAccuracy)*Math.cos(PITCH);
- distance = 0;
- do {
- x = x + xv;
- y = y + yv;
- z = z + zv;
- distance = distance + collisionAccuracy;
- //System.out.println("x " + x + "y " + y + "z " + z);
- ;
- if (check(x, y, z)) {
- oldY = (int)y;
- cont = 1;
- shadowY = 500;
- do {
- shadowY = shadowY - 1;
- } while (!check(x, shadowY, z));
- if ((oldY-1) < shadowY && (oldY+1) > shadowY ) {
- fill (r*255,g*255,b*255);
- }else{
- fill (r*100,g*100,b*100);
- }
- //cont = 1;
- //System.out.println("DETECTED CUBE");
- }
- if (distance > 200 && cont == 0) {
- fill (0, 0, 0);
- cont = 1;
- }
- } while (cont == 0);
- }
- public void setup() {
- size(1200,900);
- screenX = 0;
- screenY = 0;
- }
- public void draw() {
- background(255);
- noStroke();
- screenX = 0;
- screenY = 900;
- pitch = Math.PI*-0.1875+Math.PI*truePitch;
- yaw = Math.PI*-0.25+Math.PI*trueYaw;
- //plus = plus + 0.1;
- //yaw = yaw + plus;
- do {
- do {
- yaw = yaw + ((Math.PI*0.5)/1200);
- //System.out.println("screenX" + screenX);
- screenX = screenX + 1;
- cast(yaw, pitch);
- rect(screenX,screenY,1,1);
- } while(screenX < 1200);
- //System.out.println("screenY" + screenY);
- screenY = screenY - 1;
- pitch = pitch + ((Math.PI*0.375)/900);
- yaw = Math.PI*-0.25+Math.PI*trueYaw + plus;
- screenX = 0;
- cast(yaw, pitch);
- rect(screenX,screenY,1,1);
- } while(screenY > 0);
- frames = frames + 1;
- System.out.println(frames);
- }
- }
- //Math.PI*0.25 Math.PI*0.1875
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement