Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7042879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:13:17+00:00 2026-05-28T02:13:17+00:00

For a game i’m trying to calculate the angle between where i’m looking at

  • 0

For a game i’m trying to calculate the angle between where i’m looking at and the position of another object in the scene. I got the angle by using the following code:

Vec3 out_sub;
Math.Subtract(pEnt->vOrigin, pLocalEnt->vOrigin, out_sub);
float angle = Math.DotProductAcos(out_sub, vec3LookAt);

This code does give me the angle between where im looking at and an object in the scene. But there’s a small problem.

When i don’t directly look at the object but slightly to the left of it, then it says i have to rotate 10 degrees in order to directly look at the object. Which is perfectly correct.

But, when i look slightly to the right of the object, it also says i have to rotate 10 degrees in order to look directly to the object.

The problem here is, the i have no way to tell which way to rotate to. I only know its 10 degrees. But do i have to rotate to the left or right? That’s what i need to find out.

How can i figure that out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:13:18+00:00Added an answer on May 28, 2026 at 2:13 am

    I feel the need to elaborate on Ignacio’s answer…

    In general, your question is not well-founded, since “turn left” and “turn right” only have meaning after you decide which way is “up”.

    The cross product of two vectors is a vector that tells you which way is “up”. That is, A x B is the “up” that you have to use if you want to turn left to get from A to B. (And the magnitude of the cross product tells you how far you have to turn, more or less…)

    For 3D vectors, the cross product has a z component of x1 * y2 - y1 * x2. If the vectors themselves are 2D (i.e., have zero z components), then this is the only thing you have to compute to get the cross product; the x and y components of the cross product are zero. So in 2D, if this number is positive, then “up” is the positive z direction and you have to turn left. If this number is negative, then “up” is the negative z direction and you have to turn left while upside-down; i.e., turn right.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using cocos2d for iPhone game development, I am confused between Layer and Scene. For
I am looking into game programming in Java to see if it is feasible.
I am porting a game using SpiderMonkey to Android. Because I need to integrate
The game is simple where the Pan object catches the Pizza objects that are
i am making a game using andengine in android, in this game various sprites(eggs)
I'm writing a game in C using the Gtk libraries, in which the player
game.cpp #include <iostream> #include <string> #include <sstream> #include game.h #include board.h #include piece.h using
I wrote a game in c++ using SDL. The game currently updates a highscore
I'm a web-game developer and I got a problem with random numbers. Let's say
I'm creating a game in C++ (speaking of which, does the code I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.