 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
I'm trying to master converting a vector to an angle in 3D with no luck
(2D sure, I got that).
I tried two different formulas with varying degrees of not success.
In the code below, the secret to my success will be the VtoA macro.
The result should be, the Cyan sphere, whose position is generated from
the VtoA macro, should be locked in the center of the screen behind the
Red sphere, which is locked to the center of the screen, because it is
look_at. The current odd return from VtoA is the closest I can get.
This works good if I move from 0 in only one axis at a time.
Help?
--
dik
Post a reply to this message
Attachments:
Download 'test.inc.txt' (2 KB)
Download 'animtest.ini.txt' (1 KB)
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Am 2017-05-29 15:42, also sprach dick balaska:
> I'm trying to master converting a vector to an angle in 3D
Of course I figured it out after finally asking:
// Convert this vector into its angle
#macro VtoA(V)
#local _V=vnormalize(V);
#local rZ=degrees(acos(_V.z));
#local rY=0;
#if (_V.y != 0)
#local rY=degrees(atan2(_V.x,_V.y));
#end
#debug concat("rY/Z=", str(rY,0,2), ", ", str(rZ,0,2), "\n")
<-rZ,0,-rY>
#end
--
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Am 2017-05-29 15:42, also sprach dick balaska:
> I'm trying to master converting a vector to an angle in 3D with no luck
Help, Math wizards, you're my only hope.
Ok. I'm stuck. I'm missing something.
My goal is to position an object in a fixed position on the screen, like
carrying a flashlight. Or a gun, like in a video game.
So I need to calculate the angle of Lookat-Camera and act on that.
My primary macro works, but I'm missing something in determining the
position of an object that is not exactly on the look_at. I can't
figure out if I need to subtract an angle or a vector or from whom.
For example, in this screen shot,
http://www.buckosoft.com/tteoac/video/testRenders/test001.png
the red ball is look_at,
the cyan ball is the angle correctly derived from (look_at-camera),
but the green ball is only correctly 1 unit horizontally to the right of
the cyan ball for this angle <0,0,0>. Otherwise it spins incoherently
(to me) around the cyan ball. Interestingly, it keeps the correct distance.
http://www.buckosoft.com/tteoac/video/testRenders/test.mp4
argh. I keep trying to work it out on paper, but I'm not feeling it.
--
dik
Post a reply to this message
Attachments:
Download 'test.inc.txt' (3 KB)
Download 'animtest.ini.txt' (1 KB)
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
dick balaska <dic### [at] buckosoft com> wrote:
> Am 2017-05-29 15:42, also sprach dick balaska:
> > I'm trying to master converting a vector to an angle in 3D with no luck
>
> Help, Math wizards, you're my only hope.
>
> Ok. I'm stuck. I'm missing something.
>
> My goal is to position an object in a fixed position on the screen, like
> carrying a flashlight. Or a gun, like in a video game.
>
> So I need to calculate the angle of Lookat-Camera and act on that.
I was looking through the docs, and there really is SO MUCH in the include files
and macros and functions, that I can hardly keep track of where I started once I
reach the end.
I'd say start by looking over the vector functions like VAngleD(),
VProject_Axis(), VProject_Plane()etc and see if you can maybe blindly plug in
vectors and get it to work. There might be some scenes in the distribution that
have some good code snippets.
There might also be some good code snippets from things like sunpos.inc and
scenes like my watch animation that handle data like you're talking about.
> argh. I keep trying to work it out on paper, but I'm not feeling it.
I have been there SO many times.
I will try to draw it out on paper and see what I can tell you - unless someone
else jumps on this before then.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
OK, the way I see it is that you need to take the atan2 of your _distance_
between the 2 points and the x or y value of the look_at
The key is that you need to take into account the x AND y variation of your
vector when you calculate the x and y angles. So use the whole vector length
in your atan2 function.
so, that would be something like
degrees(atan2(Vlength(LA-Cam), LA.x)) and degrees(atan2(Vlength(LA-Cam), LA.y))
or expanded:
degrees( atan2 ( sqrt( ((LA.x-Cam.x)^2)+((LA.y-Cam.y)^2)+((LA.z-Cam.z)^2) ),
LA.x ))
degrees( atan2 ( sqrt( ((LA.x-Cam.x)^2)+((LA.y-Cam.y)^2)+((LA.z-Cam.z)^2) ),
LA.y ))
(worked out in OpenOffice, so they _may_ some editing need (like the N^2
notation) )
Good luck, YMMV :D
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 31/05/2017 07:06, dick balaska wrote:
> Am 2017-05-29 15:42, also sprach dick balaska:
>> I'm trying to master converting a vector to an angle in 3D with no luck
>
> Help, Math wizards, you're my only hope.
>
> Ok. I'm stuck. I'm missing something.
>
> My goal is to position an object in a fixed position on the screen, like
> carrying a flashlight. Or a gun, like in a video game.
>
> So I need to calculate the angle of Lookat-Camera and act on that.
>
> My primary macro works, but I'm missing something in determining the
> position of an object that is not exactly on the look_at. I can't
> figure out if I need to subtract an angle or a vector or from whom.
> For example, in this screen shot,
> http://www.buckosoft.com/tteoac/video/testRenders/test001.png
> the red ball is look_at,
> the cyan ball is the angle correctly derived from (look_at-camera),
> but the green ball is only correctly 1 unit horizontally to the right of
> the cyan ball for this angle <0,0,0>. Otherwise it spins incoherently
> (to me) around the cyan ball. Interestingly, it keeps the correct distance.
> http://www.buckosoft.com/tteoac/video/testRenders/test.mp4
>
> argh. I keep trying to work it out on paper, but I'm not feeling it.
Try the attached.
Post a reply to this message
Attachments:
Download 'test16.pov.txt' (3 KB)
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Oh, a single rotational angle.
That makes sense.
I wasn't sure what he was after - it's hard to tell with something symmetric
like a sphere.
I'm guessing he wants to avoid:
http://www.mathwords.com/a/angle_depression.htm
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Am 2017-05-31 12:07, also sprach scott:
> On 31/05/2017 07:06, dick balaska wrote:
>> Help, Math wizards, you're my only hope.
> Try the attached.
Yeah baby! There's nothing like a copy/paste solution that I almost
understand, but does exactly what I want. ;)
I can't wait to try it out on non-solid, non-spherical shapes.
Thanks!
--
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Am 2017-05-31 07:52, also sprach Bald Eagle:
>> argh. I keep trying to work it out on paper, but I'm not feeling it.
>
> I have been there SO many times.
One of my favorites was, my wife took a picture of me with my chin on
the dining room table, playing with a Lego cow and a ruler. Which, if
you've seen my animation of the running non-articulated horses, you'll
understand what I was trying to accomplish. ;) Usually, it's just paper
with random circles and triangles and lines and points.
She: "Do you understand any of that?"
Me: "Not really."
--
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
dick balaska <dic### [at] buckosoft com> wrote:
> One of my favorites was, my wife took a picture of me with my chin on
> the dining room table, playing with a Lego cow and a ruler. Which, if
> you've seen my animation of the running non-articulated horses, you'll
> understand what I was trying to accomplish. ;)
I can't tell you how many things I measure on a regular basis.
Rulers, tape measures, eye-and-thumb, protractor, or back-estimating from
photos....
Speaking of Legos - you ought to check out the Antikythera mechanism this guy
built entirely from Lego. :O
> Usually, it's just paper
> with random circles and triangles and lines and points.
Yes. I have piles and piles of paper with lines and circles and ellipses and
triangles, and then there are the ones where there's a rat's nest of curves and
5 pages of equations...
"WTF are you ***DOING***????!!!"
"Well, ..."
"No. never mind. OMG."
:D
BTW
I think if you just look at the rotation angle like a clock hand on the screen,
centered around your camera location, then all you're doing is calculating the
angle, given the x and y coordinates.
So that's just degrees ( atan2(LookAt.y-Cam.y, LookAt.x-Cam.x) )
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
>>> Help, Math wizards, you're my only hope.
>
>> Try the attached.
>
> Yeah baby! There's nothing like a copy/paste solution that I almost
> understand, but does exactly what I want. ;)
> I can't wait to try it out on non-solid, non-spherical shapes.
>
> Thanks!
:-)
What you're trying to do is transform some kind of "screen" coordinates
into world coordinates. What I did was to calculate the directions of
the "new" x,y,z axes and then use those to transform the original
coordinate to the actual world coordinate:
> #local newZ = vnormalize( Lookat-Camera );
The new Z axis direction should be from Camera to Lookat, this is what
you want. vnormalize makes sure it's a unit length vector.
> #local newY = y;
The new Y axis direction is just y to start (it will be fixed later).
> #local newX = vnormalize(vcross(newY,newZ));
The new X axis direction is perpendicular to the Z and Y defined in the
above two lines (ie to the right). X and Z are now correct, but Y needs
to be adjusted to take account of Z probably not being horizontal (Y
needs to be "tipped back" a bit).
> #local newY = vnormalize(vcross(newZ,newX));
The new Y is now calculated as perpendicular to the Z and X just
calculated. This is correct now, with all 3 perpendicular to each other.
> #local bar = bar.x * newX + bar.y * newY + bar.z * newZ;
This line essentially takes the original xyz coordinates and transforms
them using the new XYZ axes. There are neater ways to do this, but I
thought this made it a little more clear what is going on.
Note the new coordinates are relative to the camera, so you still need
the translate camera line.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 05/29/2017 03:42 PM, dick balaska wrote:
> Help, Math wizards, you're my only hope.
I have started again to try to tackle this problem.
Scott's solution gave me a vector, which is not what I need. :( I need
an angle.
http://www.buckosoft.com/tteoac/video/testRenders/test2.mp4
The first 3 moves are correct, when I move x or z. As soon as I move
both, all hell breaks loose.
The kid in my movie is carrying a flashlight. It has an offset of
<-0.4,-0.3,0.7> from the origin and points down the Z.
The red ball is Lookat.
I have the angle between Lookat-Camera shown by the cyan ball.
It seems to me that if I move my flashlight to its offset, rotate it by
the Lookat-Camera angle, then add the Camera vector, it SHOULD BE LOCKED
TO THE CAMERA.
argh.
Post a reply to this message
Attachments:
Download 'test2.pov.txt' (5 KB)
Download 'animtest.ini.txt' (1 KB)
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
dick balaska <dic### [at] buckosoft com> wrote:
> On 05/29/2017 03:42 PM, dick balaska wrote:
>
> > Help, Math wizards, you're my only hope.
>
> I have started again to try to tackle this problem.
>
> Scott's solution gave me a vector, which is not what I need. :( I need
> an angle.
>
> http://www.buckosoft.com/tteoac/video/testRenders/test2.mp4
>
> The first 3 moves are correct, when I move x or z. As soon as I move
> both, all hell breaks loose.
>
> The kid in my movie is carrying a flashlight. It has an offset of
> <-0.4,-0.3,0.7> from the origin and points down the Z.
> The red ball is Lookat.
> I have the angle between Lookat-Camera shown by the cyan ball.
>
> It seems to me that if I move my flashlight to its offset, rotate it by
> the Lookat-Camera angle, then add the Camera vector, it SHOULD BE LOCKED
> TO THE CAMERA.
>
> argh.
So, just so I fully understand what you want,
1. You want to have a flashlight that always points at "Lookat"
2. You want it offset by a certain amount from the camera position
3. ... ? (if any)
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 12/15/2017 07:50 AM, Bald Eagle wrote:
> argh.
>
> So, just so I fully understand what you want,
> 1. You want to have a flashlight that always points at "Lookat"
> 2. You want it offset by a certain amount from the camera position
>
> 3. ... ? (if any)
Yes, like in Doom, where the gun is in a fixed position relative to the
game window.
(Wait, isn't there a text thingy in the object library that draws text
in a fixed position on the screen? ...)
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
dick balaska <dic### [at] buckosoft com> wrote:
> On 12/15/2017 07:50 AM, Bald Eagle wrote:
> > argh.
> >
> > So, just so I fully understand what you want,
> > 1. You want to have a flashlight that always points at "Lookat"
> > 2. You want it offset by a certain amount from the camera position
> >
> > 3. ... ? (if any)
>
> Yes, like in Doom, where the gun is in a fixed position relative to the
> game window.
>
> (Wait, isn't there a text thingy in the object library that draws text
> in a fixed position on the screen? ...)
Yes.
There is Screen.inc
I think the idea there is that with a default camera position at the origin, and
a view direction of +z, you have a standard -0.5 to +0.5y and -0.5*4/3 to
0.5*4/3x rectangle in the view frustum.
Then you can normalize everything and locate it on that rectangle and if it's a
3D object, squish it really flat. It gets jammed up right against the camera
with all the no_shadow etc stuff, so it doesn't interfere with the scene.
I had some problems unraveling it all at first, but once I wrapped my head
around it, it wasn't too bad.
http://news.povray.org/povray.binaries.images/thread/%3Cweb.587ce3fc782d1af2c437ac910%40news.povray.org%3E/?ttop=418740
&toff=50&mtop=415328
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
2 more things:
1. I have no idea what version of Doom YOU were playing - a flashlight? :O
;)
#MomMode
2. You need 2 angles - shine the light at +z, then rotate y and rotate x
I'll see if I have some time to give it a quick look when I get back tonight.
Last night was rather late.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 12/15/2017 04:26 PM, Bald Eagle wrote:
> I had some problems unraveling it all at first, but once I wrapped my head
> around it, it wasn't too bad.
>
>
http://news.povray.org/povray.binaries.images/thread/%3Cweb.587ce3fc782d1af2c437ac910%40news.povray.org%3E/?ttop=418740&toff=50&mtop=415328
Hmm, I missed that thread. It looks ... interesting to me.
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 12/15/2017 04:48 PM, Bald Eagle wrote:
> 2 more things:
>
>
> 1. I have no idea what version of Doom YOU were playing - a flashlight? :O
> ;)
> #MomMode
It's not a gun, Mom, it's a flashlight. It just looks like a gun.
>
> 2. You need 2 angles - shine the light at +z, then rotate y and rotate x
Looking at this picture
http://snipd.net/wp-content/uploads/2011/05/Spherical-coordinates.png
from this page
http://snipd.net/2d-and-3d-vector-normalization-and-angle-calculation-in-c
I wondered if doing it in two rotates was an answer, as opposed to
rotate <x, y, 0>
>
>
> I'll see if I have some time to give it a quick look when I get back tonight.
> Last night was rather late.
Well, you should. There is no greater purpose in life than helping a
fellow anonymous POV-er. I don't want no excuses about last night.
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
dick balaska <dic### [at] buckosoft com> wrote:
> It's not a gun, Mom, it's a flashlight. It just looks like a gun.
> I wondered if doing it in two rotates was an answer, as opposed to
> rotate <x, y, 0>
Yes, because the POV-Ray coordinate system is in x, y, z Cartesian space, not
spherical coordinates.
If you are getting a vector as a result, then you can likely just translate that
to spherical coordinates.
> Well, you should. There is no greater purpose in life than helping a
> fellow anonymous POV-er. I don't want no excuses about last night.
Slave.
Driver.
Give the following a whirl and see if you follow what's going on:
#################################################################
#version 3.71;
#declare Radiosity = off;
global_settings {
assumed_gamma 1
#if (Radiosity)
radiosity {
pretrace_start 0.04
pretrace_end 0.01
count 200
recursion_limit 3
nearest_count 10
error_bound 0.5
}
#end
}
#include "colors.inc"
#include "glass.inc"
#include "textures.inc"
#include "metals.inc"
#include "rand.inc"
#declare Perspective = image_width/image_height;
#declare P = Perspective;
#declare Camera = <0, 0, 0>;
camera {
perspective
up <0,1,0>
right x*Perspective
location Camera
look_at <0, 0, 1>
}
light_source {<1, 1, -50> color rgb <1,1,1>}
//plane {y, 0 texture {pigment {Gray50} normal {granite 0.1}} }
#declare Flashlight = <-0.4, -0.3, 0.7>;
#declare Size = 0.025;
#for (Y, -0.5, 0.5, 0.1)
#for (X, -0.5*P, 0.5*P, 0.1)
#declare LookAt = <X, Y, 1>;
sphere {LookAt Size pigment {rgbt <1, 0, 0, 0.9>}}
// Imagine a sphere at <0, 0, 1>
// rotating around the x-axis brings the height of the
// flashlight impact to the same height as the LookAt point
// Then, when it is rotated around the y-axis, it maintains this height
// and is oriented to point at the LookAt point
// Note that this "vector" direction is not corrected for the distance to the
plane
// and so it is is a cylindrical curve, it is not the same as the Lookat
point,
// but one can draw a line from the Flashlight
// to the LookAt point, which is in the +z view plane
#declare Xo = LookAt.y - Camera.y;
#declare Xa = LookAt.z - Camera.z;
#declare XAngle = degrees(atan2 (Xo, Xa));
#declare Yo = LookAt.x - Camera.x;
#declare Ya = LookAt.z - Camera.z;
#declare YAngle = degrees(atan2 (Yo, Ya));
#declare Xo2 = LookAt.y - Flashlight.y;
#declare Xa2 = LookAt.z - Flashlight.z;
#declare XAngle2 = degrees(atan2 (Xo, Xa));
#declare Yo2 = LookAt.x - Flashlight.x;
#declare Ya2 = LookAt.z - Flashlight.z;
#declare YAngle2 = degrees(atan2 (Yo, Ya));
sphere {<0, 0, 1> Size/2 pigment {rgbt <0, 1, 0, 0.9>} rotate x*XAngle rotate
y*YAngle}
sphere {<0, 0, 1> Size/4 pigment {White} rotate x*XAngle2 rotate y*YAngle2}
#end
#end
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 12/15/2017 06:31 PM, Bald Eagle wrote:
>
> Give the following a whirl and see if you follow what's going on:
>
Should the white/green spheres be centered in the red spheres?
or, at least, "in front of".
This looks kinda like what I got now. Once you move away from the
origin, it goes out of whack.
--
dik
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Le 17-12-15 à 15:57, dick balaska a écrit :
> On 12/15/2017 07:50 AM, Bald Eagle wrote:
>> argh.
>>
>> So, just so I fully understand what you want,
>> 1. You want to have a flashlight that always points at "Lookat"
>> 2. You want it offset by a certain amount from the camera position
>>
>> 3. ... ? (if any)
>
> Yes, like in Doom, where the gun is in a fixed position relative to the
> game window.
>
> (Wait, isn't there a text thingy in the object library that draws text
> in a fixed position on the screen? ...)
>
>
Locate your light at the same location as the camera, with a slight
offset if you want.
Make it a spot_light.
Spotlight have a point_at parameter, make it the same as your look_at.
point_at default to <0,0,0> if you don't set it.
#declare Light_Offset = <0, -0.5, 0>;
Camera{Cam_Location look_at Somewhere}
light_source{Cam_location + Light_Offset
rgb 1
spotlight
radius 5
tightness 40
point_at Somewhere
}
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 12/15/2017 07:50 AM, Bald Eagle wrote:
> dick balaska <dic### [at] buckosoft com> wrote:
>> On 05/29/2017 03:42 PM, dick balaska wrote:
>>
>> > Help, Math wizards, you're my only hope.
>>
>> I have started again to try to tackle this problem.
>>
>> Scott's solution gave me a vector, which is not what I need. :( I need
>> an angle.
>>
http://www.buckosoft.com/tteoac/video/testRenders/test3.mp4
Eureka!
The solution is to rotate it with the Cartesian result and then
translate it with scott's vcross-ish solution. i.e.
object {
myCyl
#local flOfs = <-0.4,-0.3,0.7>; // flashlight offset from camera
rotate VtoA(Lookat-Camera)
translate Camera+ssOffset(flOfs)
}
// Convert this vector into its angle
#macro VtoA(V)
#local _V=vnormalize(V);
#local rZ=degrees(acos(_V.z));
#local rY=0;
#local rX=0;
#if (_V.y != 0)
#local rY=degrees(atan2(_V.x,_V.y));
#else
#local rX=rZ;
#local rZ=0;
#end
<-rZ,rX,-rY>
#end
#macro ssOffset(bar)
#local newZ = vnormalize( Lookat-Camera );
#local newY = y;
#local newX = vnormalize(vcross(newY,newZ));
#local newY = vnormalize(vcross(newZ,newX));
#local barOut = bar.x * newX + bar.y * newY + bar.z * newZ;
barOut
#end
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
dick balaska <dic### [at] buckosoft com> wrote:
> On 12/15/2017 07:50 AM, Bald Eagle wrote:
> > dick balaska <dic### [at] buckosoft com> wrote:
> >> On 05/29/2017 03:42 PM, dick balaska wrote:
> >>
> >> > Help, Math wizards, you're my only hope.
> >>
> >> I have started again to try to tackle this problem.
> >>
> >> Scott's solution gave me a vector, which is not what I need. :( I need
> >> an angle.
> >>
>
> http://www.buckosoft.com/tteoac/video/testRenders/test3.mp4
>
> Eureka!
>
> The solution is to rotate it with the Cartesian result and then
> translate it with scott's vcross-ish solution. i.e.
> ...
See this post for an alternative solution:
From: Tor Olav Kristensen
Subject: Reorienting a flashlight along with the camera
Date: 17 Dec 2017 15:00:00
http://news.povray.org/povray.text.scene-files/thread/%3Cweb.5a36860f8dfaa90bb572bd120%40news.povray.org%3E/
It's interesting that no trigonometric functions are needed for this.
--
Tor Olav
http://subcube.com
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 5/31/2017 2:06 AM, dick balaska wrote:
> Am 2017-05-29 15:42, also sprach dick balaska:
>> I'm trying to master converting a vector to an angle in 3D with no luck
>
> Help, Math wizards, you're my only hope.
>
> Ok. I'm stuck. I'm missing something.
>
> My goal is to position an object in a fixed position on the screen, like
> carrying a flashlight. Or a gun, like in a video game.
You could create the flashlight and camera, and then apply the same
transformations to both.
Mike
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |