File: RenderablePivot.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (63 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download | duplicates (3)
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
#pragma once

#include "render/RenderableGeometry.h"

#include "math/Vector3.h"
#include "math/Vector4.h"

namespace render
{

class RenderablePivot :
	public RenderableGeometry
{
private:
	const Vector3& _pivot;
    bool _needsUpdate;

public:
    // Pass a reference to the pivot is in world coordinates
    RenderablePivot(const Vector3& pivot) :
        _pivot(pivot),
        _needsUpdate(true)
    {}

    void queueUpdate()
    {
        _needsUpdate = true;
    }

protected:
    void updateGeometry() override
    {
        if (!_needsUpdate) return;

        _needsUpdate = false;

        static const Vector4 ColourX{ 255, 0, 0, 255 };
        static const Vector4 ColourY{ 0, 255, 0, 255 };
        static const Vector4 ColourZ{ 0, 0, 255, 255 };

        std::vector<RenderVertex> vertices;

        vertices.push_back(RenderVertex(_pivot, { 0, 0, 0 }, { 0, 0 }, ColourX));
        vertices.push_back(RenderVertex(_pivot + Vector3(16, 0, 0), { 0, 0, 0 }, { 0, 0 }, ColourX));

        vertices.push_back(RenderVertex(_pivot, { 0, 0, 0 }, { 0, 0 }, ColourY));
        vertices.push_back(RenderVertex(_pivot + Vector3(0, 16, 0), { 0, 0, 0 }, { 0, 0 }, ColourY));

        vertices.push_back(RenderVertex(_pivot, { 0, 0, 0 }, { 0, 0 }, ColourZ));
        vertices.push_back(RenderVertex(_pivot + Vector3(0, 0, 16), { 0, 0, 0 }, { 0, 0 }, ColourZ));

        static std::vector<unsigned int> Indices =
        {
            0, 1,
            2, 3,
            4, 5
        };

        updateGeometryWithData(GeometryType::Lines, vertices, Indices);
    }
};

}