Loading...
Logo
Processing Forum

New problem

in Programming Questions  •  1 year ago  
I had a stupid problem. I fixed it. New problem!
 
Alright, I'm trying to create a first person shooter, and i've got the camera working. Is there a possible substitute for the cameraDirection?
int playerX=50;
int playerY=250;
int playerZ=250;
void setup()
{
  size(500,500,P3D);
  background(0);
  mouseX = 250;
}
void draw()
{
  background(0);
  beginCamera();
  camera(0.0,0.0,0.0,playerX,playerY,playerZ,0.0,1.0,0.0);
  rotateY(mouseX/50);
  endCamera();
   if(mousePressed)
     {
        if(key == 'w')
     {
        playerZ == cameraDirection;
        playerZ = playerZ+1;
     }
  }
       if(keyPressed)
          {
             if(key == 's')
          {
       playerZ == cameraDirection;
       playerZ = playerZ+ -1;
     }
   }
}
 
This is my code right now:
int playerX=50;
int playerY=250;
int playerZ=250;
void setup()
{
  size(500,500,P3D);
  background(0);
  mouseX = 250;
}
void draw()
{
  background(0);
  camera(0.0,0.0,0.0,playerX,playerY,playerZ,0.0,1.0,0.0);
  rotateY(mouseX/50);
  endCamera();
  translate(250,250,250);
  box(100);
}
The box is just so I can tell the direction
The post below was an awnser to my earlier question.

Replies(3)

The cubes move when I test it...

BTW: The response rate is generally pretty high in this forum. If you haven't gotten an answer on your previous thread, then either (a) people don't have an answer, (b) people don't understand your question, or (c) they didn't see it, in which case you can bump your message by responding to it.

Re: New problem

1 year ago
This seems to be a sin cos problem.
i simply would rotate all the blocks around you, not the camera :)
Some code of crisr, simply jus change the y coordinate to a z coordinate


Copy code

  1.     int angle=0;
        int radius = 100;
        void setup() {
          size (770, 770);
        }
        void draw() {
          background (0);
          // get x and y
          float x = cos(radians(angle)) * radius;
          float y = sin(radians(angle)) * radius;
          // headline
          fill(234, 2, 2);
          stroke(234, 2, 2);  
          text("Demonstration of sin and cos",
          width/2 - textWidth("Demonstration of sin and cos")/2,
          height / 2 -radius - 30);
          strokeWeight(1);
          line (width/2 - textWidth("Demonstration of sin and cos")/2,
          height / 2 -radius - 27,
          width/2 + textWidth("Demonstration of sin and cos")/2-8,
          height / 2 -radius - 27);
          // line from center to current angle
          strokeWeight(1);
          line (width/2, height / 2,
          width/2 + x, height/2 + y);
          // show middle point / center
          stroke(255, 2, 2);
          strokeWeight(5);
          point (width/2, height / 2);
          // show current angle by adding x and y to center
          stroke(2, 244, 222);
          point (width/2 + x, height/2 + y);
          // show x part
          stroke(2, 244, 2);
          fill(2, 244, 2);
          line (
          width/2, height / 2+ radius + 10,
          width/2 + x, height / 2 + radius + 10);
          text("x = "+x, width/2, height / 2 + radius + 30);
          // show y part
          stroke(30, 120, 222);
          fill(30, 120, 222);
          line (
          width/2 + radius + 10, height / 2,
          width/2 + radius + 10, height / 2 + y );
          text("y = "+y, width/2 + radius + 30, height / 2 + 0);
          // show angle part
          fill(234);
          println(angle);
          text ("angle = "+ angle, width/2-27, height / 2 - 10 );
          // show formula
          fill(234);
          text(  "float x = cos(radians(angle)) * radius;", width/2-227, height - 140 );
          text(  "float y = sin(radians(angle)) * radius;", width/2-227, height  - 120 );
          // ----------------
          // manage the angle
          angle ++;
          if (angle>360)
          {
            angle=0;
          }
        }

Re: New problem

1 year ago
I was playing with this. I edited it twice.
 
