root/OpenSceneGraph/trunk/src/osg/Shape.cpp @ 13041

Revision 13041, 3.4 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13#include <osg/Shape>
14#include <algorithm>
15
16using namespace osg;
17
18Shape::~Shape()
19{
20}
21
22ShapeVisitor::~ShapeVisitor()
23{
24}
25
26ConstShapeVisitor::~ConstShapeVisitor()
27{
28}
29
30Sphere::~Sphere()
31{
32}
33
34Box::~Box()
35{
36}
37
38Cone::~Cone()
39{
40}
41
42Cylinder::~Cylinder()
43{
44}
45
46Capsule::~Capsule()
47{
48}
49
50InfinitePlane::~InfinitePlane()
51{
52}
53
54TriangleMesh::~TriangleMesh()
55{
56}
57
58ConvexHull::~ConvexHull()
59{
60}
61
62HeightField::HeightField():
63    _columns(0),
64    _rows(0),
65    _origin(0.0f,0.0f,0.0f),
66    _dx(1.0f),
67    _dy(1.0f),
68    _skirtHeight(0.0f),
69    _borderWidth(0)
70{
71    _heights = new osg::FloatArray;
72}
73
74HeightField::HeightField(const HeightField& mesh,const CopyOp& copyop):
75    Shape(mesh,copyop),
76    _columns(mesh._columns),
77    _rows(mesh._rows),
78    _origin(mesh._origin),
79    _dx(mesh._dx),
80    _dy(mesh._dy),
81    _skirtHeight(mesh._skirtHeight),
82    _borderWidth(mesh._borderWidth),
83    _heights(new osg::FloatArray(*mesh._heights))
84{
85}
86
87HeightField::~HeightField()
88{
89}
90
91
92void HeightField::allocate(unsigned int numColumns,unsigned int numRows)
93{
94    if (_columns!=numColumns || _rows!=numRows)
95    {
96        _heights->resize(numColumns*numRows);
97    }
98    _columns=numColumns;
99    _rows=numRows;
100}
101
102Vec3 HeightField::getNormal(unsigned int c,unsigned int r) const
103{
104    // four point normal generation.
105   float dz_dx;
106    if (c==0)
107    {
108        dz_dx = (getHeight(c+1,r)-getHeight(c,r))/getXInterval();
109    }
110    else if (c==getNumColumns()-1)
111    {
112        dz_dx = (getHeight(c,r)-getHeight(c-1,r))/getXInterval();
113    }
114    else // assume 0<c<_numColumns-1
115    {
116        dz_dx = 0.5f*(getHeight(c+1,r)-getHeight(c-1,r))/getXInterval();
117    }
118
119    float dz_dy;
120    if (r==0)
121    {
122        dz_dy = (getHeight(c,r+1)-getHeight(c,r))/getYInterval();
123    }
124    else if (r==getNumRows()-1)
125    {
126        dz_dy = (getHeight(c,r)-getHeight(c,r-1))/getYInterval();
127    }
128    else // assume 0<r<_numRows-1
129    {
130        dz_dy = 0.5f*(getHeight(c,r+1)-getHeight(c,r-1))/getYInterval();
131    }
132
133    Vec3 normal(-dz_dx,-dz_dy,1.0f);
134    normal.normalize();
135
136    return normal;
137}
138
139Vec2 HeightField::getHeightDelta(unsigned int c,unsigned int r) const
140{
141     // four point height generation.
142    Vec2 heightDelta;
143    if (c==0)
144    {
145        heightDelta.x() = (getHeight(c+1,r)-getHeight(c,r));
146    }
147    else if (c==getNumColumns()-1)
148    {
149        heightDelta.x() = (getHeight(c,r)-getHeight(c-1,r));
150    }
151    else // assume 0<c<_numColumns-1
152    {
153        heightDelta.x() = 0.5f*(getHeight(c+1,r)-getHeight(c-1,r));
154    }
155
156    if (r==0)
157    {
158        heightDelta.y() = (getHeight(c,r+1)-getHeight(c,r));
159    }
160    else if (r==getNumRows()-1)
161    {
162        heightDelta.y() = (getHeight(c,r)-getHeight(c,r-1));
163    }
164    else // assume 0<r<_numRows-1
165    {
166        heightDelta.y() = 0.5f*(getHeight(c,r+1)-getHeight(c,r-1));
167    }
168
169    return heightDelta;
170}
171
172CompositeShape::~CompositeShape()
173{
174}
Note: See TracBrowser for help on using the browser.