POV-Ray : Newsgroups : povray.advanced-users : Point at a vector; angles for rotation on axes X and Y /w nonzero origin : Re: Point at a vector; angles for rotation on axes X and Y /w nonzero origi= Server Time
28 Jul 2024 12:21:19 EDT (-0400)
  Re: Point at a vector; angles for rotation on axes X and Y /w nonzero origi=  
From: Tor Olav Kristensen
Date: 16 Aug 2005 18:05:01
Message: <web.430261e273034d4752d573c20@news.povray.org>
"Mike C" <the### [at] hotmailcom> wrote:
> Hi all,
>
> First, apologies in advance if this is in the wrong group or previously
> posted -- I tried searching and looking in the archives, and couldn't find
> anything.  Maybe I didn't search hard enough.
>
> Anyways, I have two objects, one a cylinder pointing at positive Z, and a
> semisphere pointing at Y with a cutout of it holding above said cylinder
> (although it's "front" is at Z for the purpose of this discussion).  These
> are translated off of the origin.
>
> [Anyone who is interested, the object is supposed to represent a sort of
> cannon or gun on a spaceship or other ship.]
>
> Anyways, I want to rotate the cylinder (barrel of the gun) on the X and Y
> axes to point at a Vector, and I want the associated semisphere ("body" of
> the gun, I suppose?) to rotate the same amount on the Y axis, but not to
> rotate in any other way.  These calculations, I'm hoping, should be based
> on the vector of the cylinder's location (which could be stored in a
> seperate variable), as opposed to the origin, or at least, when translated,
> will end up pointing at the intended destination.
>
> There will be two sets of objects (handled independantly), both pointing at
> the same vector from two different locations.
>
> I am aware of the Point_At_Trans and Reorient_Trans, but I can't get them to
> work properly; either the objects end up pointing the wrong way, or they
> don't translate to the spot I want them in.
>
> Hopefully this makes sense; my thinking is a tad unclear today.
>
> Thanks in advance for any response.

Mike,
I've prepared some code for you below that shows how you can use the
Reorient_Trans() macro to point your barrel at a target.


Tor Olav
http://subcube.com

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.6;

#include "colors.inc"
#include "transforms.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare pTarget = <-10, 5, 7>;
#declare pBase = <1, 1, -3>;
#declare pFront = pBase + 3*z;

#declare vFrom = pFront - pBase;
#declare vTo = pTarget - pBase;

#declare Target = sphere { pTarget, 0.2 }
#declare Base = sphere  { pBase, 0.3 }
#declare GunBarrel = cylinder { pBase, pFront, 0.2 }
#declare LineOfSight = cylinder { pBase, pTarget, 0.1 }
#declare ReorientedGunBarrel =
  object {
    GunBarrel
    translate -pBase
    Reorient_Trans(vFrom, vTo)
    translate pBase
  }

object { Target pigment { color Cyan } }
object { Base pigment { color Orange } }
object { GunBarrel pigment { color Yellow } }
object { LineOfSight pigment { color White } }
object { ReorientedGunBarrel pigment { color Red } }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

light_source { <1, 2, -2>*100 color White*2 }

camera {
  location <3, 1, -1>*4
  look_at pBase
}

background { color Gray40 }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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