Mailing List
Home
Forum Home
Softimage
Carrara
trueSpace
Dir3d-l
Maya - a powerful 3D animation and visual effects software
Macromedia Flash Development
Subjects
Cameras
scaleDown command
black out solved
Aircraft Tutorial
Mathematical XYZ ?
Its done This vs That
Its done first week
recommendations for screen video captures?
3DExplorer "Oddity "
New Director
ProTeam renewals
Fuel 's new websites (X post)
Blue peter create a make toy
targeting groups question
XPost: Shockwave 3D game ( sort of )
RES: RES: RES: Fish Modeling
Emitting particles from object intersection
Fuel 's new websites (X post)
Texturing
Big Break Contest Videos
New Plugins
Models and Texture on my updated site
Error Installing Patch tS6 6
Plasma?
Looking for Inspiration
Weird EMail Q
It 's done first week ?
Cherry not cranberry
New game
Camera Animation Problem
Particle plugins?
 
Mapping Space to a Plane (was: Finding the landing point)

Mapping Space to a Plane (was: Finding the landing point)

2004-01-21       - By James Newton

 Back
On 8/1/04 10:15 pm, "James Newton" <james.newton@(protected)> wrote:

> On 8/1/04 3:31 pm, "Allen Partridge" <partridge@(protected)> wrote:
>> Has anyone got an efficient way to find the landing point of a
>> projectile ... that [is] hitting a ground that is rotated on the x,
>> so the ground is sort of uphill as we go.
>
> Hi Allen,
>
> Your projectile will follow a parabolic curve in a 2D plane...

> on LineCutsParabola(a, b, c, m, n) -- ---- ---- ---- ---- ---- ---- ---
>   -- INPUT: <a>, <b>, <c>, <m> and <n> must all be floats
>   --         The parabola is expressed as y = ax^2 + bx + c
>   --         The line is expressed as     y = mx + n
>   -- OUTPUT: Returns a list of points.  The list may contain 0, 1 or 2
>   --         points where the line intersects the parabola.  The
>   --         coordinates will be floats.
>   -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------

<SNIP>
>
> Your work now is to determine the input values...
>
> How's your matrix math for the 2D <=> 3D conversions?


Hello again Allen,

I needed to create some 2D <=> 3D conversion routines for my current
project, so here they are.

Cheers,

James


-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---

-- MAP SPACE TO PLANE --
--
-- � January 2004, OpenSpark Interactive Ltd
--  <james.newton@(protected)>
--
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
-- Use the global handlers in this movie script to map points in space
-- to a given 2D plane, and vice-versa.
--
-- Example uses:
-- * Convert the trajectory of a missile into a 2D parabola
-- * Bend a branch according to a Bernoulli curve in 2D space
--
-- MapSpaceToPlane(a3DPosition, anOrigin, {aYAxis {, aNormal}})
-- MapSpaceToPlane(a3DPosition, aTransform)
--
-- MapPlaneToSpace(a2DPoint, anOrigin, aYAxis, aNormal)
-- MapPlaneToSpace(a2DPoint, aTransform)
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --



