File: Plane.h

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (36 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*---------------------------------------------------------------------
 Terrain Renderer using texture splatting and geomipmapping

 Copyright (2006) Jelmer Cnossen
 This code is released under GPL license (See LICENSE.html for info)
---------------------------------------------------------------------*/
#ifndef C_MATHLIB_H
#define C_MATHLIB_H

#include "float3.h"
typedef float3 Vector3;

#define EPSILON (0.01f)

class Plane
{
public:
	float a,b,c,d;
	Plane() { a=b=c=d=0; }
	Plane(float ta,float tb,float tc,float td) { a=ta;b=tb;c=tc;d=td; }
	Plane(Vector3 dir, float dis) { a=dir.x; b=dir.y;c=dir.z; d=dis; }
	float Dist(const Vector3 *v) const { return a*v->x+b*v->y+c*v->z-d; }
	float Dist(float x,float y,float z) const {  return a*x+b*y+z*c-d; }
	bool EpsilonCompare (const Plane& pln, float epsilon);
	bool operator==(const Plane &pln);
	bool operator!=(const Plane &pln) { return !operator==(pln); }
	void MakePlane(const Vector3& v1, const Vector3& v2,const Vector3& v3);
	void Inverse() {a=-a; b=-b; c=-c; d=-d;} // Plane is the same, but is pointing to the inverse direction
	void SetVec(Vector3 v) { a=v.x;b=v.y;c=v.z; }
	void CalcDist(const Vector3& p) { d = a*p.x + b*p.y + c*p.z; }
	void copy (Plane *pl) { pl->a=a; pl->b=b; pl->c=c; pl->d=d; }
	Vector3& GetVector() { return *(Vector3*)this; }
	Vector3 GetCenter() { return Vector3 (a*d,b*d,c*d); }
};

#endif