Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CAMP
campvis-public
Commits
5ec0bdce
Commit
5ec0bdce
authored
Jan 27, 2014
by
Oliver Zettinig
Browse files
Added generic arrow GeometryDataFactory
parent
2693e463
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/datastructures/geometrydatafactory.cpp
View file @
5ec0bdce
...
...
@@ -230,4 +230,113 @@ namespace campvis {
return
toReturn
;
}
MultiIndexedGeometry
*
GeometryDataFactory
::
createArrow
(
uint16_t
numSlices
,
float
tipLen
,
float
cylRadius
,
float
tipRadius
)
{
tgtAssert
(
numSlices
>
2
,
"Arrow shaft must have minimum 3 slices!"
);
tgtAssert
(
tipRadius
>
cylRadius
,
"Tip radius must exceed cyclinder radius (for correct normals)!"
);
tgtAssert
(
tipLen
>
0
&&
tipLen
<
1
,
"Tip length must be between 0 and 1!"
);
std
::
vector
<
tgt
::
vec3
>
vertices
;
std
::
vector
<
tgt
::
vec3
>
normals
;
// add bottom vertex
vertices
.
push_back
(
tgt
::
vec3
(
0.
f
,
0.
f
,
0.
f
));
normals
.
push_back
(
tgt
::
vec3
(
0.
f
,
0.
f
,
-
1.
f
));
// add shaft floor vertices
for
(
int
i
=
0
;
i
<
numSlices
;
++
i
)
{
float
theta
=
static_cast
<
float
>
(
i
)
*
2.
f
*
tgt
::
PIf
/
static_cast
<
float
>
(
numSlices
);
vertices
.
push_back
(
tgt
::
vec3
(
cylRadius
*
cos
(
theta
),
cylRadius
*
sin
(
theta
),
0.
f
));
normals
.
push_back
(
tgt
::
vec3
(
0.
f
,
0.
f
,
-
1.
f
));
}
for
(
int
i
=
0
;
i
<
numSlices
;
++
i
)
{
float
theta
=
static_cast
<
float
>
(
i
)
*
2.
f
*
tgt
::
PIf
/
static_cast
<
float
>
(
numSlices
);
vertices
.
push_back
(
tgt
::
vec3
(
cylRadius
*
cos
(
theta
),
cylRadius
*
sin
(
theta
),
0.
f
));
normals
.
push_back
(
tgt
::
vec3
(
cos
(
theta
),
sin
(
theta
),
0.
f
));
}
// add shaft top vertices
for
(
int
i
=
0
;
i
<
numSlices
;
++
i
)
{
float
theta
=
static_cast
<
float
>
(
i
)
*
2.
f
*
tgt
::
PIf
/
static_cast
<
float
>
(
numSlices
);
vertices
.
push_back
(
tgt
::
vec3
(
cylRadius
*
cos
(
theta
),
cylRadius
*
sin
(
theta
),
1.
f
-
tipLen
));
normals
.
push_back
(
tgt
::
vec3
(
cos
(
theta
),
sin
(
theta
),
0.
f
));
}
for
(
int
i
=
0
;
i
<
numSlices
;
++
i
)
{
float
theta
=
static_cast
<
float
>
(
i
)
*
2.
f
*
tgt
::
PIf
/
static_cast
<
float
>
(
numSlices
);
vertices
.
push_back
(
tgt
::
vec3
(
cylRadius
*
cos
(
theta
),
cylRadius
*
sin
(
theta
),
1.
f
-
tipLen
));
normals
.
push_back
(
tgt
::
vec3
(
0.
f
,
0.
f
,
-
1.
f
));
}
// add arrow tip outer cone vertices
for
(
int
i
=
0
;
i
<
numSlices
;
++
i
)
{
float
theta
=
static_cast
<
float
>
(
i
)
*
2.
f
*
tgt
::
PIf
/
static_cast
<
float
>
(
numSlices
);
vertices
.
push_back
(
tgt
::
vec3
(
tipRadius
*
cos
(
theta
),
tipRadius
*
sin
(
theta
),
1.
f
-
tipLen
));
normals
.
push_back
(
tgt
::
vec3
(
0.
f
,
0.
f
,
-
1.
f
));
}
float
phi
=
atan2f
(
tipRadius
,
tipLen
);
for
(
int
i
=
0
;
i
<
numSlices
;
++
i
)
{
float
theta
=
static_cast
<
float
>
(
i
)
*
2.
f
*
tgt
::
PIf
/
static_cast
<
float
>
(
numSlices
);
vertices
.
push_back
(
tgt
::
vec3
(
tipRadius
*
cos
(
theta
),
tipRadius
*
sin
(
theta
),
1.
f
-
tipLen
));
normals
.
push_back
(
tgt
::
vec3
(
cos
(
theta
)
*
cos
(
phi
),
sin
(
theta
)
*
cos
(
phi
),
sin
(
phi
)));
}
// add top vertex
vertices
.
push_back
(
tgt
::
vec3
(
0.
f
,
0.
f
,
1.
f
));
normals
.
push_back
(
tgt
::
vec3
(
0.
f
,
0.
f
,
1.
f
));
// create geometry
MultiIndexedGeometry
*
toReturn
=
new
MultiIndexedGeometry
(
vertices
,
std
::
vector
<
tgt
::
vec3
>
(),
std
::
vector
<
tgt
::
vec4
>
(),
normals
);
// add indices for primitives to geometry:
{
// cylinder floor
std
::
vector
<
uint16_t
>
indices
;
for
(
uint16_t
j
=
0
;
j
<
numSlices
;
++
j
)
{
indices
.
push_back
(
0
);
indices
.
push_back
(
j
+
1
);
}
indices
.
push_back
(
0
);
indices
.
push_back
(
1
);
toReturn
->
addPrimitive
(
indices
);
}
{
// cylinder shaft
std
::
vector
<
uint16_t
>
indices
;
for
(
uint16_t
j
=
0
;
j
<
numSlices
;
++
j
)
{
indices
.
push_back
(
j
+
1
+
numSlices
);
indices
.
push_back
(
j
+
1
+
numSlices
*
2
);
}
indices
.
push_back
(
1
+
numSlices
);
indices
.
push_back
(
1
+
numSlices
*
2
);
toReturn
->
addPrimitive
(
indices
);
}
{
// arrow tip bottom area
std
::
vector
<
uint16_t
>
indices
;
for
(
uint16_t
j
=
0
;
j
<
numSlices
;
++
j
)
{
indices
.
push_back
(
j
+
1
+
numSlices
*
3
);
indices
.
push_back
(
j
+
1
+
numSlices
*
4
);
}
indices
.
push_back
(
1
+
numSlices
*
3
);
indices
.
push_back
(
1
+
numSlices
*
4
);
toReturn
->
addPrimitive
(
indices
);
}
{
// arrow tip cone
uint16_t
m
=
(
uint16_t
)
vertices
.
size
()
-
1
;
std
::
vector
<
uint16_t
>
indices
;
for
(
uint16_t
j
=
0
;
j
<
numSlices
;
++
j
)
{
indices
.
push_back
(
j
+
1
+
numSlices
*
5
);
indices
.
push_back
(
m
);
}
indices
.
push_back
(
1
+
numSlices
*
5
);
indices
.
push_back
(
m
);
toReturn
->
addPrimitive
(
indices
);
}
return
toReturn
;
}
}
\ No newline at end of file
core/datastructures/geometrydatafactory.h
View file @
5ec0bdce
...
...
@@ -68,11 +68,22 @@ namespace campvis {
/**
* Creates an MultiIndexedGeometry storing a unit sphere around the origin.
* \param
llf
Number of stacks in the sphere
* \param
urb
Number of slices in the sphere
* \param
numStacks
Number of stacks in the sphere
* \param
numSlices
Number of slices in the sphere
* \return MultiIndexedGeometry storing a unit sphere around the origin.
*/
static
MultiIndexedGeometry
*
createSphere
(
uint16_t
numStacks
=
6
,
uint16_t
numSlices
=
12
);
/**
* Creates an MultiIndexedGeometry storing a unit length arrow in Z direction starting from the origin.
* \param numSlices Number of slices in the cylinder and cone
* \param tipLen Length of arrow tip (between 0 and 1)
* \param cylRadius Radius of the cylinder (arrow shaft)
* \param tipRadius Radius of the bottom of the arrow tip
* \return MultiIndexedGeometry storing a unit arrow in Z direction starting from the origin.
*/
static
MultiIndexedGeometry
*
createArrow
(
uint16_t
numSlices
=
12
,
float
tipLen
=
0.35
,
float
cylRadius
=
0.05
,
float
tipRadius
=
0.15
);
};
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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