Question regarding Camera Position in a 3D Scene

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jezternz
    New Member
    • Jan 2008
    • 145

    Question regarding Camera Position in a 3D Scene

    Okay, so I have setup a scene in Java.
    I have 2 points. The first point is always 0,0,0.
    The second point is the camera position and can be any positive or negative values for x,y,z.
    Now what I want to do is have a function 'centerCameraVi ew' which will modify the camera angle values, and will put the first point (0,0,0) in the center of the camera's view.
    So I guess as much as anything I am looking for pseudo code. Any help would be great, even links to other sites, or a good search. I couldn't find anything that really helped.

    Cheers, Josh
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Jezternz
    Okay, so I have setup a scene in Java.
    I have 2 points. The first point is always 0,0,0.
    The second point is the camera position and can be any positive or negative values for x,y,z.
    Now what I want to do is have a function 'centerCameraVi ew' which will modify the camera angle values, and will put the first point (0,0,0) in the center of the camera's view.
    So I guess as much as anything I am looking for pseudo code. Any help would be great, even links to other sites, or a good search. I couldn't find anything that really helped.
    If the camera is positioned at a point (x, y, z) and always 'looks' at the origin O = (0, 0, 0) then you have to translate the subject towards that origin O. A simple translation finds the average of the subject (x', y', z') and uses that vector to translate the subject towards the origin O.

    kind regards,

    Jos

    Comment

    • Jezternz
      New Member
      • Jan 2008
      • 145

      #3
      Thanks for the reply Josah,
      I am quite new to vector math, so I was wondering if you could give me a bit more detail. When you say average of a vector (subject), do you mean the normalised version of it?
      Once I have this, I don't quite get the last line either, what do you mean by translate the subject towards the origin O.
      cheers, Josh

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Jezternz
        Thanks for the reply Josah,
        I am quite new to vector math, so I was wondering if you could give me a bit more detail. When you say average of a vector (subject), do you mean the normalised version of it?
        Once I have this, I don't quite get the last line either, what do you mean by translate the subject towards the origin O.
        cheers, Josh
        Suppose you have a unit cube with one of its corners in the origin O. The average position of the cube is at A = (1/2, 1/2, 1/2). Translate the entire cube over the vector -A so that the origin O will be at the middle of the cube.

        In general: for points v_1, v_2 ... v_n, find A = sum(v_i)/n; next translate all v_i over -A, i.e. v_i-A and project those points according to your camera position.

        kind regards,

        Jos

        Comment

        Working...