Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenFlipper-Free
OpenFlipper
Commits
0b8fb87a
Commit
0b8fb87a
authored
Nov 24, 2017
by
Weizhen Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extend the materialNode class with refractive materials
parent
d539e524
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
50 deletions
+47
-50
libs_required/ACG/GL/GLState.cc
libs_required/ACG/GL/GLState.cc
+27
-27
libs_required/ACG/Scenegraph/MaterialNode.cc
libs_required/ACG/Scenegraph/MaterialNode.cc
+7
-7
libs_required/ACG/Scenegraph/MaterialNode.hh
libs_required/ACG/Scenegraph/MaterialNode.hh
+13
-16
No files found.
libs_required/ACG/GL/GLState.cc
View file @
0b8fb87a
...
...
@@ -134,7 +134,7 @@ GLState::GLState(bool _updateGL, bool _compatibilityProfile)
glheight_
(
2
),
near_plane_
(
1.0
),
far_plane_
(
100.0
),
multisampling_
(
false
),
multisampling_
(
false
),
allow_multisampling_
(
true
),
mipmapping_
(
true
),
updateGL_
(
_updateGL
),
...
...
@@ -198,9 +198,9 @@ void GLState::initialize()
// Get max number of texture units
GLint
value
;
glGetIntegerv
(
GL_MAX_TEXTURE_IMAGE_UNITS_ARB
,
&
value
);
num_texture_units_
=
value
;
// lighting
set_twosided_lighting
(
true
);
}
...
...
@@ -399,8 +399,8 @@ void GLState::set_modelview(const GLMatrixd& _m, const GLMatrixd& _inv_m)
void
GLState
::
ortho
(
double
_left
,
double
_right
,
double
_bottom
,
double
_top
,
double
_n
,
double
_f
)
double
_bottom
,
double
_top
,
double
_n
,
double
_f
)
{
near_plane_
=
_n
;
far_plane_
=
_f
;
...
...
@@ -422,8 +422,8 @@ void GLState::ortho( double _left, double _right,
void
GLState
::
frustum
(
double
_left
,
double
_right
,
double
_bottom
,
double
_top
,
double
_n
,
double
_f
)
double
_bottom
,
double
_top
,
double
_n
,
double
_f
)
{
near_plane_
=
_n
;
far_plane_
=
_f
;
...
...
@@ -445,7 +445,7 @@ void GLState::frustum( double _left, double _right,
void
GLState
::
perspective
(
double
_fovY
,
double
_aspect
,
double
_n
,
double
_f
)
double
_n
,
double
_f
)
{
near_plane_
=
_n
;
far_plane_
=
_f
;
...
...
@@ -467,8 +467,8 @@ void GLState::perspective( double _fovY, double _aspect,
void
GLState
::
viewport
(
int
_left
,
int
_bottom
,
int
_width
,
int
_height
,
int
_glwidth
,
int
_glheight
)
int
_width
,
int
_height
,
int
_glwidth
,
int
_glheight
)
{
left_
=
_left
;
bottom_
=
_bottom
;
...
...
@@ -512,8 +512,8 @@ void GLState::viewport( int _left, int _bottom,
void
GLState
::
lookAt
(
const
Vec3d
&
_eye
,
const
Vec3d
&
_center
,
const
Vec3d
&
_up
)
const
Vec3d
&
_center
,
const
Vec3d
&
_up
)
{
modelview_
.
lookAt
(
_eye
,
_center
,
_up
);
inverse_modelview_
.
inverse_lookAt
(
_eye
,
_center
,
_up
);
...
...
@@ -530,7 +530,7 @@ void GLState::lookAt( const Vec3d& _eye,
void
GLState
::
translate
(
double
_x
,
double
_y
,
double
_z
,
MultiplyFrom
_mult_from
)
MultiplyFrom
_mult_from
)
{
if
(
_mult_from
==
MULT_FROM_RIGHT
)
{
...
...
@@ -561,7 +561,7 @@ void GLState::translate( Vec3d _vector,
void
GLState
::
rotate
(
double
_angle
,
double
_x
,
double
_y
,
double
_z
,
MultiplyFrom
_mult_from
)
MultiplyFrom
_mult_from
)
{
if
(
_mult_from
==
MULT_FROM_RIGHT
)
{
...
...
@@ -586,7 +586,7 @@ void GLState::rotate( double _angle, double _x, double _y, double _z,
void
GLState
::
scale
(
double
_sx
,
double
_sy
,
double
_sz
,
MultiplyFrom
_mult_from
)
MultiplyFrom
_mult_from
)
{
if
(
_mult_from
==
MULT_FROM_RIGHT
)
{
...
...
@@ -611,7 +611,7 @@ void GLState::scale( double _sx, double _sy, double _sz,
void
GLState
::
mult_matrix
(
const
GLMatrixd
&
_m
,
const
GLMatrixd
&
_inv_m
,
MultiplyFrom
_mult_from
)
MultiplyFrom
_mult_from
)
{
if
(
_mult_from
==
MULT_FROM_RIGHT
)
{
...
...
@@ -764,7 +764,7 @@ void GLState::set_shininess(float _shininess)
if
(
updateGL_
&&
compatibilityProfile_
)
{
makeCurrent
();
glMaterialf
(
GL_FRONT_AND_BACK
,
GL_SHININESS
,
_shininess
);
glMaterialf
(
GL_FRONT_AND_BACK
,
GL_SHININESS
,
std
::
min
(
128.
f
,
_shininess
)
)
;
}
}
...
...
@@ -891,7 +891,7 @@ Vec3d GLState::eye() const
Vec3d
GLState
::
viewing_direction
(
int
_x
,
int
_y
)
const
{
Vec3d
dir
=
(
unproject
(
Vec3d
(
_x
,
_y
,
1.0
))
-
unproject
(
Vec3d
(
_x
,
_y
,
0.0
))
);
unproject
(
Vec3d
(
_x
,
_y
,
0.0
))
);
dir
.
normalize
();
return
dir
;
}
...
...
@@ -903,7 +903,7 @@ Vec3d GLState::viewing_direction(int _x, int _y) const
Vec3d
GLState
::
up
()
const
{
Vec3d
dir
(
unproject
(
Vec3d
(
0.5
*
width_
,
height_
-
1
,
0.0
))
-
unproject
(
Vec3d
(
0.5
*
width_
,
0.5
*
height_
,
0.0
))
);
unproject
(
Vec3d
(
0.5
*
width_
,
0.5
*
height_
,
0.0
))
);
dir
.
normalize
();
return
dir
;
}
...
...
@@ -915,7 +915,7 @@ Vec3d GLState::up() const
Vec3d
GLState
::
right
()
const
{
Vec3d
dir
(
unproject
(
Vec3d
(
width_
-
1
,
0.5
*
height_
,
0.0
))
-
unproject
(
Vec3d
(
0.5
*
width_
,
0.5
*
height_
,
0.0
))
);
unproject
(
Vec3d
(
0.5
*
width_
,
0.5
*
height_
,
0.0
))
);
dir
.
normalize
();
return
dir
;
}
...
...
@@ -925,7 +925,7 @@ Vec3d GLState::right() const
void
GLState
::
viewing_ray
(
int
_x
,
int
_y
,
Vec3d
&
_origin
,
Vec3d
&
_direction
)
const
Vec3d
&
_origin
,
Vec3d
&
_direction
)
const
{
_origin
=
unproject
(
Vec3d
(
_x
,
_y
,
0.0
));
_direction
=
unproject
(
Vec3d
(
_x
,
_y
,
1.0
))
-
_origin
;
...
...
@@ -1338,7 +1338,7 @@ void GLState::syncFromGL()
if
(
glIsEnabled
(
caps
[
i
]))
stateStack_
.
back
().
glStateEnabled_
.
set
(
caps
[
i
]);
else
stateStack_
.
back
().
glStateEnabled_
.
reset
(
caps
[
i
]);
}
GLint
getparam
;
#ifdef GL_VERSION_1_4
...
...
@@ -1364,9 +1364,9 @@ void GLState::syncFromGL()
glGetIntegerv
(
GL_BLEND_EQUATION_RGB
,
&
getparam
);
stateStack_
.
back
().
blendEquationState_
=
getparam
;
glGetFloatv
(
GL_BLEND_COLOR
,
stateStack_
.
back
().
blendColorState_
);
glGetIntegerv
(
GL_ALPHA_TEST_FUNC
,
&
getparam
);
stateStack_
.
back
().
alphaFuncState_
=
getparam
;
...
...
@@ -1381,7 +1381,7 @@ void GLState::syncFromGL()
GLenum
bufGets
[
8
]
=
{
GL_ARRAY_BUFFER_BINDING
,
GL_ARRAY_BUFFER
,
GL_ELEMENT_ARRAY_BUFFER_BINDING
,
GL_ELEMENT_ARRAY_BUFFER
,
GL_ELEMENT_ARRAY_BUFFER_BINDING
,
GL_ELEMENT_ARRAY_BUFFER
,
GL_PIXEL_PACK_BUFFER_BINDING
,
GL_PIXEL_PACK_BUFFER
,
GL_PIXEL_UNPACK_BUFFER_BINDING
,
GL_PIXEL_UNPACK_BUFFER
};
...
...
@@ -1452,7 +1452,7 @@ void GLState::syncFromGL()
GL_TEXTURE_COORD_ARRAY_SIZE
,
GL_TEXTURE_COORD_ARRAY_TYPE
,
GL_TEXTURE_COORD_ARRAY_STRIDE
,
GL_TEXTURE_COORD_ARRAY_POINTER
};
GLStateContext
::
GLVertexPointer
*
ptrs
[]
=
{
&
stateStack_
.
back
().
vertexPointer_
,
GLStateContext
::
GLVertexPointer
*
ptrs
[]
=
{
&
stateStack_
.
back
().
vertexPointer_
,
&
stateStack_
.
back
().
colorPointer_
,
&
stateStack_
.
back
().
texcoordPointer_
};
for
(
int
i
=
0
;
i
<
3
;
++
i
)
...
...
@@ -1743,7 +1743,7 @@ void GLState::depthRange(GLclampd _zNear, GLclampd _zFar)
{
if
(
!
depthRangeLock_
)
{
#ifdef GLSTATE_AVOID_REDUNDANT_GLCALLS
#ifdef GLSTATE_AVOID_REDUNDANT_GLCALLS
if
(
abs
(
_zNear
-
stateStack_
.
back
().
depthRange_
[
0
])
>
1e-6
||
abs
(
_zFar
-
stateStack_
.
back
().
depthRange_
[
1
])
>
1e-6
)
#endif
...
...
libs_required/ACG/Scenegraph/MaterialNode.cc
View file @
0b8fb87a
...
...
@@ -141,9 +141,9 @@ QString Material::serializeToJson() const {
matMap
[
"specularColor"
]
=
col2vl
(
specularColor_
);
matMap
[
"overlayColor"
]
=
col2vl
(
overlayColor_
);
matMap
[
"shininess"
]
=
shininess_
;
matMap
[
"illum"
]
=
illum_
;
matMap
[
"reflectance"
]
=
reflectance_
;
matMap
[
"indexOfRefraction"
]
=
indexOfRefraction_
;
matMap
[
"isRefractive"
]
=
isRefractive_
;
matMap
[
"pointSize"
]
=
pointSize_
;
matMap
[
"lineWidth"
]
=
lineWidth_
;
matMap
[
"roundPoints"
]
=
roundPoints_
;
...
...
@@ -179,9 +179,9 @@ void Material::deserializeFromVariantMap(const QVariantMap &matMap) {
if
(
matMap
.
contains
(
"specularColor"
))
specularColor_
=
vl2col
(
matMap
[
"specularColor"
].
toList
());
if
(
matMap
.
contains
(
"overlayColor"
))
overlayColor_
=
vl2col
(
matMap
[
"overlayColor"
].
toList
());
if
(
matMap
.
contains
(
"shininess"
))
shininess_
=
matMap
[
"shininess"
].
toFloat
();
if
(
matMap
.
contains
(
"illum"
))
illum_
=
matMap
[
"illum"
].
toInt
();
if
(
matMap
.
contains
(
"reflectance"
))
reflectance_
=
matMap
[
"reflectance"
].
toDouble
();
if
(
matMap
.
contains
(
"indexOfRefraction"
))
indexOfRefraction_
=
matMap
[
"indexOfRefraction"
].
toDouble
();
if
(
matMap
.
contains
(
"isRefractive"
))
isRefractive_
=
matMap
[
"isRefractive"
].
toBool
();
if
(
matMap
.
contains
(
"pointSize"
))
pointSize_
=
matMap
[
"pointSize"
].
toFloat
();
if
(
matMap
.
contains
(
"lineWidth"
))
lineWidth_
=
matMap
[
"lineWidth"
].
toFloat
();
if
(
matMap
.
contains
(
"roundPoints"
))
roundPoints_
=
matMap
[
"roundPoints"
].
toBool
();
...
...
@@ -484,7 +484,7 @@ MaterialNode::read(std::istream& _is)
char
s
[
200
];
float
x
,
y
,
z
,
u
;
int
i
;
bool
b
;
while
(
_is
&&
(
!
_is
.
eof
())
&&
_is
.
getline
(
s
,
200
)
)
{
std
::
istringstream
buffer
(
s
);
...
...
@@ -546,12 +546,12 @@ MaterialNode::read(std::istream& _is)
material_
.
shininess
(
x
);
}
}
//
Illumination model
else
if
(
specifier
==
"
Illum
"
)
{
buffer
>>
i
;
//
Refractive
else
if
(
specifier
==
"
isRefractive
"
)
{
buffer
>>
b
;
if
(
buffer
.
good
())
{
material_
.
illum
(
i
);
material_
.
set_refractive
(
b
);
}
}
// OverlayColor
...
...
libs_required/ACG/Scenegraph/MaterialNode.hh
View file @
0b8fb87a
...
...
@@ -95,9 +95,9 @@ public:
specularColor_
(
GLState
::
default_specular_color
),
overlayColor_
(
GLState
::
default_overlay_color
),
shininess_
(
GLState
::
default_shininess
),
illum_
(
0
),
reflectance_
(
0.0
),
indexOfRefraction_
(
1.0
),
isRefractive_
(
false
),
pointSize_
(
1.0
),
lineWidth_
(
1.0
),
roundPoints_
(
false
),
...
...
@@ -122,9 +122,9 @@ public:
specularColor_
(
_m
.
specularColor_
),
overlayColor_
(
_m
.
overlayColor_
),
shininess_
(
_m
.
shininess_
),
illum_
(
_m
.
illum_
),
reflectance_
(
_m
.
reflectance_
),
indexOfRefraction_
(
_m
.
indexOfRefraction_
),
isRefractive_
(
_m
.
isRefractive_
),
pointSize_
(
_m
.
pointSize_
),
lineWidth_
(
_m
.
lineWidth_
),
roundPoints_
(
_m
.
roundPoints_
),
...
...
@@ -211,23 +211,20 @@ public:
/// get shininess
float
shininess
()
const
{
return
shininess_
;
}
/// set illumnation model
void
illum
(
int
_m
)
{
illum_
=
_m
;
}
/// get illumination model
int
illum
()
const
{
return
illum_
;
}
/// set reflectance ( not used in OpenGL Rendering)
void
reflectance
(
double
_m
)
{
reflectance_
=
_m
;
}
/// get reflectance ( not used in OpenGL Rendering)
double
reflectance
()
const
{
return
reflectance_
;
}
/// set index of refraction
void
indexOfRefraction
(
double
_m
)
{
indexOfRefraction_
=
_m
;
}
/// get index of refraction ( not used in OpenGL Rendering)
double
indexOfRefraction
()
const
{
return
indexOfRefraction_
;
}
bool
isRefractive
()
const
{
return
illum_
==
4
||
illum_
==
6
||
illum_
==
7
||
illum_
==
9
;}
/// set refractive flag
void
set_refractive
(
bool
_r
)
{
isRefractive_
=
_r
;
}
/// get refractive flag
bool
isRefractive
()
const
{
return
isRefractive_
;}
/// set point size (default: 1.0)
void
pointSize
(
float
_sz
)
{
pointSize_
=
_sz
;
}
...
...
@@ -302,7 +299,7 @@ public:
/// disable backface culling (not active by default, see applyProperties)
void
disableBackfaceCulling
()
{
backfaceCulling_
=
false
;
}
bool
isEmissive
()
const
{
return
baseColor_
[
0
]
>
0.
f
||
baseColor_
[
1
]
>
0.
f
||
baseColor_
[
2
]
>
0.
f
;
}
bool
isEmissive
()
const
{
return
(
baseColor_
[
0
]
>
0.
f
||
baseColor_
[
1
]
>
0.
f
||
baseColor_
[
2
]
>
0.
f
)
;
}
protected:
...
...
@@ -313,9 +310,9 @@ protected:
Vec4f
overlayColor_
;
float
shininess_
;
int
illum_
;
double
reflectance_
;
double
indexOfRefraction_
;
bool
isRefractive_
;
float
pointSize_
;
float
lineWidth_
;
...
...
@@ -470,11 +467,6 @@ public:
/// get shininess
float
shininess
()
const
{
return
material_
.
shininess
();
}
/// set illumination model
void
set_illum
(
int
_m
)
{
material_
.
illum
(
_m
);
}
/// get illumination model
int
illum
()
const
{
return
material_
.
illum
();
}
/// set reflectance
void
set_reflectance
(
double
_m
)
{
material_
.
reflectance
(
_m
);
}
/// get reflectance
...
...
@@ -485,6 +477,11 @@ public:
/// get index of refraction
double
indexOfRefraction
()
const
{
return
material_
.
indexOfRefraction
();
}
/// set refractive flag
void
set_refractive
(
bool
_r
)
{
material_
.
isRefractive_
=
_r
;
}
/// get refractive flag
bool
isRefractive
()
const
{
return
material_
.
isRefractive_
;}
/** @} */
//===========================================================================
...
...
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