本文整理汇总了C++中Ray::GetOrigin方法的典型用法代码示例。如果您正苦于以下问题:C++ Ray::GetOrigin方法的具体用法?C++ Ray::GetOrigin怎么用?C++ Ray::GetOrigin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ray
的用法示例。
在下文中一共展示了Ray::GetOrigin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ImpulseBegin
void TranslationTool::ImpulseBegin(const Ray& ray) {
UpdateScale();
Vector3f position = transformable->GetPosition();
Matrix transform = Matrix::CreateScale(Vector3f(scale)) * Matrix::CreateTranslation(position);
BoundingBox xBox = BoundingBox::Transform(xAxisBBox, transform);
BoundingBox yBox = BoundingBox::Transform(yAxisBBox, transform);
BoundingBox zBox = BoundingBox::Transform(zAxisBBox, transform);
F32 distance;
if (ray.Intersects(xBox, &distance)) {
if (ray.Intersects(Plane(Vector3f::Up, -position.y), &distance)) {
type = XAxis;
prevPoint = ray.GetOrigin() + ray.GetDirection() * distance;
}
} else if (ray.Intersects(yBox, &distance)) {
if (ray.Intersects(Plane(Vector3f::Backward, -position.z), &distance)) {
type = YAxis;
prevPoint = ray.GetOrigin() + ray.GetDirection() * distance;
}
} else if (ray.Intersects(zBox, &distance)) {
if (ray.Intersects(Plane(Vector3f::Right, -position.x), &distance)) {
type = ZAxis;
prevPoint = ray.GetOrigin() + ray.GetDirection() * distance;
}
}
}
示例2: Impulse
void TranslationTool::Impulse(const Ray& ray) {
Vector3f position = transformable->GetPosition();
switch(type) {
case XAxis: {
F32 distance;
if (ray.Intersects(Plane(Vector3f::Up, -position.y), &distance)) {
Vector3f intersection = ray.GetOrigin() + ray.GetDirection() * distance;
F32 deltaX = intersection.x - prevPoint.x;
transformable->SetPosition(Vector3f(position.x + deltaX, position.y, position.z));
prevPoint = intersection;
}
break;
}
case YAxis: {
F32 distance;
if (ray.Intersects(Plane(Vector3f::Backward, -position.z), &distance)) {
Vector3f intersection = ray.GetOrigin() + ray.GetDirection() * distance;
F32 deltaY = intersection.y - prevPoint.y;
transformable->SetPosition(Vector3f(position.x, position.y + deltaY, position.z));
prevPoint = intersection;
}
break;
}
case ZAxis: {
F32 distance;
if (ray.Intersects(Plane(Vector3f::Right, -position.x), &distance)) {
Vector3f intersection = ray.GetOrigin() + ray.GetDirection() * distance;
F32 deltaZ = intersection.z - prevPoint.z;
transformable->SetPosition(Vector3f(position.x, position.y, position.z + deltaZ));
prevPoint = intersection;
}
break;
}
}
}
示例3: Intersects
GeometryRayTestResult Intersects(const Sphere& Ball, const Ray& Cast)
{
// Code in this function is based on the equivalent in Ogre
const Vector3 CastDir = Cast.GetNormal();
const Vector3 CastOrigin = Cast.GetOrigin() - Ball.Center; // Makes math easier to do this in sphere local coordinates
const Real Radius = Ball.Radius;
// Build coefficients for our formula
// t = (-b +/- sqrt(b*b + 4ac)) / 2a
Real ACoEff = CastDir.DotProduct(CastDir);
Real BCoEff = 2 * CastOrigin.DotProduct(CastDir);
Real CCoEff = CastOrigin.DotProduct(CastOrigin) - ( Radius * Radius );
// Get the Determinate
Real Determinate = ( BCoEff * BCoEff ) - ( 4 * ACoEff * CCoEff );
if( Determinate < 0 ) {
return GeometryRayTestResult(false,Ray());
}else{
Real NearDist = ( -BCoEff - MathTools::Sqrt( Determinate ) ) / ( 2 * ACoEff );
Real FarDist = ( -BCoEff + MathTools::Sqrt( Determinate ) ) / ( 2 * ACoEff );
Ray Ret( Cast.GetOrigin() + (CastDir * NearDist), Cast.GetOrigin() + (CastDir * FarDist) );
return GeometryRayTestResult(true,Ret);
}
}
示例4: IntersectingRayAgainstAABB
bool BasicPrimitiveTests::IntersectingRayAgainstAABB(const Ray & ray, const AABB & aabb, float & rtn_t)
{
/*
Main Idea:
-> Uses slab representation for box.
-> Finds intersection of ray/segment with each slab. Then compares intersection times for overlap in all slabs.
-> Keep track of:
-> A: The farthest of all entries into a slab
-> B: The closest of all exits out of a slab.
-> If A > B at anytime, exit with no intersection.
Intersecting slabs:
-> Intersect slabs by inserting ray equation into plane equations for slab.
-> Solve for t
-> Must handle case when ray parallel to slab separately.
-> To avoid division by zero.
Can test for intersection without calculating intersection point:
-> Choose coordinate system where box is axis aligned and centered at origin:
AABB:
-> Translate segment and AABB to origin.
OBB:
-> Transform Segment to OBB space, then translate both segment and OBB to origin.
-> Do separating axis test with 6 axes:
-> Three principle axes.
-> Three cross products of box face normals and segment direction vector.
*/
rtn_t = 0.0f;
float tmax = FLT_MAX;
Eigen::Vector3f aabb_min = aabb.GetCenter() - aabb.GetExtents();
Eigen::Vector3f aabb_max = aabb.GetCenter() + aabb.GetExtents();
for (int i = 0; i < 3; ++i)
{
if (abs(ray.GetDirection()[i]) < EPSILON)
{
//Ray is parallel to slab. Not hit if origin not within slab.
if (ray.GetOrigin()[i] < aabb_min[i] || ray.GetOrigin()[i] > aabb_max[i])
{
return false;
}
}
else
{
float one_over_direction = 1.0f / ray.GetDirection()[i];
float t1 = (aabb_min[i] - ray.GetOrigin()[i]) * one_over_direction;
float t2 = (aabb_max[i] - ray.GetOrigin()[i]) * one_over_direction;
if (t1 > t2) Swap(t1, t2);
if (t1 > rtn_t) rtn_t = t1;
if (t2 > tmax) tmax = t2;
if (rtn_t > tmax) return false;
}
}
return true;
}
示例5: Transform
Ray Ray::Transform(const Ray& ray, const Matrix& transform) {
Vector3f origin = ray.GetOrigin();
Vector3f target = origin + ray.GetDirection() * ray.GetDistance();
Vector3f newOrigin = Vector3f::Transform(origin, transform);
Vector3f newTarget = Vector3f::Transform(target, transform);
return Ray(newOrigin, newTarget);
}
示例6:
Air::U1 MeshEntity::RayCast( const Ray& ray ,float* pOutDistance)
{
#if 1
if(!GetWorldBoundingBox().RayCast(ray.GetOrigin(),ray.GetDirection())){//.Intersect(GetWorldBoundingBox())){
return false;
}
#endif
Matrix matWorld = *GetWorldMatrix();
Matrix matWorldInv = matWorld;
matWorldInv.Inverse();
Float3 vStart = ray.m_vStart;
Float3 vLookAt = vStart + ray.m_vDirection;
vStart = matWorldInv*vStart;
vLookAt = matWorldInv*vLookAt;
Float3 vDir = (vLookAt - vStart);
vDir.Normalize();
Ray objSpaceRay(vStart,vDir);
float fDistance = 999999.0f;
U1 bHit = m_pMesh->RayCast(objSpaceRay,&fDistance);
if(bHit && pOutDistance!=NULL){
Float3 vObjSpaceHitPostion = vStart + vDir*fDistance;
Float3 vWorldSpaceHiPosition = matWorld*vObjSpaceHitPostion;
*pOutDistance = (vWorldSpaceHiPosition - ray.m_vStart).Length();
}
return bHit;
}
示例7: fabs
bool PlaneIntersector<real>::Intersect( const Plane<real>* plane, const Ray<real>& ray, Intersection<real>& oIntersection )
{
const Vector3<real>& origin = ray.GetOrigin();
const Vector3<real>& direction = ray.GetDirection();
// Do not perform intersection if the direction of the ray is degenerated relative to the plane
if ( fabs( direction.Y() ) > EPS )
{
// Compute the intersection point and see if it's inside the plane bounds
real t = -origin.Y() / direction.Y();
Vector3<real> intersectionPoint = origin + t * direction;
bool isInsideXBounds = ( fabs( intersectionPoint.X() ) < plane->GetSizeX() * 0.5 ) ? true : false;
bool isInsideZBounds = ( fabs( intersectionPoint.Z() ) < plane->GetSizeZ() * 0.5 ) ? true : false;
// If the ray intersect and the intersection is in front
if ( ( t > 0 ) && isInsideXBounds && isInsideZBounds )
{
oIntersection.SetPosition( intersectionPoint );
oIntersection.SetNormal( Vector3<real>( 0, -sign<real>( direction.Y() ), 0 ) );
oIntersection.IsInside( false );
// Compute texture coodinates as (z=-0.5 => u=0 and x=-0.5 => v=0)
real u = ( intersectionPoint.Z() + plane->GetSizeZ() * 0.5 ) / plane->GetSizeZ();
real v = ( intersectionPoint.X() + plane->GetSizeX() * 0.5 ) / plane->GetSizeX();
oIntersection.SetTextureCoordinates( Vector3<real>( u, v, 0 ) );
return true;
}
}
return false;
}
示例8: CheckCollision
float Sphere::CheckCollision(Ray ray)
{
Vector q = ray.GetOrigin();
Vector v = ray.GetDirection();
float A = pow(v.x, 2) + pow(v.y, 2) + pow(v.z, 2);
float Bx = v.x * (q.x - origin.x);
float By = v.y * (q.y - origin.y);
float Bz = v.z * (q.z - origin.z);
float B = 2 * (Bx + By + Bz);
float C = pow(q.x - origin.x, 2) + pow(q.y - origin.y, 2) + pow(q.z - origin.z, 2) - pow(radius, 2);
//Determines if we have a 'hit'
float discriminant = pow(B, 2) - (4 * A * C);
if (discriminant >= 0.f)
{
//Calculate our t values
float root = sqrt(discriminant);
float t1 = (-B + root) / (2 * A);
float t2 = (-B - root) / (2 * A);
float d = t1;
if (t1 > t2 && t2 > 0) //Make sure we don't take a negative
d = t2; //Choose the smaller (closer) of the 2 values.
if (d >= 0) //We want a positive distance from the starting vector
{
return d;
}
}
return -1.0f;
}
示例9:
Ray<real> NodeIntersector<real>::TransformRayToLocalCoordinates( const CoreLib::Node<real>* node, const Ray<real>& ray )
{
const Matrix4<real>& globalToLocal = node->GetGlobalToLocal();
// The origin is affected by the affine transformation while the direction is not affected by translation ( operator ^ )
return Ray<real>( globalToLocal * ray.GetOrigin(), globalToLocal ^ ray.GetDirection() );
}
示例10: Intersect
int Sphere::Intersect( Ray& a_Ray, float& a_Dist )
{
vector3 v = a_Ray.GetOrigin() - m_Centre;
float b = -DOT( v, a_Ray.GetDirection() );
float det = (b * b) - DOT( v, v ) + m_SqRadius;
int retval = MISS;
if (det > 0)
{
det = sqrtf( det );
float i1 = b - det;
float i2 = b + det;
if (i2 > 0)
{
if (i1 < 0)
{
if (i2 < a_Dist)
{
a_Dist = i2;
retval = INPRIM;
}
}
else
{
if (i1 < a_Dist)
{
a_Dist = i1;
retval = HIT;
}
}
}
}
return retval;
}
示例11: if
bool SphereIntersector<real>::Intersect( const Sphere<real>* sphere, const Ray<real>& ray, Intersection<real>& oIntersection )
{
// Compute the equation corresponding to x²+y²+z²=0 with p+t*d to obtain a quadratic equation
real a = ray.GetDirection().SquaredLength();
real b = 2.0 * ray.GetDirection() * ray.GetOrigin();
real c = ray.GetOrigin().SquaredLength() - sphere->GetRadius() * sphere->GetRadius();
real discriminant = b*b - 4*a*c;
// Discriminant >= 0 => the must be at least one intersection
if ( discriminant >= 0 )
{
// Compute the two potential intersections and only keep the nearest
real sqrtDisc = sqrt( discriminant );
real t = 0;
real t1 = ( -b - sqrtDisc ) / ( 2.0 * a );
real t2 = ( -b + sqrtDisc ) / ( 2.0 * a );
if ( t1 >= 0 )
{
t = t1;
oIntersection.IsInside( false );
}
else if ( t2 >= 0 )
{
t = t2;
oIntersection.IsInside( true );
}
else
return false;
oIntersection.SetPosition( ray.GetOrigin() + t * ray.GetDirection() );
oIntersection.SetNormal( oIntersection.GetPosition().Normalized() );
oIntersection.SetTextureCoordinates( oIntersection.GetPosition().Normalized() );
// The normal must be flipped to coincide with the hit direction
if ( oIntersection.IsInside() )
oIntersection.SetNormal( -oIntersection.GetNormal() );
return true;
}
return false;
}
示例12: IntersectingRayAgainstOBB
bool BasicPrimitiveTests::IntersectingRayAgainstOBB(const Ray & ray, const OBB & obb)
{
Eigen::Matrix3f obb_rotation;
obb.GetRotationMatrix(obb_rotation);
Eigen::Vector3f ray_d_obb = obb_rotation * ray.GetDirection();
Eigen::Vector3f ray_o_obb = obb_rotation * (ray.GetOrigin() - obb.GetCenter());
return 0;
}
示例13: GetIntersectionDisk
FPType Plane::GetIntersectionDisk(Ray ray, Vector3d normal_, Vector3d position)
{
FPType denom = normal_.Dot(ray.GetDirection());
FPType t = -1;
if(std::abs(denom) > ray.tMin && t <= ray.tMax)
{
t = (position - ray.GetOrigin()).Dot(normal_) / denom;
}
return t;
}
示例14: GetIntersection
FPType Plane::GetIntersection(const Ray &ray)
{
FPType denom = normal.Dot(ray.GetDirection());
if(std::abs(denom) > BIAS)
{
FPType t = (center - ray.GetOrigin()).Dot(normal) / denom;
if(t > BIAS)
return t;
}
return false;
}
示例15: getPoint
bool Camera::getPoint(int mx, int my, const std::vector<LineSegment>& lines,
Vector3& p, const Plane& plane) {
float minDist = 1000.0f;
bool findCurr = false;
Ray ray = getRay(mx, my);
for (int i = 0; i < lines.size(); ++i) {
for (int j = 0; j < 2; ++j) {
if (Ray::distRayPoint(ray, lines[i].points[j]) < 0.1f) {
if ((ray.GetOrigin() - lines[i].points[j]).length() < minDist) {
minDist = (ray.GetOrigin() - lines[i].points[j]).length();
p = lines[i].points[j];
findCurr = true;
}
}
}
}
if (!findCurr)
p = intersect(ray, plane);
// std::cout<<p<<std::endl;
return findCurr;
}