# Using one point to calculate another...

Fayetteville, NC, USA
OK, somewhere along the line my vector code got screwed up. I have two vectors, one being where the camera is situated and one being the area the camera is looking at. Here's my current code, which does NOT work.
[code]
Base.LX = Base.X + cos(Base.Heading * (pi / 180)) + 64;
Base.LY = Base.Y + sin(Base.LookUp * (pi / 180)) + 64;
Base.LZ = Base.Z + sin(Base.Heading * (pi / 180)) + 64;
[/code]
The L* variables are the ones that the camera needs to look at. Say I'm at 0,0,0 looking north (0deg heading). The L* should be set to 0,0,64 but it isn't! Heading is anything from 0 to 359, and lookup ranges from -90 to +90. What's wrong here?

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

• [b][red]This message was edited by Zaffire at 2002-12-27 22:44:23[/red][/b][hr]
: OK, somewhere along the line my vector code got screwed up. I have two vectors, one being where the camera is situated and one being the area the camera is looking at. Here's my current code, which does NOT work.
: [code]
: Base.LX = Base.X + cos(Base.Heading * (pi / 180)) + 64;
: Base.LY = Base.Y + sin(Base.LookUp * (pi / 180)) + 64;
: Base.LZ = Base.Z + sin(Base.Heading * (pi / 180)) + 64;
: [/code]
: The L* variables are the ones that the camera needs to look at. Say I'm at 0,0,0 looking north (0deg heading). The L* should be set to 0,0,64 but it isn't! Heading is anything from 0 to 359, and lookup ranges from -90 to +90. What's wrong here?
:
: -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
:
adding 64 to each vector component will just shift L* by +64, +64, +64. if 64 is the magnitude to give L* length, shouldn't you be multiplying by 64 instead of adding? what is the 64 there for? also, which direction is north?

if 0 degrees heading is pointing down the negative z axis, an increase in heading sweeps towards the positive X axis, and you want to keep a constant magnitude of 64, then try this:
[code]
Base.LX = Base.X + 64 * cos(Base.LookUp * (pi/180)) * sin(Base.Heading * (pi/180));
Base.LZ = Base.Z - 64 * cos(Base.LookUp * (pi/180)) * cos(Base.Heading * (pi/180));

Base.LY = Base.Y + 64 * sin(Base.LookUp * (pi/180));
[/code]
then, when you are at (0,0,0) w/ heading 0 and LookUp 0, L* will be <0,0,-64>, which would be straight ahead. in your code, heading is the angle from the positive x axis, sweeping towards the positive z axis, and it won't maintain a constant magnitude, thus . if heading 0 is another direction, you have to re-figure the formulas based on an angle from that direction. hope that helps, and that i didn't totally misunderstand your question.

Zaffire
• Fayetteville, NC, USA
Yeah I eventually figured that I needed to add 64 before doing the calculations. Originally I added it after the calculation, which of course failed. Then I multiplied by 1.5 afetr the calculation, which worked to an extent, but I finally did figure out what I was doing wrong. Thanks Zaff.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]