Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
7b351f94
Commit
7b351f94
authored
Apr 13, 2010
by
schurade
Browse files
[ADD] some functions to the triangle mesh class
parent
ef840dc6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
0 deletions
+93
-0
src/graphicsEngine/WTriangleMesh2.cpp
src/graphicsEngine/WTriangleMesh2.cpp
+47
-0
src/graphicsEngine/WTriangleMesh2.h
src/graphicsEngine/WTriangleMesh2.h
+46
-0
No files found.
src/graphicsEngine/WTriangleMesh2.cpp
View file @
7b351f94
...
...
@@ -158,6 +158,12 @@ osg::Vec3 WTriangleMesh2::getVertex( size_t index ) const
return
(
*
m_verts
)[
index
];
}
osg
::
Vec4
WTriangleMesh2
::
getVertColor
(
size_t
index
)
const
{
WAssert
(
index
<
m_countVerts
,
"get vertex: index out of range"
);
return
(
*
m_vertColors
)[
index
];
}
wmath
::
WPosition
WTriangleMesh2
::
getVertexAsPosition
(
size_t
index
)
const
{
WAssert
(
index
<
m_countVerts
,
"get vertex as position: index out of range"
);
...
...
@@ -362,6 +368,10 @@ void WTriangleMesh2::doLoopSubD()
}
delete
[]
newVertexPositions
;
(
*
m_vertNormals
).
resize
(
(
*
m_verts
).
size
()
);
(
*
m_vertColors
).
resize
(
(
*
m_verts
).
size
()
);
m_meshDirty
=
true
;
}
...
...
@@ -538,3 +548,40 @@ size_t WTriangleMesh2::loopGetThirdVert( size_t coVert1, size_t coVert2, size_t
return
getTriVertId2
(
triangleNum
);
}
void
WTriangleMesh2
::
addMesh
(
boost
::
shared_ptr
<
WTriangleMesh2
>
mesh
,
float
xOff
,
float
yOff
,
float
zOff
)
{
size_t
oldVertSize
=
m_countVerts
;
(
*
m_vertColors
).
resize
(
oldVertSize
+
mesh
->
vertSize
()
);
for
(
size_t
i
=
0
;
i
<
mesh
->
vertSize
();
++
i
)
{
osg
::
Vec3
v
(
mesh
->
getVertex
(
i
)
);
v
[
0
]
+=
xOff
;
v
[
1
]
+=
yOff
;
v
[
2
]
+=
zOff
;
addVertex
(
v
);
setVertexColor
(
oldVertSize
+
i
,
mesh
->
getVertColor
(
i
)
);
}
for
(
size_t
i
=
0
;
i
<
mesh
->
triangleSize
();
++
i
)
{
addTriangle
(
mesh
->
getTriVertId0
(
i
)
+
oldVertSize
,
mesh
->
getTriVertId1
(
i
)
+
oldVertSize
,
mesh
->
getTriVertId2
(
i
)
+
oldVertSize
);
}
m_meshDirty
=
true
;
}
void
WTriangleMesh2
::
translateMesh
(
float
xOff
,
float
yOff
,
float
zOff
)
{
osg
::
Vec3
t
(
xOff
,
yOff
,
zOff
);
for
(
size_t
i
=
0
;
i
<
(
*
m_verts
).
size
();
++
i
)
{
(
*
m_verts
)[
i
]
+=
t
;
}
}
void
WTriangleMesh2
::
zoomMesh
(
float
zoom
)
{
for
(
size_t
i
=
0
;
i
<
(
*
m_verts
).
size
();
++
i
)
{
(
*
m_verts
)[
i
]
*=
zoom
;
}
}
src/graphicsEngine/WTriangleMesh2.h
View file @
7b351f94
...
...
@@ -118,6 +118,14 @@ public:
*/
void
addTriangle
(
osg
::
Vec3
vert0
,
osg
::
Vec3
vert1
,
osg
::
Vec3
vert2
);
/**
* sets a vertex to a new position
*
* \param index
* \param vert
*/
void
setVertex
(
size_t
index
,
osg
::
Vec3
vert
);
/**
* sets the normal for a given vertex
*
...
...
@@ -203,6 +211,14 @@ public:
*/
osg
::
Vec3
getVertex
(
size_t
index
)
const
;
/**
* getter
*
* \param index
* \return color
*/
osg
::
Vec4
getVertColor
(
size_t
index
)
const
;
/**
* getter
*
...
...
@@ -272,6 +288,32 @@ public:
*/
size_t
getTriVertId2
(
size_t
triId
)
const
;
/**
* adds a mesh to the existing, no check for duplicate vertexes is performed, an additional
* vector may be specified to move the mesh to add
*
* \param mesh
* \param xOff
* \param yOff
* \param zOff
*/
void
addMesh
(
boost
::
shared_ptr
<
WTriangleMesh2
>
mesh
,
float
xOff
=
0.
,
float
yOff
=
0.
,
float
zOff
=
0.
);
/**
* moves the entire mesh to a new postion
*
* \param xOff
* \param yOff
* \param zOff
*/
void
translateMesh
(
float
xOff
,
float
yOff
,
float
zOff
);
/**
* multiplies the vertex vectors of the mesh with a given number
*
* \param zoom
*/
void
zoomMesh
(
float
zoom
);
protected:
static
boost
::
shared_ptr
<
WPrototyped
>
m_prototype
;
//!< The prototype as singleton.
...
...
@@ -548,5 +590,9 @@ inline size_t WTriangleMesh2::getTriVertId2( size_t triId ) const
return
m_triangles
[
triId
*
3
+
2
];
}
inline
void
WTriangleMesh2
::
setVertex
(
size_t
index
,
osg
::
Vec3
vert
)
{
(
*
m_verts
)[
index
]
=
vert
;
}
#endif // WTRIANGLEMESH2_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment