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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
* Copyright (C) 2021 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2021 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-dsp-units
* Created on: 9 авг. 2021 г.
*
* lsp-dsp-units is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-dsp-units is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-dsp-units. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LSP_PLUG_IN_DSP_UNITS_3D_OBJECT3D_H_
#define LSP_PLUG_IN_DSP_UNITS_3D_OBJECT3D_H_
#include <lsp-plug.in/dsp-units/version.h>
#include <lsp-plug.in/dsp-units/3d/types.h>
#include <lsp-plug.in/dsp-units/3d/Scene3D.h>
#include <lsp-plug.in/dsp/dsp.h>
#include <lsp-plug.in/common/types.h>
#include <lsp-plug.in/common/status.h>
#include <lsp-plug.in/runtime/LSPString.h>
#include <lsp-plug.in/lltl/parray.h>
namespace lsp
{
namespace dspu
{
class Scene3D;
/** One scene object in the 3D space
*
*/
class LSP_DSP_UNITS_PUBLIC Object3D
{
private:
Object3D(const Object3D &);
Object3D & operator = (const Object3D &);
protected:
LSPString sName;
lltl::parray<obj_triangle_t> vTriangles;
dsp::matrix3d_t sMatrix;
bool bVisible;
Scene3D *pScene;
obj_boundbox_t sBoundBox;
dsp::point3d_t sCenter;
friend class Scene3D;
protected:
/** Default constructor
*
*/
explicit Object3D(Scene3D *scene, const LSPString *name);
/** Destructor
*
*/
~Object3D();
protected:
void calc_bound_box(const obj_vertex_t *v);
obj_edge_t *register_edge(obj_vertex_t *v0, obj_vertex_t *v1);
public:
/** Destroy object's contents
*
*/
void destroy();
/**
* Compute additional parameters after loading
*/
void post_load();
/** Add triangle
*
* @param face_id unique face identifier
* @param v1 index of vertex 1, non-negative
* @param v2 index of vertex 2, non-negative
* @param v3 index of vertex 3, non-negative
* @param vn1 index of normal 1, can be negative
* @param vn2 index of normal 2, can be negative
* @param vn3 index of normal 3, can be negative
* @return status of operation
*/
status_t add_triangle(
ssize_t face_id,
ssize_t v1, ssize_t v2, ssize_t v3,
ssize_t vn1=-1, ssize_t vn2=-1, ssize_t vn3=-1
);
/** Add triangle
*
* @param vv array of three vertex indexes
* @param vn array of three normal indexes
* @return status of operation
*/
status_t add_triangle(ssize_t *vv, ssize_t *vn);
/**
* Return number of triangles
* @return number of triangles
*/
inline size_t num_triangles() const { return vTriangles.size(); }
/**
* Get triangle
* @param index triangle index
* @return pointer to triangle or NULL
*/
inline obj_triangle_t *triangle(size_t index) { return vTriangles.get(index); }
/** Add triangle
*
* @param vv array of three vertex indexes
* @return status of operation
*/
status_t add_triangle(ssize_t *vv);
/** Check if object is visible
*
* @return true if object is visible
*/
inline bool is_visible() const
{
return bVisible;
}
/** Set object visible
*
* @param visible visibility flag
*/
inline void set_visible(bool visible)
{
bVisible = visible;
}
/**
* Get name of object
* @param name pointer to store name
* @return true on success
*/
inline bool get_name(LSPString *name) const { return name->set(&sName); }
/**
* Get name of object in UTF-8 character set
* @return name of object in UTF-8 character set
*/
inline const char *get_name() const { return sName.get_utf8(); }
/**
* Get bounding box
* @return pointer to bounding box
*/
inline obj_boundbox_t *bound_box() { return &sBoundBox; }
/**
* Get bounding box (const version)
* @return pointer to bounding box
*/
inline const obj_boundbox_t *bound_box() const { return &sBoundBox; }
/**
* Get bounding box
* @return pointer to bounding box
*/
inline dsp::point3d_t *center() { return &sCenter; }
/**
* Get bounding box (const version)
* @return pointer to bounding box
*/
inline const dsp::point3d_t *center() const { return &sCenter; }
/**
* Get the scene the object relates to
* @return the scene the object relates to
*/
inline Scene3D *scene() { return pScene; }
/** Get object transformation matrix
*
* @return object transformation matrix
*/
inline dsp::matrix3d_t *matrix() { return &sMatrix; }
/**
* Compute bounding box
*/
void calc_bound_box();
};
}
}
#endif /* LSP_PLUG_IN_DSP_UNITS_3D_OBJECT3D_H_ */
|