Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
   Copyright (c) 2015 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _SPHERE_3D_H_
#define _SPHERE_3D_H_

#include "Geometry/Shapes/Headers/Object3D.h"
#include "Platform/Video/Buffers/VertexBuffer/Headers/VertexBuffer.h"

namespace Divide {

class Sphere3D : public Object3D {
   public:
    /// Change resolution to affect the spacing between vertices
    Sphere3D(F32 radius, F32 resolution)
        : Object3D(ObjectType::SPHERE_3D, ObjectFlag::OBJECT_FLAG_NONE),
          _radius(radius),
          _resolution(resolution)
    {
        _dirty = true;
        _vertexCount = resolution * resolution;
        getGeometryVB()->reservePositionCount(_vertexCount);
        getGeometryVB()->reserveNormalCount(_vertexCount);
        getGeometryVB()->getTexcoord().reserve(_vertexCount);
        getGeometryVB()->reserveIndexCount(_vertexCount);
        if (_vertexCount + 1 > std::numeric_limits<U16>::max()) {
            getGeometryVB()->useLargeIndices(true);
        }
        clean();
    }

    virtual ~Sphere3D() {}
    inline F32 getRadius() { return _radius; }
    inline F32 getResolution() { return _resolution; }
    inline void setRadius(F32 radius) {
        _radius = radius;
        _dirty = true;
        getGeometryVB()->queueRefresh();
    }
    inline void setResolution(F32 resolution) {
        _resolution = resolution;
        _dirty = true;
        getGeometryVB()->queueRefresh();
    }

    virtual bool computeBoundingBox(SceneGraphNode& sgn) {
        if (sgn.getBoundingBoxConst().isComputed()) {
            return true;
        }
        sgn.getBoundingBox().set(vec3<F32>(-_radius), vec3<F32>(_radius));
        return SceneNode::computeBoundingBox(sgn);
    }

    bool onDraw(const RenderStage& currentStage) {
        clean();
        return Object3D::onDraw(currentStage);
    }

    bool onDraw(SceneGraphNode& sgn, const RenderStage& currentStage) {
        clean();
        return Object3D::onDraw(sgn, currentStage);
    }

   protected:
    void clean() {
        if (_dirty) {
            createSphere(_resolution, _resolution);
            _dirty = false;
        }
    }

   private:
    // SuperBible stuff
    void createSphere(U32 slices, U32 stacks) {
        getGeometryVB()->Reset();
        F32 drho = M_PI / (F32)stacks;
        F32 dtheta = 2.0f * M_PI / (F32)slices;
        F32 ds = 1.0f / (F32)slices;
        F32 dt = 1.0f / (F32)stacks;
        F32 t = 1.0f;
        F32 s = 0.0f;
        U32 i, j;  // Looping variables
        U32 index = 0;  /// for the index buffer

        for (i = 0; i < stacks; i++) {
            F32 rho = i * drho;
            F32 srho = std::sin(rho);
            F32 crho = std::cos(rho);
            F32 srhodrho = std::sin(rho + drho);
            F32 crhodrho = std::cos(rho + drho);

            // Many sources of OpenGL sphere drawing code uses a triangle fan
            // for the caps of the sphere. This however introduces texturing
            // artifacts at the poles on some OpenGL implementations
            s = 0.0f;
            for (j = 0; j <= slices; j++) {
                F32 theta = (j == slices) ? 0.0f : j * dtheta;
                F32 stheta = -std::sin(theta);
                F32 ctheta = std::cos(theta);

                F32 x = stheta * srho;
                F32 y = ctheta * srho;
                F32 z = crho;

                getGeometryVB()->addPosition(
                    vec3<F32>(x * _radius, y * _radius, z * _radius));
                getGeometryVB()->getTexcoord().push_back(vec2<F32>(s, t));
                getGeometryVB()->addNormal(vec3<F32>(x, y, z));
                getGeometryVB()->addIndex(index++);

                x = stheta * srhodrho;
                y = ctheta * srhodrho;
                z = crhodrho;
                s += ds;

                getGeometryVB()->addPosition(
                    vec3<F32>(x * _radius, y * _radius, z * _radius));
                getGeometryVB()->getTexcoord().push_back(vec2<F32>(s, t - dt));
                getGeometryVB()->addNormal(vec3<F32>(x, y, z));
                getGeometryVB()->addIndex(index++);
            }
            t -= dt;
        }

        vec2<U32> indiceLimits;
        for (i = 0; i < getGeometryVB()->getIndexCount(); i++) {
            if (indiceLimits.x > getGeometryVB()->getIndex(i))
                indiceLimits.x = getGeometryVB()->getIndex(i);
            if (indiceLimits.y < getGeometryVB()->getIndex(i))
                indiceLimits.y = getGeometryVB()->getIndex(i);
        }

        getGeometryVB()->Create();
    }

