changed copyright years in source files
[fegdk.git] / core / code / video / f_brush.h
blob485d789723892aa405afe94acc3a06627fc7990c
1 /*
2 fegdk: FE Game Development Kit
3 Copyright (C) 2001-2008 Alexey "waker" Yakovenko
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 Alexey Yakovenko
20 waker@users.sourceforge.net
23 #ifndef __F_BRUSH_H
24 #define __F_BRUSH_H
26 #include "f_math.h"
27 #include "f_string.h"
28 #include "f_types.h"
29 #include "f_helpers.h"
30 #include "f_material.h"
31 #include "f_effect.h"
32 #include "f_basetexture.h"
34 namespace fe
37 class brushWinding
39 friend class brushFace;
40 friend class brush;
41 protected:
43 std::vector< vector3 > mPoints;
44 std::vector< vector2 > mTexCoords;
46 public:
48 brushWinding ();
49 brushWinding (const brushWinding &w);
50 ~brushWinding ();
52 // properties
53 vector3& point (int iPoint) { return mPoints[iPoint]; }
54 const vector3& point (int iPoint) const { return mPoints[iPoint]; }
55 int numPoints (void) const { return (int)mPoints.size (); }
56 vector2& texCoord (int iPoint) { return mTexCoords[iPoint]; }
57 const vector2& texCoord (int iPoint) const { return mTexCoords[iPoint]; }
58 void baseForPlane (const plane &p);
59 bool clip (const plane &split, bool keepon);
63 class brushFaceTexdef
66 private:
68 cStr mName;
69 int mShift[2];
70 int mRotate;
71 float mScale[2];
72 long mContents;
73 long mFlags;
74 long mValue;
76 public:
78 brushFaceTexdef ();
80 cStr& name (void) { return mName; }
81 const cStr& name (void) const { return mName; }
82 int* shift (void) { return mShift; }
83 const int* shift (void) const { return mShift; }
84 int& rotate (void) { return mRotate; }
85 const int& rotate (void) const { return mRotate; }
86 float* scale (void) { return mScale; }
87 const float* scale (void) const { return mScale; }
88 long& contents (void) { return mContents; }
89 const long& contents (void) const { return mContents; }
90 long& flags (void) { return mFlags; }
91 const long& flags (void) const { return mFlags; }
92 long& value (void) { return mValue; }
93 const long& value (void) const { return mValue; }
96 class brushFace
98 friend class brush;
99 protected:
101 plane mPlane;
102 vector3 mPlanePts[3];
103 brushWinding mWinding;
104 brushFaceTexdef mTexdef;
105 materialPtr mpMtl;
107 public:
109 brushFace ();
110 brushFace (const brushFace &f);
111 ~brushFace ();
113 plane& plane () { return mPlane; }
114 const plane& plane () const { return mPlane; }
115 vector3& planePt (uint iPoint) { assert (iPoint < 3); return mPlanePts[iPoint]; }
116 const vector3& planePt (uint iPoint) const { assert (iPoint < 3); return mPlanePts[iPoint]; }
117 brushWinding& winding () { return mWinding; }
118 const brushWinding& winding () const { return mWinding; }
119 materialPtr material () const { return mpMtl; }
120 void setMaterial (const materialPtr &mtl);
121 brushFaceTexdef& texdef () { return mTexdef; }
122 void textureVectors (float stFromXYZ[2][4]);
123 vector2 emitTexCoords (const vector3 &pt);
124 void applyTexdef (void);
128 class brush
131 protected:
133 std::vector< brushFace > mFaces;
134 vector3 mMins;
135 vector3 mMaxs;
137 bool makeFaceWinding (int face);
138 bool makeFacePlane (int face);
140 public:
142 brush ();
143 brush (const vector3 &mins, const vector3 &maxs);
144 void create (const vector3 &mins, const vector3 &maxs);
145 brush (const brush &b);
146 ~brush ();
147 void clear (void) { mFaces.clear (); }
149 // edit
150 void buildWindings (bool snap = true);
151 void move (const vector3 &moveVec, bool snap = true);
152 void splitByFace (const brushFace &f, brush *&front, brush *&back);
153 void snapToGrid ();
154 void snapPlanePts ();
155 void rotate (const vector3 &angle, const vector3 &origin, bool build = true);
156 void flip (const vector3 &axis, const vector3 &origin);
157 void removeEmptyFaces ();
158 virtual void build (bool bSnap = true);
159 void buildTexturing (void);
161 // primitives
162 void makeSided (int sides, int axis = 2); // default axis is z
163 void makeSidedCone (int sides);
164 void makeSidedSphere (int sides);
166 // properties
167 brushFace& faces (int iFace) { return mFaces[iFace]; }
168 const brushFace& faces (int iFace) const { return mFaces[iFace]; }
169 int numFaces (void) const { return (int)mFaces.size (); }
170 vector3& mins () { return mMins; }
171 vector3& maxs () { return mMaxs; }
172 void addFace (const brushFace& f) { mFaces.push_back (f); }
174 // csg
175 // void csgAdd (std::vector<brush *> &outBrushList, brush *b);
176 void csgSubtract (std::vector<brush *> &outBrushList, brush *b);
177 // void csgIntersection (std::vector<brush *> &outBrushList, brush *b);
178 // void csgDifference (std::vector<brush *> &outBrushList, brush *b);
183 #endif // __F_BRUSH_H