POV-Ray : Newsgroups : povray.advanced-users : Vector to Angle Server Time
29 Mar 2024 10:37:43 EDT (-0400)
  Vector to Angle (Message 11 to 20 of 24)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 4 Messages >>>
From: scott
Subject: Re: Vector to Angle
Date: 2 Jun 2017 02:59:43
Message: <59310cdf$1@news.povray.org>
>>> 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

From: dick balaska
Subject: Re: Vector to Angle
Date: 15 Dec 2017 02:30:21
Message: <5a337a0d$1@news.povray.org>
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)

From: Bald Eagle
Subject: Re: Vector to Angle
Date: 15 Dec 2017 07:55:01
Message: <web.5a33c52f3905ed8fc437ac910@news.povray.org>
dick balaska <dic### [at] buckosoftcom> 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

From: dick balaska
Subject: Re: Vector to Angle
Date: 15 Dec 2017 15:57:00
Message: <5a34371c$1@news.povray.org>
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

From: Bald Eagle
Subject: Re: Vector to Angle
Date: 15 Dec 2017 16:30:01
Message: <web.5a343e1a3905ed8fc437ac910@news.povray.org>
dick balaska <dic### [at] buckosoftcom> 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

From: Bald Eagle
Subject: Re: Vector to Angle
Date: 15 Dec 2017 16:50:01
Message: <web.5a3443343905ed8fc437ac910@news.povray.org>
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

From: dick balaska
Subject: Re: Vector to Angle
Date: 15 Dec 2017 17:17:46
Message: <5a344a0a$1@news.povray.org>
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

From: dick balaska
Subject: Re: Vector to Angle
Date: 15 Dec 2017 17:26:03
Message: <5a344bfb@news.povray.org>
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

From: Bald Eagle
Subject: Re: Vector to Angle
Date: 15 Dec 2017 18:35:00
Message: <web.5a345b433905ed8f5cafe28e0@news.povray.org>
dick balaska <dic### [at] buckosoftcom> 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

From: dick balaska
Subject: Re: Vector to Angle
Date: 15 Dec 2017 22:24:10
Message: <5a3491da$1@news.povray.org>
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

<<< Previous 10 Messages Goto Latest 10 Messages Next 4 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.