root/cafu/trunk/CaWE/SurfaceInfo.hpp

Revision 457, 4.0 KB (checked in by Carsten, 4 months ago)

Using UltraEdit's multi-line search-and-replace-in-files feature, replaced


^#ifndef _(CAFU|CF|CFS|CA)_(.*)_$
^#define _\1_\2_$

with

#ifndef CAFU_\2_INCLUDED
#define CAFU_\2_INCLUDED

and


^#ifndef _(.*)_HPP_$
^#define _\1_HPP_$

with

#ifndef CAFU_\1_HPP_INCLUDED
#define CAFU_\1_HPP_INCLUDED

Closes #91.

Line 
1/*
2=================================================================================
3This file is part of Cafu, the open-source game engine and graphics engine
4for multiplayer, cross-platform, real-time 3D action.
5Copyright (C) 2002-2012 Carsten Fuchs Software.
6
7Cafu is free software: you can redistribute it and/or modify it under the terms
8of the GNU General Public License as published by the Free Software Foundation,
9either version 3 of the License, or (at your option) any later version.
10
11Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with Cafu. If not, see <http://www.gnu.org/licenses/>.
17
18For support and more information about Cafu, visit us at <http://www.cafu.de>.
19=================================================================================
20*/
21
22#ifndef CAFU_SURFACE_INFO_HPP_INCLUDED
23#define CAFU_SURFACE_INFO_HPP_INCLUDED
24
25#include "Math3D/Plane3.hpp"
26#include "Templates/Array.hpp"
27
28
29class TextParserT;
30
31
32/// This enum describes the technique that is used to generate texture-coordinates for the associated map primitive.
33enum TexCoordGenModeT
34{
35    Custom=0,   ///< The tex-coords are freely specified (per vertex).
36    MatFit,     ///< Texture coordinates are created, so the material fits exactly on the patch.
37    PlaneProj   ///< Texture coordinates are created using a plane projection with UV axes.
38};
39
40
41class TexCoordT
42{
43    public:
44
45    TexCoordT() : u(0), v(0) { }
46
47    float& operator [] (unsigned long Index)
48    {
49        assert(Index<2);
50        return Index==0 ? u : v;
51    }
52
53    const float& operator [] (unsigned long Index) const
54    {
55        assert(Index<2);
56        return Index==0 ? u : v;
57    }
58
59    float u;
60    float v;
61};
62
63
64/// This class holds all information that is needed in order to compute the UV texture-space
65/// coordinates of (and thus to apply a material onto) a primitive surface.
66class SurfaceInfoT
67{
68    public:
69
70    /// The default constructor.
71    SurfaceInfoT();
72
73    /// The constructor for creating a SurfaceInfoT in plane projection mode, matching the given plane.
74    SurfaceInfoT(const Plane3fT& Plane, bool FaceAligned);
75
76    /// Named constructor for loading a SurfaceInfoT from a cmap file.
77    static SurfaceInfoT Create_cmap(TextParserT& TP);
78
79
80    /// Serializes this instance into a cmap file.
81    void Save_cmap(std::ostream& OutFile) const;
82
83    /// Resets the texture-space u- and v-axes as appropriate for the given plane.
84    /// @param Plane         The plane with reference to which the axes are reset.
85    /// @param FaceAligned   When true, the axes are re-initialized face-aligned, world-aligned otherwise.
86    void ResetUVAxes(const Plane3fT& Plane, bool FaceAligned);
87
88    /// Wraps the Trans[] members so that they are in the interval [0, 1[.
89    void WrapTranslations();
90
91    /// Rotates the texture-space u- and v-axes by the given angle.
92    /// @param Angle   The angle of rotation, in degrees.
93    void RotateUVAxes(float Angle);
94
95    /// Changes this SurfaceInfoT so that the material is aligned on the surface according to AlignKey.
96    /// @param AlignKey   How the material is aligned wrt. the surface. Valid keys are "top", "bottom", "left", "right", "center" and "fit".
97    /// @param Vertices   The vertices of the surface for which the alignment is to be computed.
98    void AlignMaterial(const char* AlignKey, const ArrayT<Vector3fT>& Vertices);
99
100
101    TexCoordGenModeT TexCoordGenMode;   ///< Determines the algorithm that is used to generate texture-coordinates for the associated map primitive.
102    float            Trans[2];
103    float            Scale[2];
104    float            Rotate;
105    Vector3fT        UAxis;
106    Vector3fT        VAxis;
107    float            LightmapScale;
108};
109
110#endif
Note: See TracBrowser for help on using the browser.