Can't get camera() to work the way I want it to.

I want to use camera() in a way that allows me to rotate the camera properly. I want you to make 2 functions; 1 that converts pitch, yaw, and roll into x, y, and z for the eye variables, and another that takes the same variables and produces x, y, and z, for the up variables. Use PVector for the return types.

Tagged:

Answers

  • When you remove the changes of the UP vector here, it’s a good starting point:

    See my code here:

    https://forum.processing.org/two/discussion/comment/121992/#Comment_121992

  • Have you looked at the QueasyCam library?

  • His main goal is to have peasy cam functionality without pressing the left mouse button (so basically throughout), judging from his other thread(s)

    But it’s hard to tell PeasyCam this so he‘s going to write his own

  • judging from his other thread(s)

    oof. Everything related in one place, please!

  • This may actually be simpler than I thought for first-person... Up-down controls rotation on X and Z, depending upon Y rotation value (sin(),cos()), and Left-right controls rotation on Y. I bet I could even get rotateX() rotateY() and rotateZ() to work perfectly for my purposes, with translate() for movement, of course.

  • edited April 2018

    P.S. What is QueasyCam? (I edited this because of a typo)

  • I believe I've made some code that could, in theory, work:

    rotY = mouseX;
    rotX = -cos(rotY)*mouseY;
    rotZ = -sin(rotY)*mouseY;
    

    Now, I just need to find the proper order to apply the rotation functions in...

  • ...Or did I just get the right order of rotations, from just the lines that calculated the rotation values?

  • No... From a webpage I found on Yaw, pitch, and roll rotations, the rotation functions are to be applied Z, then Y, then X.

  • Well, I just had a Eureka moment. Sorry, but you didn't really help that much.

  • can you post your result?

  • edited April 2018

    Sorry, but you didn't really help that much.

    ??

    why did you write that? I think you have the boxes code from me and the camera code as well....?

  • edited April 2018

    I take it back. What I actually need code for is:

    • mouseX (horizontal motion) turns the players "head" left and right.

    • mouseY (vertical motion) turns the players "head" up and down.

    If you can, try to make it so that there's no way to turn your head the remaining way. So, maybe your idea from another thread could work really well, with just a small modification:

    Projecting the camera in the bottom half of a sphere in such a way that both X and Y controls are inverted. Then, use camera() with that resultant vector to create perspective. Decrease the radius/diameter of the sphere to zoom in, increase to zoom out. You could also use scale() to accomplish the zoom functionality.

    Is there a function to find your position in 3D space given latitude and longitude? Because that's basically what I'm inputting (longitude is mouseX times PI over width, latitude is mouseY times PI over height)

  • post your entire code

  • edited April 2018

    Wait... I've just found a solution to my own problem again, haven't I? And again, it involves rotateY() and rotateZ(), just not rotateX(). rotate y by longitude, and rotate z by latitude. Put together, we get something like this:

    longitude = mouseX * PI / width;
    latitude = mouseY * PI / height;
    rotateY(longitude);
    rotateZ(latitude);
    

    Of course, there is still likely the problem of it rotating the whole thing.So, maybe insert rotate(compensate(longitude, latitude));. We would definitely need to work out that function, so we now have a sub-problem. And that's what I need help with now.

  • Wait again... longitude is not used. Instead, it's rotate(compensate(latitude));, which may, in fact, be as simple as:

    float compensate(float latitude) {
      return -latitude;
    }
    

    So, then, the whole code for the perspective is:

    longitude = mouseX * PI / width;
    latitude = mouseY * PI / height;
    rotateY(-longitude);
    rotateZ(-latitude);
    rotate(latitude);
    

    I negated all use of the longitude and latitude variables, as without it, the axes would be inverted, which I actually don't want here.

  • edited April 2018

    Or, I suppose, EYE could be player position, CENTER could be EYE + lat-long projected into a hemisphere, using ECEF (Earth-Centered Earth-Fixed). In which case, we'd repeat the following, including the start of what I plan to use this advice for (a Minecraft clone):

    clear();
    
    if(keyPressed) {
      movePlayer();
    }
    
    latlong.x = mouseX * PI / width;
    latlong.y = mouseY * PI / height;
    
    center = player + toECEF(latlong);
    
    pushMatrix();
    camera(player.x, player.y, player.z, center.x, center.y, center.z, 0.0, 1.0, 0.0);
    drawPlayer();
    popMatrix();
    

    Of course, we have variables player, latlong, center and functions movePlayer(), toECEF(PVector), drawPlayer(). These will be dealt with, and currently the most difficult part will be toECEF(PVector)

  • What is QueasyCam?

    it's a library similar to peasyCam but with first person perspective

    please try it. although again it might only work when mouse is pressed and not throughout

    maybe this can switched off or defined differently

  • Thank you for telling me what QueasyCam is. If it is designed for first-person, you would probably expect it to work throughout. If it does, I can use the mouse buttons to place/break blocks, rather than moving the camera. If not, I will try either modifying usage of the library, looking for a new library that works throughout, or (this is what I was trying) writing my own camera script.

  • Good news: It appears to work throughout, with no code in draw(). I will use the "quantize variables of type float" to position boxes which I define in a class. The class "player" I mentioned in that thread is useless, just define px, py, pz, and probably some variables to state which direction the player is facing.

  • QueasyCam is pan-tilt... why didn't I think of doing it that way?

    spoon counter incremented to 1, because I just built it for this purpose

  • re:

    What is QueasyCam?

    In case it is unclear to later readers of this thread, QueasyCam is linked on the Processing Libraries page and available via the QueasyCam gitHub repo. Top search result:

    "QueasyCam is a super-simple first-person-shooter camera for 3D Processing sketches."

    And, via Processing > Add Tool > Libraries:

    "QueasyCam: A super-simple FPS camera for Processing."

  • re:

    "QueasyCam is a super-simple first-person-shooter camera for 3D Processing sketches."

    I'm not using it for a first-person shooter, just for first-person. But that's fine.

    Also, I didn't really have to think about adding it other than finding it in the menu, because I installed the sound library for a different sketch on another computer, and I may end up using it in the same sketch as what I wanted to use this for.

Sign In or Register to comment.