Announcement

Collapse
No announcement yet.

how to calculate the point that the camera is most looking at

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    how to calculate the point that the camera is most looking at

    Given a camera point in world space, a normalized camera direction (vector) and a list of points in world space,
    How can I find which point the camera is most looking at.

    I was assuming:
    Make a list of object
    Subtract the direction vector of the camera against the object to get a directional vector. example camera angle (0,0,1) vs point position (1,1,1)
    Then get the angle from the original camera vector against the new vector.

    How’s ever angle is smaller that should be one that is most looking at right?
    Wonder how that could that be written in code?

    #2
    I assume that just giving those objects a collision and then tracing for them is not an option.

    So I have two ideas that would work

    Idea 1:

    Well, basically it is your idea :P

    Pseudocode:

    Code:
    for(object in objectArray)
    {
        float DotResult = FVector::Dot(CamForwardVector, (object.Location - CamLocation).SafeNormal());
        if(DotResult > BestResult)
        {
             bestObject = object;
        }
    }
    IF both vectors are normalized, DotProduct gives you, well the angle between them. It returns the angle in a range of -1 to 1 where 1 -> 0degree difference and -1 -> 180°difference and 0 -> 90°.

    Note: You might want to add a distance from camera to this evaluation, so if two objects are kinda the same angle but one is closer to the cam, you might want to take the one closer, even if it's angle is bigger.

    Idea 2:

    Just project the points onto your 2D ViewPlane using Canvas->Project(). Then just check the distance from the point to the center of the screen and pick the smallest.
    That does not work if you have points behind you though.
    Last edited by DennyR; 09-10-2014, 07:30 PM.

    Comment


      #3
      Assuming you're looking for the object closest to the centre of the screen and disregarding distance

      For each Actor
      EyeVector = Normalized(ActorLocation - CameraLocation)
      ActorDot = Dot(EyeVector, CameraDirection)

      What ever Actor has the biggest ActorDot is the one closest to the centre of the screen.
      @kylerocha
      Luminawesome Games
      http://luminawesome.com/

      Comment

      Working...
      X