My camera can zoom in and out and I already figured out how to check if an object is INSIDE the camera with the frustum, but I want to check if an object is to the left or right side of the camera (The middle being its width divided by two). I'm also trying to use this to figure out how to play sounds in a certain part of the speakers, which I suppose is the pan variable of the sounds.
So if the “Object” is at position A, the camera is at position C, and the camera’s left direction is the vector L then:
if (A - C) . L > 0 the object is to the left
if (A - C) . L < 0 the object is to the right
if (A - C) . L = 0 the object is dead in the centre.
I am very much confused at what you’re giving here. Why is there a period after the parenthesis and then the L? How exactly would I define L? Also, the camera can zoom in and out, wouldn’t this math be screwed up as soon as I zoom out?
A and C are (X,Y,Z) coordinates. You subtract them component-wise and access the X component, which is what @quew8 meant by .L.
Then you do the dot product with the L (left) vector of the camera, which is perpendicular to the forward vector and the up vector.
Actually A, C, and L are all vectors. He means to calculate A - C and dot product it with L. The dot product is notated with a dot, although writing a period is much easier when on a computer.
L is simply the look direction of the camera, rotated to be left relative to the camera. Zooming in and out has no impact as you are not changing the view direction of the camera.
If your game is 2D, it may be easiest to do it the arithmetic way, calculating offsets and checking if they are positive or negative. Doing A - C will work here, which may be what @ra4king meant, as you are calculating if the direction is negative or positive allowing you to check which quadrant the object is in.
Dot product is a type of vector multiplication, it is best denoted by a *
Ah thank you all very much! I didn’t know until today that that was an actual symbol of multiplication.
Yes, I did mean for the full stop “.” to denote the vector dot product (aka scalar product). Sorry for all the confusion, I normally define that. And fyi, I don’t use “*” so as not to confuse with the cross product (aka vector product).
As for how to get the left vector, I thought you would already have that to do the frustum test. Essentially you can take it directly from the rotation matrix of the camera. That is the matrix that defines the rotation. Not the viewing matrix (which includes translation) not the projection matrix. Just the rotation matrix.
A1 A2 A3 A4
B1 B2 B3 B4
C1 C2 C3 C4
D1 D2 D3 D4
Then the left vector is just (A1, A2, A3) although if you’re using a right handed coordinate system this is the right vector. If you’re interested, (B1, B2, B3) is the “up” vector and (C1, C2, C3) is the “forward” vector.
Sorry again for all the confusion.
Op, of you’re new to vectors and dot product, this article describes how the dot product can be used for your EXACT requirements. Which is convenient lol.
Thank you! I spent a good hour Googling every single part of the previous answer to figure out what most of it meant. I eventually figured it out, but also thank you for the link!!! Every resource helps! ;D