   protected:
    F32 _radius, _resolution;
    U32 _vertexCount;
    bool _dirty;
};

};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Geometry/Shapes/Headers/Predefined/Sphere3D.h

Diff revisions: vs.
Revision Author Commited Message
365 Diff Diff IonutCava picture IonutCava Sun 08 Mar, 2015 21:26:10 +0000

[Ionut]
- More enum-related type safety changes

364 Diff Diff IonutCava picture IonutCava Fri 06 Mar, 2015 16:55:21 +0000

[Ionut]
- Part 1 of type safe enum replacement (does not compile)

354 Diff Diff IonutCava picture IonutCava Fri 20 Feb, 2015 17:17:37 +0000

[Ionut]
- Replaced GLEW with glbinding (requires a CEGUI recompile. It currently crashes)
- Replaced most “SceneGraphNode* const sgn” expressions with "SceneGraphNode& sgn"
- Replaced some pointers to kernel to references to kernel
- Fixed compilation issues with EASTL
- Removed NPOT -> POT texture conversion code. Modern GPUs handle NPOT textures perfectly fine

350 Diff Diff IonutCava picture IonutCava Tue 10 Feb, 2015 16:25:39 +0000

[Ionut]
- Simplified some Util-namespace level functions by using STL algorithms where possible
- Formatted the entire codebase using clang-format with the following style: "{BasedOnStyle: Google, IndentWidth: 4}"
- Attempted to make ProfileTimer thread-safe (temp fix until std::chrono works properly in Visual Studio)

343 Diff Diff IonutCava picture IonutCava Thu 15 Jan, 2015 17:30:12 +0000

[Ionut]
- Refactored 2 singletons into static classes (Console and TerrainLoader)
- Changed some C-casts to static_casts
- Updated copyright notices

337 Diff Diff IonutCava picture IonutCava Wed 17 Dec, 2014 17:25:16 +0000

[Ionut]
- Replaced all tabs with 4 spaces (some spacing may be off now. no way to check all the files.)
- Moved implementation details for ParamHandler, BoundingBox, BoundingSphere and ProfileTimer to proper .inl and .cpp files. (more to follow)
- Update all forward declared enums with the required storage type (as requested by the C++11 standard)

334 Diff Diff IonutCava picture IonutCava Wed 10 Dec, 2014 17:21:22 +0000

[Ionut]
- Reorganized the Hardware project and renamed to "Platform"
- Reorganized the Server project

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

279 IonutCava picture IonutCava Sat 28 Jun, 2014 16:20:46 +0000

[Ionut][[BR]]
- Unified draw command system into GenericDrawCommand [[BR]]
- Fixed double VB creation in Object3D [[BR]]
- Reworked triangle data computation (now Object3D’s responsibility) [[BR]]
- VertexArrays can now render using the primitive type specified in the draw command instead of the fixed type specified at creation [[BR]]
- Optimized terrain shader [[BR]]