Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/math/plane.h @ 7924

Last change on this file since 7924 was 7711, checked in by patrick, 19 years ago

trunk: merged the cd branche back to trunk

File size: 2.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Christian Meyer
13   co-programmer: ...
14*/
15
16/*!
17 * @file plane.h
18 * A basic 3D plane math framework
19 *
20 * Contains class to handle planes
21*/
22
23#ifndef __PLANE_H_
24#define __PLANE_H_
25
26#include <math.h>
27#include "compiler.h"
28#include "vector.h"
29#include "line.h"
30
31//! 3D plane
32/**
33  Class to handle planes in 3-dimensional space
34
35  Critical for polygon-based collision detection
36*/
37class Plane
38{
39  public:
40
41  Vector n;   //!< Normal vector
42  float k;    //!< Offset constant
43
44  Plane (const Vector& a, const Vector& b, const Vector& c);
45  Plane (const Vector& norm, const Vector& p);
46  Plane (const Vector& norm, const sVec3D& p);
47  Plane (const Vector& n, float k) : n(n), k(k) {} //!< assignment constructor
48  Plane () : n(Vector(1,1,1)), k(0) {}
49  ~Plane () {}
50
51  Vector intersectLine (const Line& l) const;
52  float distancePoint (const Vector& p) const;
53//   float distancePoint (const sVec3D& p) const;
54  float distancePoint (const float* p) const;
55  float locatePoint (const Vector& p) const;
56};
57
58
59
60//! A class that represents a rectangle, this is needed for SpatialSeparation
61class Rectangle
62{
63
64  public:
65    Rectangle() { this->center = Vector(); }
66    Rectangle(const Vector &center, float len) { this->center = Vector(center.x, center.y, center.z); this->axis[0] = len; this->axis[1] = len; }
67    virtual ~Rectangle() {}
68
69    /** \brief sets the center of the rectangle to a defined vector @param center the new center */
70   inline void setCenter(const Vector &center) { this->center = center;}
71    /** \brief sets the center of the rectangle to a defined vector @param x coord of the center @param y coord of the center @param z coord of the center */
72   inline void setCenter(float x, float y, float z) { this->center.x = x; this->center.y = y; this->center.z = z; }
73   /** \brief returns the center of the rectangle to a defined vector @returns center the new center */
74   inline const Vector& getCenter() const { return this->center; }
75
76   /** \brief sets both axis of the rectangle to a defined vector @param unityLength the new center */
77   inline void setAxis(float unityLength) { this->axis[0] = unityLength; this->axis[1] = unityLength; }
78   /** \brief sets both axis of the rectangle to a defined vector @param v1 the length of the x axis @param v2 the length of the z axis*/
79   inline void setAxis(float v1, float v2) { this->axis[0] = v1; this->axis[1] = v2; }
80   /** \brief gets one axis length of the rectangle  @returns the length of the axis 0 */
81   inline float getAxis() { return this-> axis[0]; }
82
83  private:
84    Vector          center;
85    float           axis[2];
86};
87
88
89#endif /* __PLANE_H_ */
90
Note: See TracBrowser for help on using the repository browser.