Forked from
Alchemy Viewer / Alchemy Viewer
8976 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
raytrace.cpp 38.23 KiB
/**
* @file raytrace.cpp
* @brief Functions called by box object scripts.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "math.h"
//#include "vmath.h"
#include "v3math.h"
#include "llquaternion.h"
#include "m3math.h"
#include "raytrace.h"
BOOL line_plane(const LLVector3 &line_point, const LLVector3 &line_direction,
const LLVector3 &plane_point, const LLVector3 plane_normal,
LLVector3 &intersection)
{
F32 N = line_direction * plane_normal;
if (0.0f == N)
{
// line is perpendicular to plane normal
// so it is either entirely on plane, or not on plane at all
return FALSE;
}
// Ax + By, + Cz + D = 0
// D = - (plane_point * plane_normal)
// N = line_direction * plane_normal
// intersection = line_point - ((D + plane_normal * line_point) / N) * line_direction
intersection = line_point - ((plane_normal * line_point - plane_point * plane_normal) / N) * line_direction;
return TRUE;
}
BOOL ray_plane(const LLVector3 &ray_point, const LLVector3 &ray_direction,
const LLVector3 &plane_point, const LLVector3 plane_normal,
LLVector3 &intersection)
{
F32 N = ray_direction * plane_normal;
if (0.0f == N)
{
// ray is perpendicular to plane normal
// so it is either entirely on plane, or not on plane at all
return FALSE;
}
// Ax + By, + Cz + D = 0
// D = - (plane_point * plane_normal)
// N = ray_direction * plane_normal