/*-
 * Copyright (c) 1999,2000 Qube Software, Ltd.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of the source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 
 * 2. Any redistribution solely in binary form must conspicuously
 *    reproduce the following disclaimer in documentation provided with the
 *    binary redistribution.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'', WITHOUT ANY WARRANTIES, EXPRESS
 * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  LICENSOR SHALL
 * NOT BE LIABLE FOR ANY LOSS OR DAMAGES RESULTING FROM THE USE OF THIS
 * SOFTWARE, EITHER ALONE OR IN COMBINATION WITH ANY OTHER SOFTWARE.
 * 
 * 	$Id: ray.h,v 1.7 2000/04/20 16:21:58 n_hibma Exp $
 */

#ifndef __ray_h__
#define __ray_h__

MATHS_BEGIN

struct EXPORT_QMATHS Rayf {
    // Constructors
			Rayf() {}
			Rayf(const Vec3f& o, const Vec3f& d)
			    : origin_(o), direction_(d)
			{
			    init();
			}

    // Destructor
			~Rayf() {}

    // Accesors
    const Vec3f&	origin() const { return origin_; }
    const Vec3f&	direction() const { return direction_; }
    const Vec3f&	invDir() const { return invdir_; }

    // Modifiers
    void		origin(const Vec3f& v) { origin_ = v; }
    void		direction(const Vec3f& d)
	{
	    direction_ = d;
	    init();
	}
    
    // Matrix operations
    Rayf		transform(const Matrix4f& m) const
			{
			    return Rayf(origin_.transform(m),
					direction_.rotate(m));
			}

    Rayf		inverseTransform(const Matrix4f& m) const
			{
			    return Rayf(origin_.inverseTransform(m),
					direction_.inverseRotate(m));
			}

private:
    void                init();
    static unsigned long nextId;

    Vec3f		origin_;	// ray origin
    Vec3f		direction_;	// unit vector, indicating ray dir 
    Vec3f		invdir_;	// inverse of direction
    unsigned long	id_;
};

MATHS_END

#endif /* __ray_h__ */

// Local Variables:
// mode: c++
// End:
