POV-Ray : Newsgroups : povray.advanced-users : Vector to Angle Server Time
29 Mar 2024 10:52:43 EDT (-0400)
  Vector to Angle (Message 15 to 24 of 24)  
<<< Previous 10 Messages Goto Initial 10 Messages
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

From: Alain
Subject: Re: Vector to Angle
Date: 16 Dec 2017 15:02:16
Message: <5a357bc8@news.povray.org>
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

From: dick balaska
Subject: Re: Vector to Angle
Date: 16 Dec 2017 21:05:28
Message: <5a35d0e8$1@news.povray.org>
On 12/15/2017 07:50 AM, Bald Eagle wrote:
> 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/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

From: Tor Olav Kristensen
Subject: Re: Vector to Angle
Date: 17 Dec 2017 10:10:00
Message: <web.5a3687793905ed8fb572bd120@news.povray.org>
dick balaska <dic### [at] buckosoftcom> wrote:
> On 12/15/2017 07:50 AM, Bald Eagle wrote:
> > 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/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

From: Mike Horvath
Subject: Re: Vector to Angle
Date: 18 Jan 2018 12:38:29
Message: <5a60db95$1@news.povray.org>
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

<<< Previous 10 Messages Goto Initial 10 Messages

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