on MapSpaceToPlane(a3DPosition, anOrigin, aYAxis, aNormal) -- ---- ---
 -- INPUT: <a3DPosition> should be a position vector, which is to
 --         be mapped onto the plane.
 --        <anOrigin> should be a position vector, defining the
 --         origin (0, 0) of the 2D plane.
 --        <aYAxis> should be a unit vector defining the direction of
 --         the y-axis of the 2D plane.  If not, vector(0, 1, 0) is
 --         used.
 --        <aNormal> may be a vector or it may be omitted.  If
 --         aNormal is a vector not parallel to aYAxis then the plane
 --         will be oriented to contain aYAxis and the cross-product
 --         of aYAxis and aNormal.  In this case, a3DPosition will
 --         be projected onto the plane.
 --         In all other cases, the plane will be defined to contain
 --         both aYAxis and the vector from anOrigin to
 --         a3DPosition.
 -- Alternative Syntax: <anOrigin> may be a transform, in which case
 --         aYAxis will be the transform's y-axis, and aNormal will
 --         be the transform's z-axis.  The second parameter will
 --         be used for a3DPosition.  Subsequent parameters will be
 --         ignored.
 -- OUTPUT: Returns a 2D point(<float>, <float>), or an error
 --         symbol if the input parameters were unusable.  The point
 --         will always have a non-negative x co-ordinate.
 -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----

 -- Check the validity of the parameters
 case ilk(anOrigin) of
   #vector:
     if not ilk(a3DPosition, #vector) then
       return #invalidPoint
     end if

     if ilk(aYAXis, #vector) then
       -- Ensure that aYAxis is a unit vector
       aYAxis = aYAxis.getNormalized()
     else
       aYAxis = vector(0, 1, 0) -- use up by default
     end if

   #transform:
     if ilk(aYAXis, #vector) then
       -- Use this second parameter for a3DPosition
       a3DPosition = aYAxis
     else
       return #invalidAxis
     end if

     -- Unpack the plane definition from the transform
     aNormal  = anOrigin.zAxis
     aYAxis   = anOrigin.yAxis
     anOrigin = anOrigin.position

   otherwise:
     return #invalidOrigin
 end case

 -- Define a3DPosition with respect to the origin
 tRelativePosition = a3DPosition - anOrigin

 -- Check if aNormal is defined, and if so, project a3DPosition
 -- onto the plane defined by anOrigin and aNormal

 if ilk(aNormal, #vector) then
   tTemp = aNormal.cross(aYAxis)
   if tTemp.magnitude <> 0 then
     -- aNormal is not parallel to aYAxis, so we can make it a unit
     -- vector orthogonal to aYAxis
     aNormal = aYAxis.cross(tTemp)
     aNormal.normalize()

     -- Project a3DPosition onto the plane
     tDistanceToPlane = tRelativePosition * aNormal
     if tDistanceToPlane <> 0 then
       tRelativePosition = tRelativePosition-aNormal*tDistanceToPlane
     end if
   end if
 end if

 -- Determine the y coordinate (positive or negative)
 y = aYAxis * tRelativePosition
 x = (tRelativePosition - y * aYAxis).magnitude -- never negative

 tPoint = point(x, y)

 return tPoint
end MapSpaceToPlane



on MapPlaneToSpace(a2DPoint, anOrigin, aYAxis, aNormal) -- ---- ------
 -- INPUT: <a2DPoint> should be a point object.  LocH and LocV may
 --         be represented as floats
 --        <anOrigin> should be a position vector, defining the
 --         origin (0, 0) of the 2D plane.
 --        <aYAxis> should be a unit vector defining the direction of
 --         the y-axis of the 2D plane.  If not, vector(0, 1, 0) is
 --         used.
 --        <aNormal> should be a vector which is not parallel to
 --         aYAxis.
 -- Alternative Syntax: <anOrigin> may be a transform, in which case
 --         aYAxis will be the transform's y-axis, and aNormal will
 --         be the transform's z-axis.  The second parameter will
 --         be used for a3DPosition.  Subsequent parameters will be
 --         ignored.
 -- OUTPUT: Returns a 3D position vector, or an error symbol if the
 --         input parameters were unusable.
 -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----

 if ilk(a2DPoint) <> #point then
   return #invalidPoint
 end if

 case ilk(anOrigin) of
   #vector:
     if ilk(aYAXis, #vector) then
       -- Ensure that aYAxis is a unit vector
       aYAxis = aYAxis.getNormalized()
     else
       aYAxis = vector(0, 1, 0)
     end if

     if ilk(aNormal, #vector) then
       -- Ensure that aNormal is a unit vector
       tTemp = aNormal.cross(aYAxis)
       if tTemp.magnitude <> 0 then
         -- aNormal is not parallel to aYAxis, so we can make it a
         -- unit vector orthogonal to aYAxis
         aNormal = aYAxis.cross(tTemp)
         aNormal.normalize()

       else -- parallel to the y-axis
         return #invalidNormal
       end if
     else -- not a vector
       return #invalidVector
     end if

   #transform:
     -- Unpack the plane definition from the transform
     aNormal  = anOrigin.zAxis
     aYAxis   = anOrigin.yAxis
     anOrigin = anOrigin.position

   otherwise:
     return #invalidOrigin
 end case

 tXAxis   = aYAxis.cross(aNormal)
 t3DPoint = anOrigin + tXAxis*a2DPoint.locH + aYAxis*a2DPoint.locV

 return t3DPoint
end MapPlaneToSpace


__ ____ ____ ____ ____ ____ ____ ____ ____ ____
Dir3d-l mailing list
Dir3d-l@(protected)
http://nuttybar.drama.uga.edu/mailman/listinfo/dir3d-l