Ejemplo n.º 1
0
 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;
         }
     }
 }
Ejemplo n.º 2
0
	IResult Intersects(const Ray& ray, const Transformation& objT) const{
		if (!mBV)
			return IResult(false, FLT_MAX);
		Ray localRay = objT.ApplyInverse(ray, false);
		Ray::IResult ret = localRay.Intersects(mBV.get());
		return ret;
	}
Ejemplo n.º 3
0
bool Circle::IntersectsDisc(const Ray &ray) const
{
	float d;
	bool intersectsPlane = ray.Intersects(ContainingPlane(), &d);
	if (intersectsPlane)
		return false;
	return ray.GetPoint(d).DistanceSq(pos) <= r*r;
}
Ejemplo n.º 4
0
    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;
            }
        }
    }
Ejemplo n.º 5
0
bool AABB::Intersects(const Ray& r) const { return r.Intersects(*this); }
Ejemplo n.º 6
0
bool Plane::Intersects(const Ray& r,
                       CollisionInfo* const pInfo /*= NULL*/) const {
  return r.Intersects(*this, pInfo);
}