This was the simplest of edits:
Copy code
  1. int angle=0;
        int radius = 100;
        void setup() {
          size (770, 770);
        }
        void draw() {
          background (0);
          // get x and y
          float x = cos(radians(angle)) * radius;
          float y = sin(radians(angle)) * radius;
          // headline
          fill(234, 2, 2);
          stroke(234, 2, 2);  
          text("Demonstration of sin and cos",
          width/2 - textWidth("Demonstration of sin and cos")/2,
          height / 2 -radius - 30);
          strokeWeight(1);
          line (width/2 - textWidth("Demonstration of sin and cos")/2,
          height / 2 -radius - 27,
          width/2 + textWidth("Demonstration of sin and cos")/2-8,
          height / 2 -radius - 27);
          // line from center to current angle
          strokeWeight(1);
          line (width/2, height / 2,
          width/2 + x, height/2 + y);
          // show middle point / center
          stroke(255, 2, 2);
          strokeWeight(5);
          point (width/2, height / 2);
          // show current angle by adding x and y to center
          stroke(2, 244, 222);
          point (width/2 + x, height/2 + y);
          // show x part
          stroke(2, 244, 2);
          fill(2, 244, 2);
          line (
          width/2, height / 2+ radius + 10,
          width/2 + x, height / 2 + radius + 10);
          text("x = "+x, width/2, height / 2 + radius + 30);
          // show y part
          stroke(30, 120, 222);
          fill(30, 120, 222);
          line (
          width/2 + radius + 10, height / 2,
          width/2 + radius + 10, height / 2 + y );
          text("y = "+y, width/2 + radius + 30, height / 2 + 0);
          // show angle part
          fill(234);
          println(angle);
          text ("angle = "+ angle, width/2-27, height / 2 - 10 );
          // show formula
          fill(234);
          text(  "float x = cos(radians(angle)) * radius;", width/2-227, height - 140 );
          text(  "float y = sin(radians(angle)) * radius;", width/2-227, height  - 120 );
          // ----------------
          // manage the angle
          angle = mouseX;
        }
On this one I Edited the camera the camera
 
Copy code
  1.     int angle=0;
        int radius = 100;
        void setup() {
          size (770, 770,P3D);
        }
        void draw() {
          background (0);
          // get x and y
          float x = cos(radians(angle)) * radius;
          float y = sin(radians(angle)) * radius;
          // headline
          fill(234, 2, 2);
          stroke(234, 2, 2);  
          text("Demonstration of sin and cos",
          width/2 - textWidth("Demonstration of sin and cos")/2,
          height / 2 -radius - 30);
          strokeWeight(1);
          line (width/2 - textWidth("Demonstration of sin and cos")/2,
          height / 2 -radius - 27,
          width/2 + textWidth("Demonstration of sin and cos")/2-8,
          height / 2 -radius - 27);
          // line from center to current angle
          strokeWeight(1);
          camera(width/2, height / 2,
          0,width/2 + x, height/2 + y,0,0.0,0.0,1.0);
          // show middle point / center
          stroke(255, 2, 2);
          strokeWeight(5);
          point (width/2, height / 2);
          // show current angle by adding x and y to center
          stroke(2, 244, 222);
          point (width/2 + x, height/2 + y);
          // show x part
          stroke(2, 244, 2);
          fill(2, 244, 2);
          line (
          width/2, height / 2+ radius + 10,
          width/2 + x, height / 2 + radius + 10);
          text("x = "+x, width/2, height / 2 + radius + 30);
          // show y part
          stroke(30, 120, 222);
          fill(30, 120, 222);
          line (
          width/2 + radius + 10, height / 2,
          width/2 + radius + 10, height / 2 + y );
          text("y = "+y, width/2 + radius + 30, height / 2 + 0);
          // show angle part
          fill(234);
          println(angle);
          text ("angle = "+ angle, width/2-27, height / 2 - 10 );
          // show formula
          fill(234);
          text(  "float x = cos(radians(angle)) * radius;", width/2-227, height - 140 );
          text(  "float y = sin(radians(angle)) * radius;", width/2-227, height  - 120 );
          // ----------------
          // manage the angle
          angle = mouseX;
        }
 
So your looking from the blue dot into the red dot.
 
I can't see how to make it go forwards and backwards depending on the camera direction.