many micro-optimizations

This commit is contained in:
cxgeorge 2001-05-24 03:29:47 +00:00
parent 4ec6f610d0
commit ca7d33480a
27 changed files with 495 additions and 346 deletions

View File

@ -66,7 +66,8 @@ xform(const LMatrix4f &mat) {
_center = _center * mat;
// We'll take just the length of the y axis as the matrix's scale.
LVector3f y = mat.get_row3(1);
LVector3f y;
mat.get_row3(y,1);
float factor_squared = y.length_squared();
LODSwitchVector::iterator si;

View File

@ -185,7 +185,7 @@ internal_compare_to(const NodeTransition *other) const {
// For now, we compare componentwise. It makes paranoid_wrt more
// sensible, and it doesn't seem to make a big different to
// performance.
return _matrix.compare_to(ot->_matrix, 0.00001);
return _matrix.compare_to(ot->_matrix, 0.00001f);
// Uncomment this line instead to compare matrices pointerwise.
// return this - other;
@ -201,7 +201,7 @@ internal_compare_to(const NodeTransition *other) const {
template<class Matrix>
void MatrixTransition<Matrix>::
internal_generate_hash(GraphHashGenerator &hash) const {
_matrix.generate_hash(hash, 0.00001);
_matrix.generate_hash(hash, 0.00001f);
}
////////////////////////////////////////////////////////////////////

View File

@ -13,15 +13,33 @@ TypeHandle GuiLabel::_type_handle;
void GuiLabel::recompute_transform(void) {
this->freeze();
switch (_type) {
case SIMPLE_TEXT:
{
/*
LMatrix4f mat = LMatrix4f::scale_mat(LVector3f::rfu(_scale_x, _scale_y,
_scale_z)) *
LMatrix4f::scale_mat(_scale) *
LMatrix4f::scale_mat(LVector3f::rfu((_mirror_x?-1.:1.), 1.,
(_mirror_y?-1.:1.))) *
LMatrix4f::scale_mat(LVector3f::rfu((_mirror_x?-1.0f:1.0f), 1.0f,
(_mirror_y?-1.0f:1.0f))) *
LMatrix4f::translate_mat(_pos);
*/
// optimize the above calculation
LVector3f scalevec1 = LVector3f::rfu(_scale_x*_scale, _scale_y*_scale, _scale_z*_scale);
LVector3f scalevec2 = LVector3f::rfu((_mirror_x?-1.0f:1.0f),
1.0f,
(_mirror_y?-1.0f:1.0f));
scalevec1._v.v._0 *= scalevec2._v.v._0;
scalevec1._v.v._1 *= scalevec2._v.v._1;
scalevec1._v.v._2 *= scalevec2._v.v._2;
LMatrix4f mat(scalevec1._v.v._0, 0.0f, 0.0f, 0.0f,
0.0f, scalevec1._v.v._1, 0.0f, 0.0f,
0.0f, 0.0f, scalevec1._v.v._2, 0.0f,
_pos._v.v._0, _pos._v.v._1, _pos._v.v._2, 1.0f);
switch (_type) {
case SIMPLE_TEXT:
{
TextNode* n = DCAST(TextNode, _geom);
n->set_transform(mat);
}
@ -30,12 +48,6 @@ void GuiLabel::recompute_transform(void) {
case SIMPLE_CARD:
case L_NULL:
{
LMatrix4f mat = LMatrix4f::scale_mat(LVector3f::rfu(_scale_x, _scale_y,
_scale_z)) *
LMatrix4f::scale_mat(_scale) *
LMatrix4f::scale_mat(LVector3f::rfu((_mirror_x?-1.:1.), 1.,
(_mirror_y?-1.:1.))) *
LMatrix4f::translate_mat(_pos);
_internal->set_transition(new TransformTransition(mat));
}
break;
@ -43,12 +55,26 @@ void GuiLabel::recompute_transform(void) {
{
float w=_have_width?_scale*_width:_scale;
float h=_have_height?_scale*_height:_scale;
/*
LMatrix4f mat = LMatrix4f::scale_mat(LVector3f::rfu(_scale_x, _scale_y,
_scale_z)) *
LMatrix4f::scale_mat(LVector3f::rfu(w, 1., h)) *
LMatrix4f::scale_mat(LVector3f::rfu((_mirror_x?-1.:1.), 1.,
(_mirror_y?-1.:1.))) *
LMatrix4f::scale_mat(LVector3f::rfu(w, 1.0f, h)) *
LMatrix4f::scale_mat(LVector3f::rfu((_mirror_x?-1.0f:1.0f), 1.0f,
(_mirror_y?-1.0f:1.0f))) *
LMatrix4f::translate_mat(_pos + _model_pos);
*/
// optimize above calculation
LVector3f scalevec3 = LVector3f::rfu(w, 1.0f, h);
mat._m.m._00 *= scalevec3._v.v._0;
mat._m.m._11 *= scalevec3._v.v._1;
mat._m.m._22 *= scalevec3._v.v._2;
mat._m.m._30 += _model_pos._v.v._0;
mat._m.m._31 += _model_pos._v.v._1;
mat._m.m._32 += _model_pos._v.v._2;
_internal->set_transition(new TransformTransition(mat));
}
break;
@ -83,7 +109,7 @@ void GuiLabel::set_properties(void) {
float h = v[3] - v[2];
if (_have_width) {
w = _width - w;
w *= 0.5;
w *= 0.5f;
v[1] += w;
v[0] -= w;
} else {
@ -92,7 +118,7 @@ void GuiLabel::set_properties(void) {
}
if (_have_height) {
h = _height - h;
h *= 0.5;
h *= 0.5f;
v[3] += h;
v[2] -= h;
} else {
@ -118,7 +144,7 @@ void GuiLabel::set_properties(void) {
if (_have_foreground) {
_internal->set_transition(new ColorTransition(_foreground));
TransparencyProperty::Mode mode;
if (_foreground[3] != 1.)
if (_foreground[3] != 1.0f)
mode = TransparencyProperty::M_alpha;
else
mode = TransparencyProperty::M_none;
@ -126,13 +152,13 @@ void GuiLabel::set_properties(void) {
}
{
float w, h;
w = _have_width?(_width * 0.5):0.5;
h = _have_height?(_height * 0.5):0.5;
w = _have_width?(_width * 0.5f):0.5f;
h = _have_height?(_height * 0.5f):0.5f;
PTA_Vertexf verts;
verts.push_back(Vertexf::rfu(-w, 0., h));
verts.push_back(Vertexf::rfu(-w, 0., -h));
verts.push_back(Vertexf::rfu(w, 0., h));
verts.push_back(Vertexf::rfu(w, 0., -h));
verts.push_back(Vertexf::rfu(-w, 0.0f, h));
verts.push_back(Vertexf::rfu(-w, 0.0f, -h));
verts.push_back(Vertexf::rfu(w, 0.0f, h));
verts.push_back(Vertexf::rfu(w, 0.0f, -h));
_gset->set_coords(verts, G_PER_VERTEX);
}
break;
@ -174,33 +200,33 @@ GuiLabel* GuiLabel::make_simple_texture_label(Texture* texture) {
if (xs > ys) {
// horizontally dominant
ratio = ((float)ys) / ((float)xs);
ratio *= 0.5;
l = -0.5;
r = 0.5;
ratio *= 0.5f;
l = -0.5f;
r = 0.5f;
b = -ratio;
t = ratio;
} else {
// vertically dominant
ratio = ((float)xs) / ((float)ys);
ratio *= 0.5;
ratio *= 0.5f;
l = -ratio;
r = ratio;
b = -0.5;
t = 0.5;
b = -0.5f;
t = 0.5f;
}
}
verts.push_back(Vertexf::rfu(l, 0., t));
verts.push_back(Vertexf::rfu(l, 0., b));
verts.push_back(Vertexf::rfu(r, 0., t));
verts.push_back(Vertexf::rfu(r, 0., b));
verts.push_back(Vertexf::rfu(l, 0.0f, t));
verts.push_back(Vertexf::rfu(l, 0.0f, b));
verts.push_back(Vertexf::rfu(r, 0.0f, t));
verts.push_back(Vertexf::rfu(r, 0.0f, b));
geoset->set_num_prims(1);
geoset->set_lengths(lengths);
geoset->set_coords(verts, G_PER_VERTEX);
PTA_TexCoordf uvs;
uvs.push_back(TexCoordf(0., 1.));
uvs.push_back(TexCoordf(0., 0.));
uvs.push_back(TexCoordf(1., 1.));
uvs.push_back(TexCoordf(1., 0.));
uvs.push_back(TexCoordf(0.0f, 1.0f));
uvs.push_back(TexCoordf(0.0f, 0.0f));
uvs.push_back(TexCoordf(1.0f, 1.0f));
uvs.push_back(TexCoordf(1.0f, 0.0f));
geoset->set_texcoords(uvs, G_PER_VERTEX);
n2->add_geom(geoset);
ret->_gset = geoset;
@ -224,8 +250,8 @@ GuiLabel* GuiLabel::make_simple_text_label(const string& text, TextFont* font,
n->set_text(text);
if (tex != (Texture*)0L)
n->set_card_texture(tex);
ret->set_scale(1.);
ret->set_pos(LVector3f(0., 0., 0.));
ret->set_scale(1.0f);
ret->set_pos(LVector3f(0.0f, 0.0f, 0.0f));
ret->recompute_transform();
return ret;
}
@ -242,10 +268,10 @@ GuiLabel* GuiLabel::make_simple_card_label(void) {
PTA_int lengths(0);
lengths.push_back(4);
PTA_Vertexf verts;
verts.push_back(Vertexf::rfu(-0.5, 0., 0.5));
verts.push_back(Vertexf::rfu(-0.5, 0., -0.5));
verts.push_back(Vertexf::rfu(0.5, 0., 0.5));
verts.push_back(Vertexf::rfu(0.5, 0., -0.5));
verts.push_back(Vertexf::rfu(-0.5f, 0.0f, 0.5f));
verts.push_back(Vertexf::rfu(-0.5f, 0.0f, -0.5f));
verts.push_back(Vertexf::rfu(0.5f, 0.0f, 0.5f));
verts.push_back(Vertexf::rfu(0.5f, 0.0f, -0.5f));
geoset->set_num_prims(1);
geoset->set_lengths(lengths);
geoset->set_coords(verts, G_PER_VERTEX);
@ -286,8 +312,8 @@ GuiLabel* GuiLabel::make_model_label(Node* geom, float left, float right,
GuiLabel* ret = new GuiLabel();
ret->_type = MODEL;
ret->_geom = new NamedNode("GUI label");
ret->_model_pos = LVector3f::rfu(-(left + right) * 0.5, 0.,
-(bottom + top) * 0.5);
ret->_model_pos = LVector3f::rfu(-(left + right) * 0.5f, 0.0f,
-(bottom + top) * 0.5f);
ret->_model_width = right - left;
ret->_model_height = top - bottom;
ret->_internal = new RenderRelation(ret->_geom, geom);
@ -365,24 +391,47 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
LVector3f ul, lr;
if (xs > ys) {
// horizontally dominant
ratio = ((float)ys) / ((float)xs);
ratio *= 0.5;
ul = LVector3f::rfu(-0.5, 0., ratio);
lr = LVector3f::rfu(0.5, 0., -ratio);
// horizontally dominant
ratio = ((float)ys) / ((float)xs);
ratio *= 0.5f;
ul = LVector3f::rfu(-0.5f, 0.0f, ratio);
lr = LVector3f::rfu(0.5f, 0.0f, -ratio);
} else {
// vertically dominant
ratio = ((float)xs) / ((float)ys);
ratio *= 0.5;
ul = LVector3f::rfu(-ratio, 0., 0.5);
lr = LVector3f::rfu(ratio, 0., -0.5);
// vertically dominant
ratio = ((float)xs) / ((float)ys);
ratio *= 0.5f;
ul = LVector3f::rfu(-ratio, 0.0f, 0.5f);
lr = LVector3f::rfu(ratio, 0.0f, -0.5f);
}
/*
LMatrix4f mat = LMatrix4f::scale_mat(LVector3f::rfu(_scale_x, _scale_y,
_scale_z)) *
LMatrix4f::scale_mat(_scale) *
LMatrix4f::translate_mat(_pos);
ul = ul * mat;
lr = lr * mat;
ul = ul * mat;
lr = lr * mat;
*/
// optimize above
LVector3f scalevec1 = LVector3f::rfu(_scale_x*_scale, _scale_y*_scale, _scale_z*_scale);
LVector3f scalevec2 = LVector3f::rfu((_mirror_x?-1.0f:1.0f),
1.0f,
(_mirror_y?-1.0f:1.0f));
scalevec1._v.v._0 *= scalevec2._v.v._0;
scalevec1._v.v._1 *= scalevec2._v.v._1;
scalevec1._v.v._2 *= scalevec2._v.v._2;
ul._v.v._0 = scalevec1._v.v._0 * ul._v.v._0 + _pos._v.v._0;
ul._v.v._1 = scalevec1._v.v._1 * ul._v.v._1 + _pos._v.v._1;
ul._v.v._2 = scalevec1._v.v._2 * ul._v.v._2 + _pos._v.v._2;
lr._v.v._0 = scalevec1._v.v._0 * lr._v.v._0 + _pos._v.v._0;
lr._v.v._1 = scalevec1._v.v._1 * lr._v.v._1 + _pos._v.v._1;
lr._v.v._2 = scalevec1._v.v._2 * lr._v.v._2 + _pos._v.v._2;
l = ul.dot(ul.right());
r = lr.dot(lr.right());
b = lr.dot(lr.up());
@ -391,42 +440,42 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
break;
case SIMPLE_CARD:
{
float x = _pos.dot(LVector3f::rfu(1., 0., 0.));
float y = _pos.dot(LVector3f::rfu(0., 0., 1.));
l = _have_width?-(_width*0.5):-0.5;
r = _have_width?(_width*0.5):0.5;
float x = _pos.dot(LVector3f::rfu(1.0f, 0.0f, 0.0f));
float y = _pos.dot(LVector3f::rfu(0.0f, 0.0f, 1.0f));
l = _have_width?-(_width*0.5f):-0.5f;
r = _have_width?(_width*0.5f):0.5f;
l += x;
r += x;
b = _have_height?-(_height*0.5):-0.5;
t = _have_height?(_height*0.5):0.5;
b = _have_height?-(_height*0.5f):-0.5f;
t = _have_height?(_height*0.5f):0.5f;
b += y;
t += y;
}
break;
case L_NULL:
{
float x = _pos.dot(LVector3f::rfu(1., 0., 0.));
float y = _pos.dot(LVector3f::rfu(0., 0., 1.));
l = _have_width?-(_width*0.5):-0.000005;
r = _have_width?(_width*0.5):0.000005;
float x = _pos.dot(LVector3f::rfu(1.0f, 0.0f, 0.0f));
float y = _pos.dot(LVector3f::rfu(0.0f, 0.0f, 1.0f));
l = _have_width?-(_width*0.5f):-0.000005f;
r = _have_width?(_width*0.5f):0.000005f;
l += x;
r += x;
b = _have_height?-(_height*0.5):-0.000005;
t = _have_height?(_height*0.5):0.000005;
b = _have_height?-(_height*0.5f):-0.000005f;
t = _have_height?(_height*0.5f):0.000005f;
b += y;
t += y;
}
break;
case MODEL:
{
float x = _pos.dot(LVector3f::rfu(1., 0., 0.));
float y = _pos.dot(LVector3f::rfu(0., 0., 1.));
l = _have_width?-(_width*_model_width*0.5):-(_model_width*0.5);
r = _have_width?(_width*_model_width*0.5):(_model_width*0.5);
float x = _pos.dot(LVector3f::rfu(1.0f, 0.0f, 0.0f));
float y = _pos.dot(LVector3f::rfu(0.0f, 0.0f, 1.0f));
l = _have_width?-(_width*_model_width*0.5f):-(_model_width*0.5f);
r = _have_width?(_width*_model_width*0.5f):(_model_width*0.5f);
l += x;
r += x;
b = _have_height?-(_height*_model_height*0.5):-(_model_height*0.5);
t = _have_height?(_height*_model_height*0.5):(_model_height*0.5);
b = _have_height?-(_height*_model_height*0.5f):-(_model_height*0.5f);
t = _have_height?(_height*_model_height*0.5f):(_model_height*0.5f);
b += y;
t += y;
}
@ -434,8 +483,8 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) {
default:
gui_cat->warning()
<< "trying to get extents from something I don't know how to" << endl;
l = b = 0.;
r = t = 1.;
l = b = 0.0f;
r = t = 1.0f;
}
}
@ -454,21 +503,21 @@ float GuiLabel::get_width(void) {
break;
case SIMPLE_TEXTURE:
gui_cat->warning() << "tried to get width from a texture label" << endl;
w = 1.;
w = 1.0f;
break;
case SIMPLE_CARD:
w = _have_width?_width:1.;
w = _have_width?_width:1.0f;
break;
case MODEL:
w = _have_width?(_width*_model_width):_model_width;
break;
case L_NULL:
w = _have_width?_width:0.00001;
w = _have_width?_width:0.00001f;
break;
default:
gui_cat->warning()
<< "trying to get width from something I don't know how to" << endl;
w = 1.;
w = 1.0f;
}
return w;
}
@ -488,10 +537,10 @@ float GuiLabel::get_height(void) {
break;
case SIMPLE_TEXTURE:
gui_cat->warning() << "tried to get height from a texture label" << endl;
h = 1.;
h = 1.0f;
break;
case SIMPLE_CARD:
h = _have_height?_height:1.;
h = _have_height?_height:1.0f;
break;
case MODEL:
h = _have_height?(_height*_model_height):_model_height;
@ -502,7 +551,7 @@ float GuiLabel::get_height(void) {
default:
gui_cat->warning()
<< "trying to get height from something I don't know how to" << endl;
h = 1.;
h = 1.0f;
}
return h;
}
@ -513,7 +562,7 @@ void GuiLabel::set_foreground_color(const Colorf& color) {
}
void GuiLabel::set_background_color(const Colorf& color) {
static Colorf zero(0., 0., 0., 0.);
static Colorf zero(0.0f, 0.0f, 0.0f, 0.0f);
_background = color;
_have_background = (color != zero);

View File

@ -134,9 +134,9 @@ bool Spotlight::make_image(Texture* texture, float radius)
float D = dist_from_center;
if (D <= radius)
intensity = 1.0f;
else if (D < 1.0f)
else if (D < 1.0f)
intensity = pow(cos((D-radius) /
(1-radius) * (MathNumbers::pi/2.0f)), _exponent);
(1.0f-radius) * (MathNumbers::pi_f*0.5f)), _exponent);
else
intensity = 0;
@ -176,7 +176,7 @@ make_geometry(float intensity, float length, int num_facets)
diffuse[3] = intensity;
Colorf black(0.0, 0.0, 0.0, intensity);
float radius = length * (float)tan(deg_2_rad(get_cutoff_angle()));
float ang_inc = 6.2831853 / (float)num_facets;
float ang_inc = 2.0f*MathNumbers::pi_f / (float)num_facets;
int num_verts = num_facets + 1;
int num_indices = num_facets + 2;
LVector3f offset(0.0, length, 0.0);

View File

@ -14,7 +14,7 @@ get_num_points() const {
INLINE_MATHUTIL LPoint3f BoundingHexahedron::
get_point(int n) const {
nassertr(n >= 0 && n < num_points, LPoint3f(0.0, 0.0, 0.0));
nassertr(n >= 0 && n < num_points, LPoint3f(0.0f, 0.0f, 0.0f));
return _points[n];
}

View File

@ -19,7 +19,7 @@ BoundingHexahedron(const Frustumf &frustum, bool is_ortho,
cs = default_coordinate_system;
}
float fs = 1.0;
float fs = 1.0f;
if (!is_ortho) {
fs = frustum._ffar / frustum._fnear;
}
@ -54,8 +54,8 @@ make_copy() const {
LPoint3f BoundingHexahedron::
get_min() const {
nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0));
nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0));
nassertr(!is_empty(), LPoint3f(0.0f, 0.0f, 0.0f));
nassertr(!is_infinite(), LPoint3f(0.0f, 0.0f, 0.0f));
int i;
LPoint3f m = _points[0];
for (i = 1; i < num_points; i++) {
@ -68,8 +68,8 @@ get_min() const {
LPoint3f BoundingHexahedron::
get_max() const {
nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0));
nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0));
nassertr(!is_empty(), LPoint3f(0.0f, 0.0f, 0.0f));
nassertr(!is_infinite(), LPoint3f(0.0f, 0.0f, 0.0f));
int i;
LPoint3f m = _points[0];
for (i = 1; i < num_points; i++) {
@ -82,8 +82,8 @@ get_max() const {
LPoint3f BoundingHexahedron::
get_approx_center() const {
nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0));
nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0));
nassertr(!is_empty(), LPoint3f(0.0f, 0.0f, 0.0f));
nassertr(!is_infinite(), LPoint3f(0.0f, 0.0f, 0.0f));
return _centroid;
}
@ -201,7 +201,7 @@ contains_point(const LPoint3f &point) const {
// the planes.
for (int i = 0; i < num_planes; i++) {
const Planef &p = _planes[i];
if (p.dist_to_plane(point) > 0.0) {
if (p.dist_to_plane(point) > 0.0f) {
return IF_no_intersection;
}
}
@ -222,8 +222,8 @@ contains_lineseg(const LPoint3f &a, const LPoint3f &b) const {
// are in front of any one plane.
for (int i = 0; i < num_planes; i++) {
const Planef &p = _planes[i];
if (p.dist_to_plane(a) > 0.0 ||
p.dist_to_plane(b) > 0.0) {
if (p.dist_to_plane(a) > 0.0f ||
p.dist_to_plane(b) > 0.0f) {
return IF_no_intersection;
}
}

View File

@ -18,8 +18,8 @@ make_copy() const {
LPoint3f BoundingLine::
get_approx_center() const {
nassertr(!is_empty(), LPoint3f(0.0, 0.0, 0.0));
nassertr(!is_infinite(), LPoint3f(0.0, 0.0, 0.0));
nassertr(!is_empty(), LPoint3f(0.0f, 0.0f, 0.0f));
nassertr(!is_infinite(), LPoint3f(0.0f, 0.0f, 0.0f));
return (get_point_a() + get_point_b()) / 2.0;
}
@ -94,21 +94,21 @@ contains_sphere(const BoundingSphere *sphere) const {
float BoundingLine::
sqr_dist_to_line(const LPoint3f &point) const {
nassertr(!point.is_nan(), 0.0);
nassertr(!is_empty() && !is_infinite(), 0.0);
nassertr(!_vector.almost_equal(LVector3f(0.0, 0.0, 0.0)), 0.0);
nassertr(!point.is_nan(), 0.0f);
nassertr(!is_empty() && !is_infinite(), 0.0f);
nassertr(!_vector.almost_equal(LVector3f(0.0f, 0.0f, 0.0f)), 0.0f);
// The formula for the distance from a point to the line based on
// the quadratic equation.
float A = dot(_vector, _vector);
nassertr(A != 0.0, 0.0);
nassertr(A != 0.0f, 0.0f);
LVector3f fc = _origin - point;
float B = 2.0 * dot(_vector, fc);
float fc_d2 = dot(fc, fc);
float r2 = fc_d2 - B*B / 4.0*A;
nassertr(!cnan(r2), 0.0);
nassertr(!cnan(r2), 0.0f);
return r2;
}

View File

@ -26,8 +26,8 @@ get_center() const {
INLINE_MATHUTIL float BoundingSphere::
get_radius() const {
nassertr(!is_empty(), 0.0);
nassertr(!is_infinite(), 0.0);
nassertr(!is_empty(), 0.0f);
nassertr(!is_infinite(), 0.0f);
return _radius;
}

View File

@ -285,6 +285,11 @@ write_hprs(Datagram &datagram, const LVecBase3f *array, int length) {
// If quality level is at least 104, we don't even convert hpr at
// all.
vector_float h, p, r;
h.reserve(length);
p.reserve(length);
r.reserve(length);
for (int i = 0; i < length; i++) {
h.push_back(array[i][0]);
p.push_back(array[i][1]);
@ -339,6 +344,11 @@ write_hprs(Datagram &datagram, const LVecBase3f *array, int length) {
vector_float qr, qi, qj, qk;
qr.reserve(length);
qi.reserve(length);
qj.reserve(length);
qk.reserve(length);
for (int i = 0; i < length; i++) {
LMatrix3f mat;
compose_matrix(mat, LVecBase3f(1.0, 1.0, 1.0), array[i]);
@ -371,14 +381,14 @@ write_hprs(Datagram &datagram, const LVecBase3f *array, int length) {
bool success = decompose_matrix(mat2, scale, hpr);
nassertv(success);
if (!array[i].almost_equal(hpr, 0.001) ||
!scale.almost_equal(LVecBase3f(1.0, 1.0, 1.0), 0.001)) {
mathutil_cat.debug()
<< "Converted hpr to quaternion incorrectly!\n"
<< " Source hpr: " << array[i] << "\n"
<< " Quaternion: " << rot << "\n"
<< " Which represents: hpr " << hpr << " scale "
<< scale << "\n";
}
!scale.almost_equal(LVecBase3f(1.0, 1.0, 1.0), 0.001)) {
mathutil_cat.debug()
<< "Converted hpr to quaternion incorrectly!\n"
<< " Source hpr: " << array[i] << "\n"
<< " Quaternion: " << rot << "\n"
<< " Which represents: hpr " << hpr << " scale "
<< scale << "\n";
}
}
qr.push_back(rot.get_r());
@ -452,6 +462,8 @@ read_reals(DatagramIterator &di, vector_float &array) {
int length = di.get_int32();
if (_quality > 100) {
array.reserve(array.size() + length);
// Special case: lossless output.
for (int i = 0; i < length; i++) {
array.push_back(di.get_float32());
@ -530,7 +542,7 @@ read_hprs(DatagramIterator &di, vector_LVecBase3f &array) {
if (okflag) {
nassertr(h.size() == p.size() && p.size() == r.size(), false);
for (int i = 0; i < (int)h.size(); i++) {
array.push_back(LVecBase3f(h[i], p[i], r[i]));
array.push_back(LVecBase3f(h[i], p[i], r[i]));
}
}

View File

@ -10,12 +10,12 @@
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL FLOATNAME(Frustum)::
FLOATNAME(Frustum)() {
_fnear = 1.4142;
_ffar = 10.0;
_l = -1;
_r = 1;
_t = 1;
_b = -1;
_fnear = FLOATCONST(1.4142);
_ffar = FLOATCONST(10.0);
_l = -1.0f;
_r = 1.0f;
_t = 1.0f;
_b = -1.0f;
}
////////////////////////////////////////////////////////////////////
@ -24,7 +24,7 @@ FLOATNAME(Frustum)() {
// Description: Sets up a two-dimensional orthographic frustum
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL void FLOATNAME(Frustum)::make_ortho_2D(void) {
make_ortho(-1, 1);
make_ortho(-1.0f, 1.0f);
}
////////////////////////////////////////////////////////////////////
@ -34,7 +34,7 @@ INLINE_MATHUTIL void FLOATNAME(Frustum)::make_ortho_2D(void) {
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL void FLOATNAME(Frustum)::
make_ortho_2D(FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b) {
make_ortho(-1, 1, l, r, t, b);
make_ortho(-1.0f, 1.0f, l, r, t, b);
}
////////////////////////////////////////////////////////////////////
@ -45,10 +45,10 @@ make_ortho_2D(FLOATTYPE l, FLOATTYPE r, FLOATTYPE t, FLOATTYPE b) {
INLINE_MATHUTIL void FLOATNAME(Frustum)::make_ortho(FLOATTYPE fnear, FLOATTYPE ffar) {
_fnear = fnear;
_ffar = ffar;
_l = -1;
_r = 1;
_t = 1;
_b = -1;
_l = -1.0f;
_r = 1.0f;
_t = 1.0f;
_b = -1.0f;
}
////////////////////////////////////////////////////////////////////
@ -94,7 +94,7 @@ make_perspective_hfov(FLOATTYPE hfov, FLOATTYPE aspect, FLOATTYPE fnear,
FLOATTYPE ffar) {
_fnear = fnear;
_ffar = ffar;
_r = tan(deg_2_rad(hfov) * 0.5) * _fnear;
_r = tan(deg_2_rad(hfov) * FLOATCONST(0.5)) * _fnear;
_l = -_r;
_t = _r / aspect;
_b = -_t;
@ -106,7 +106,7 @@ make_perspective_vfov(FLOATTYPE yfov, FLOATTYPE aspect, FLOATTYPE fnear,
FLOATTYPE ffar) {
_fnear = fnear;
_ffar = ffar;
_t = tan(deg_2_rad(yfov) * 0.5) * _fnear;
_t = tan(deg_2_rad(yfov) * 0.5f) * _fnear;
_b = -_t;
_r = _t * aspect;
_l = -_r;
@ -118,9 +118,9 @@ make_perspective(FLOATTYPE xfov, FLOATTYPE yfov, FLOATTYPE fnear,
FLOATTYPE ffar) {
_fnear = fnear;
_ffar = ffar;
_t = tan(deg_2_rad(yfov) * 0.5) * _fnear;
_t = tan(deg_2_rad(yfov) * 0.5f) * _fnear;
_b = -_t;
_r = tan(deg_2_rad(xfov) * 0.5) * _fnear;
_r = tan(deg_2_rad(xfov) * 0.5f) * _fnear;
_l = -_r;
}
@ -132,7 +132,7 @@ make_perspective(FLOATTYPE xfov, FLOATTYPE yfov, FLOATTYPE fnear,
INLINE_MATHUTIL void FLOATNAME(Frustum)::
get_perspective_params(FLOATTYPE& yfov, FLOATTYPE& aspect,
FLOATTYPE& fnear, FLOATTYPE& ffar) const {
yfov = rad_2_deg(atan(_t / _fnear)) * 2.0;
yfov = rad_2_deg(atan(_t / _fnear)) * 2.0f;
aspect = _r / _t;
fnear = _fnear;
ffar = _ffar;
@ -146,7 +146,7 @@ get_perspective_params(FLOATTYPE& yfov, FLOATTYPE& aspect,
INLINE_MATHUTIL void FLOATNAME(Frustum)::
get_perspective_params(FLOATTYPE& xfov, FLOATTYPE& yfov, FLOATTYPE& aspect,
FLOATTYPE& fnear, FLOATTYPE& ffar) const {
xfov = rad_2_deg(atan(_r / _fnear)) * 2.0;
xfov = rad_2_deg(atan(_r / _fnear)) * 2.0f;
get_perspective_params(yfov, aspect, fnear, ffar);
}
@ -163,25 +163,39 @@ get_perspective_projection_mat(CoordinateSystem cs) const {
cs = default_coordinate_system;
}
FLOATTYPE a = (2.0 * _fnear) / (_r - _l);
FLOATTYPE recip_far_minus_near = 1.0f/(_ffar - _fnear);
FLOATTYPE recip_r_minus_l = 1.0f/(_r - _l);
FLOATTYPE recip_t_minus_b = 1.0f/(_t - _b);
FLOATTYPE two_fnear = 2.0f*_fnear;
FLOATTYPE d = (_r + _l) * recip_r_minus_l;
FLOATTYPE a = two_fnear * recip_r_minus_l;
FLOATTYPE e = two_fnear * recip_t_minus_b;
FLOATTYPE b = (_t + _b) * recip_t_minus_b;
FLOATTYPE c = (_ffar + _fnear) * recip_far_minus_near;
FLOATTYPE f = -_ffar * two_fnear * recip_far_minus_near;
/*
FLOATTYPE a = (2.0f * _fnear) / (_r - _l);
FLOATTYPE b = (_t + _b) / (_t - _b);
FLOATTYPE c = (_ffar + _fnear) / (_ffar - _fnear);
FLOATTYPE d = (_r + _l) / (_r - _l);
FLOATTYPE e = (2.0 * _fnear) / (_t - _b);
FLOATTYPE f = (-2.0 * _ffar * _fnear) / (_ffar - _fnear);
FLOATTYPE e = (2.0f * _fnear) / (_t - _b);
FLOATTYPE f = (-2.0f * _ffar * _fnear) / (_ffar - _fnear);
*/
switch (cs) {
case CS_zup_right:
return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0,
0.0, -b, c, 1.0,
d, e, 0.0, 0.0,
0.0, 0.0, f, 0.0);
return FLOATNAME(LMatrix4)( a, 0.0f, 0.0f, 0.0f,
0.0f, -b, c, 1.0f,
d, e, 0.0f, 0.0f,
0.0f, 0.0f, f, 0.0f);
case CS_yup_right:
return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0,
0.0, e, 0.0, 0.0,
d, b, -c,-1.0,
0.0, 0.0, f, 0.0);
return FLOATNAME(LMatrix4)( a, 0.0f, 0.0f, 0.0f,
0.0f, e, 0.0f, 0.0f,
d, b, -c,-1.0f,
0.0f, 0.0f, f, 0.0f);
case CS_zup_left:
return FLOATNAME(LMatrix4)::convert_mat(CS_zup_right, CS_zup_left) *
@ -210,24 +224,32 @@ get_ortho_projection_mat(CoordinateSystem cs) const {
if (cs == CS_default) {
cs = default_coordinate_system;
}
FLOATTYPE a = 2.0 / (_r - _l);
FLOATTYPE b = 2.0 / (_t - _b);
FLOATTYPE c = 2.0 / (_ffar - _fnear);
FLOATTYPE d = (_r + _l) / (_r - _l);
FLOATTYPE a = 2.0f / (_r - _l);
FLOATTYPE b = 2.0f / (_t - _b);
FLOATTYPE c = 2.0f / (_ffar - _fnear);
FLOATTYPE d = (_r + _l) * a * 0.5f;
FLOATTYPE e = (_t + _b) * b * 0.5f;
FLOATTYPE f = (_ffar + _fnear) * c * 0.5f;
/*
FLOATTYPE a = 2.0f / (_r - _l);
FLOATTYPE b = 2.0f / (_t - _b);
FLOATTYPE c = 2.0f / (_ffar - _fnear);
FLOATTYPE d = (_r + _l) / (_r + _l)
FLOATTYPE e = (_t + _b) / (_t - _b);
FLOATTYPE f = (_ffar + _fnear) / (_ffar - _fnear);
*/
switch (cs) {
case CS_zup_right:
return FLOATNAME(LMatrix4)::convert_mat(CS_yup_right, CS_zup_right) *
get_ortho_projection_mat(CS_yup_right);
case CS_yup_right:
return FLOATNAME(LMatrix4)( a, 0.0, 0.0, 0.0,
0.0, b, 0.0, 0.0,
0.0, 0.0, -c, 0.0,
-d, -e, -f, 1.0);
return FLOATNAME(LMatrix4)( a, 0.0f, 0.0f, 0.0f,
0.0f, b, 0.0f, 0.0f,
0.0f, 0.0f, -c, 0.0f,
-d, -e, -f, 1.0f);
case CS_zup_left:
return FLOATNAME(LMatrix4)::convert_mat(CS_zup_right, CS_zup_left) *

View File

@ -28,7 +28,7 @@ make_copy() const {
////////////////////////////////////////////////////////////////////
LPoint3f OmniBoundingVolume::
get_approx_center() const {
return LPoint3f(0.0, 0.0, 0.0);
return LPoint3f(0.0f, 0.0f, 0.0f);
}
////////////////////////////////////////////////////////////////////

View File

@ -12,10 +12,10 @@
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL FLOATNAME(Plane)::
FLOATNAME(Plane)(void) {
_a = 0.0;
_b = 0.0;
_c = 1.0;
_d = 0.0;
_a = 0.0f;
_b = 0.0f;
_c = 1.0f;
_d = 0.0f;
}
////////////////////////////////////////////////////////////////////
@ -166,9 +166,9 @@ intersects_line(FLOATNAME(LPoint3) &intersection_point,
// function returns false and leaves t undefined. If
// there is an intersection with the plane, the function
// returns true and sets t to the parametric value that
// defines the point of intersection. That is, t == 0.0
// defines the point of intersection. That is, t == 0.0f
// implies that the intersection occurred exactly at
// point from, and t == 1.0 implies at point from +
// point from, and t == 1.0f implies at point from +
// delta, with other values of t accordingly.
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL bool FLOATNAME(Plane)::

View File

@ -35,13 +35,13 @@ FLOATNAME(LPoint3) FLOATNAME(Plane)::
get_point() const {
// Choose the denominator based on the largest axis in the normal.
if (cabs(_a) >= cabs(_b) && cabs(_a) >= cabs(_c)) {
nassertr(_a != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0));
return FLOATNAME(LPoint3)(-_d / _a, 0.0, 0.0);
nassertr(_a != 0.0f, FLOATNAME(LPoint3)(0.0f, 0.0f, 0.0f));
return FLOATNAME(LPoint3)(-_d / _a, 0.0f, 0.0f);
} else if (cabs(_b) >= cabs(_c)) {
nassertr(_b != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0));
return FLOATNAME(LPoint3)(0.0, -_d / _b, 0.0);
nassertr(_b != 0.0f, FLOATNAME(LPoint3)(0.0f, 0.0f, 0.0f));
return FLOATNAME(LPoint3)(0.0f, -_d / _b, 0.0f);
} else {
nassertr(_c != 0.0, FLOATNAME(LPoint3)(0.0, 0.0, 0.0));
return FLOATNAME(LPoint3)(0.0, 0.0, -_d / _c);
nassertr(_c != 0.0f, FLOATNAME(LPoint3)(0.0f, 0.0f, 0.0f));
return FLOATNAME(LPoint3)(0.0f, 0.0f, -_d / _c);
}
}

View File

@ -21,13 +21,13 @@ _rotate_to(FLOATNAME(LMatrix3) &mat,
if (sin_theta < 0.0001) {
// The vectors are collinear.
if (cos_theta < 0.0) {
if (cos_theta < 0.0f) {
// The vectors are opposite; choose an arbitrary axis
// perpendicular to a.
FLOATNAME(LVector3) absa(fabs(a[0]), fabs(a[1]), fabs(a[2]));
FLOATNAME(LVector3) lca(0., 0., 0.);
lca[absa[0]<=absa[1] ? absa[0]<=absa[2] ? 0 : 2
: absa[1]<=absa[2] ? 1 : 2] = 1.0;
: absa[1]<=absa[2] ? 1 : 2] = 1.0f;
axis = normalize(a.cross(lca));
} else {
@ -44,7 +44,7 @@ _rotate_to(FLOATNAME(LMatrix3) &mat,
FLOATTYPE y = axis[1];
FLOATTYPE z = axis[2];
FLOATTYPE t = 1.0 - cos_theta;
FLOATTYPE t = 1.0f - cos_theta;
mat(0, 0) = t * x * x + cos_theta;
mat(0, 1) = t * x * y + sin_theta * z;

View File

@ -11,8 +11,8 @@
int
main() {
/*
LVector3d a(1.0, 0.0, 0.0);
LVector3d b = normalize(LVector3d(0.5, 0.5, 0.0));
LVector3d a(1.0f, 0.0f, 0.0f);
LVector3d b = normalize(LVector3d(0.5, 0.5, 0.0f));
LMatrix3d rot;
rotate_to(rot, a, b);

View File

@ -19,7 +19,7 @@ BaseParticleRenderer(ParticleRendererAlphaMode alpha_mode) :
_alpha_mode(PR_NOT_INITIALIZED_YET) {
_render_node = new GeomNode("BaseParticleRenderer render node");
_user_alpha = 1.0;
_user_alpha = 1.0f;
update_alpha_mode(alpha_mode);
}

View File

@ -65,7 +65,7 @@ make_copy(void) {
void DiscEmitter::
assign_initial_position(LPoint3f& pos) {
// position
float theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi;
float theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
_distance_from_center = NORMALIZED_RAND();
float r_scalar = _distance_from_center * _radius;
@ -99,7 +99,7 @@ assign_initial_velocity(LVector3f& vel) {
}
// velocity
float vel_z = mag * sinf(aoe * (MathNumbers::pi / 180.0f));
float vel_z = mag * sinf(deg_2_rad(aoe));
float abs_diff = fabs((mag * mag) - (vel_z * vel_z));
float root_mag_minus_z_squared = sqrtf(abs_diff);
float vel_x = _cosf_theta * root_mag_minus_z_squared;

View File

@ -56,7 +56,7 @@ make_copy(void) {
////////////////////////////////////////////////////////////////////
void RingEmitter::
assign_initial_position(LPoint3f& pos) {
float theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi;
float theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
_cos_theta = cosf(theta);
_sin_theta = sinf(theta);
@ -73,7 +73,7 @@ assign_initial_position(LPoint3f& pos) {
////////////////////////////////////////////////////////////////////
void RingEmitter::
assign_initial_velocity(LVector3f& vel) {
float vel_z = sinf(_aoe * (MathNumbers::pi / 180.0f));
float vel_z = sinf(deg_2_rad(_aoe));
float abs_diff = fabs(1.0f - (vel_z * vel_z));
float root_mag_minus_z_squared = sqrtf(abs_diff);

View File

@ -56,7 +56,7 @@ assign_initial_position(LPoint3f& pos) {
z = SPREAD(_radius);
r = sqrtf((_radius * _radius) - (z * z));
theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi;
theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
pos.set(r * cosf(theta), r * sinf(theta), z);
}

View File

@ -58,7 +58,7 @@ assign_initial_position(LPoint3f& pos) {
z = SPREAD(_radius);
r = sqrtf((_radius * _radius) - (z * z));
theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi;
theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
t = NORMALIZED_RAND();

View File

@ -52,12 +52,12 @@ make_copy(void) {
////////////////////////////////////////////////////////////////////
void TangentRingEmitter::
assign_initial_position(LPoint3f& pos) {
float theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi;
float theta = NORMALIZED_RAND() * 2.0f * MathNumbers::pi_f;
_x = cosf(theta);
_y = sinf(theta);
pos.set(_radius * _x, _radius * _y, 0);
pos.set(_radius * _x, _radius * _y, 0.0f);
}
////////////////////////////////////////////////////////////////////
@ -67,5 +67,5 @@ assign_initial_position(LPoint3f& pos) {
////////////////////////////////////////////////////////////////////
void TangentRingEmitter::
assign_initial_velocity(LVector3f& vel) {
vel.set(-_y, _x, 0);
vel.set(-_y, _x, 0.0f);
}

View File

@ -87,7 +87,10 @@ transform_changed(NodeRelation *arc) {
arc->get_transition(TransformTransition::get_class_type());
// extract the position
LPoint3f pos = tt->get_matrix().get_row3(3);
LPoint3f pos;
tt->get_matrix().get_row3(pos,3);
// extract the orientation
if (_mass_center->get_oriented() == true) {

View File

@ -61,25 +61,34 @@ sub_render(NodeRelation *arc, const AllAttributesWrapper &,
rel_mat = tt->get_matrix();
}
LVector3f camera_pos = -rel_mat.get_row3(3);
LVector3f up = _up_vector;
LVector3f camera_pos,up;
CoordinateSystem coordsys = gsg->get_coordinate_system();
// If this is an eye-relative Billboard, then (a) the up vector is
// relative to the camera, not to the world, and (b) the look
// direction is towards the plane that contains the camera,
// perpendicular to the forward direction, not directly to the
// camera.
if (_eye_relative) {
up = _up_vector * rel_mat;
camera_pos = LVector3f::forward(gsg->get_coordinate_system()) * rel_mat;
camera_pos = LVector3f::forward(coordsys) * rel_mat;
} else {
// camera_pos= -rel_mat.get_row3(pos,3);
camera_pos._v.v._0 = -rel_mat._m.m._30;
camera_pos._v.v._1 = -rel_mat._m.m._31;
camera_pos._v.v._2 = -rel_mat._m.m._32;
up = _up_vector;
}
// Now determine the rotation matrix for the Billboard.
LMatrix4f rotate;
if (_axial_rotate) {
heads_up(rotate, camera_pos, up, gsg->get_coordinate_system());
heads_up(rotate, camera_pos, up, coordsys);
} else {
look_at(rotate, camera_pos, up, gsg->get_coordinate_system());
look_at(rotate, camera_pos, up, coordsys);
}
// And finally, apply the rotation transform to the set of

View File

@ -254,6 +254,91 @@ clear() {
_head.clear();
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::get_mat
// Access: Public
// Description: Returns the matrix that describes the coordinate
// space of the bottom node, relative to the other
// path's bottom node's coordinate space.
////////////////////////////////////////////////////////////////////
LMatrix4f NodePath::
get_mat(const NodePath &other) const {
NodeTransitionWrapper ntw(TransformTransition::get_class_type());
if (is_empty() && other.is_empty()) {
return LMatrix4f::ident_mat();
} else if (is_empty()) {
wrt(NULL, other.node(), other.begin(), other.end(),
ntw, _graph_type);
} else if (other.is_empty()) {
wrt(node(), begin(), end(), (Node *)NULL, ntw, _graph_type);
} else {
wrt(node(), begin(), end(),
other.node(), other.begin(), other.end(),
ntw, _graph_type);
}
const TransformTransition *tt;
if (!get_transition_into(tt, ntw)) {
// No relative transform.
return LMatrix4f::ident_mat();
} else {
return tt->get_matrix();
}
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_mat
// Access: Public
// Description: Converts the indicated matrix from the other's
// coordinate space to the local coordinate space, and
// applies it to the arc.
////////////////////////////////////////////////////////////////////
void NodePath::
set_mat(const NodePath &other, const LMatrix4f &mat) {
nassertv_always(has_arcs());
#ifndef NDEBUG
if (_graph_type == DataRelation::get_class_type()) {
sgmanip_cat.warning()
<< "Setting transform on data graph arc.\n"
<< "(This is probably meaningless. Did you mean to do this to the bottom node?)\n";
}
#endif
NodeRelation *darc = arc();
// First, we perform a wrt to the node's parent, to get the
// conversion matrix.
NodeTransitionWrapper ntw(TransformTransition::get_class_type());
ForwardIterator from = begin();
++from;
if (other.is_empty()) {
wrt(NULL, darc->get_parent(), from, end(), ntw, _graph_type);
} else {
wrt(other.node(), other.begin(), other.end(),
darc->get_parent(), from, end(),
ntw, _graph_type);
}
LMatrix4f new_mat,*new_mat_ptr;
const TransformTransition *tt;
if (!get_transition_into(tt, ntw)) {
// No relative transform.
new_mat_ptr = (LMatrix4f*)&mat;
} else {
new_mat.multiply(mat,tt->get_matrix());
new_mat_ptr = &new_mat;
}
darc->set_transition(new TransformTransition(*new_mat_ptr));
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::get_children
// Access: Public
@ -1294,9 +1379,10 @@ get_scale() const {
// Extract the axes from the matrix.
LVector3f x, y, z;
x = mat.get_row3(0);
y = mat.get_row3(1);
z = mat.get_row3(2);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
// Now return the lengths of these axes as the scale.
return LVecBase3f(length(x), length(y), length(z));
@ -1321,7 +1407,7 @@ set_color_scale(const LVecBase4f &sv4) {
#endif
NodeRelation *darc = _head->get_arc();
if (sv4[0] != 1 || sv4[1] != 1 || sv4[2] != 1) {
if (sv4[0] != 1.0f || sv4[1] != 1.0f || sv4[2] != 1.0f) {
LMatrix4f mat = LMatrix4f::scale_mat(sv4[0], sv4[1], sv4[2]);
darc->set_transition(new ColorMatrixTransition(mat));
}
@ -1330,7 +1416,7 @@ set_color_scale(const LVecBase4f &sv4) {
}
if (sv4[3] != 1) {
darc->set_transition(new AlphaTransformTransition(0, sv4[3]));
darc->set_transition(new AlphaTransformTransition(0.0f, sv4[3]));
}
else {
darc->clear_transition(AlphaTransformTransition::get_class_type());
@ -1346,7 +1432,7 @@ set_color_scale(const LVecBase4f &sv4) {
////////////////////////////////////////////////////////////////////
LVecBase4f NodePath::
get_color_scale() const {
nassertr(has_arcs(), LVecBase4f(1,1,1,1));
nassertr(has_arcs(), LVecBase4f(1.0f,1.0f,1.0f,1.0f));
LVecBase4f scale;
@ -1354,9 +1440,9 @@ get_color_scale() const {
const ColorMatrixTransition *ct;
if (!get_transition_into(ct, darc)) {
// No relative transform.
scale[0] = 1;
scale[1] = 1;
scale[2] = 1;
scale[0] = 1.0f;
scale[1] = 1.0f;
scale[2] = 1.0f;
}
else
{
@ -1369,7 +1455,7 @@ get_color_scale() const {
const AlphaTransformTransition *att;
if (!get_transition_into(att, darc)) {
scale[3] = 1;
scale[3] = 1.0f;
}
else {
scale[3] = att->get_scale();
@ -1486,20 +1572,34 @@ look_at_preserve_scale(const LPoint3f &point, const LVector3f &up) {
// Extract the axes from the matrix.
LVector3f x, y, z;
x = mat.get_row3(0);
y = mat.get_row3(1);
z = mat.get_row3(2);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
// The lengths of the axes defines the scale.
LVecBase3f scale(length(x), length(y), length(z));
LPoint3f pos = mat.get_row3(3);
float scale_0 = length(x);
float scale_1 = length(y);
float scale_2 = length(z);
LPoint3f pos;
mat.get_row3(pos,3);
::look_at(mat, point - pos, up);
// Now reapply the scale and position.
mat.set_row(0, mat.get_row3(0) * scale[0]);
mat.set_row(1, mat.get_row3(1) * scale[1]);
mat.set_row(2, mat.get_row3(2) * scale[2]);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
x *= scale_0;
y *= scale_1;
z *= scale_2;
mat.set_row(0, x);
mat.set_row(1, y);
mat.set_row(2, z);
mat.set_row(3, pos);
set_mat(mat);
}
@ -1521,20 +1621,33 @@ heads_up_preserve_scale(const LPoint3f &point, const LVector3f &up) {
// Extract the axes from the matrix.
LVector3f x, y, z;
x = mat.get_row3(0);
y = mat.get_row3(1);
z = mat.get_row3(2);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
float scale_0 = length(x);
float scale_1 = length(y);
float scale_2 = length(z);
// The lengths of the axes defines the scale.
LVecBase3f scale(length(x), length(y), length(z));
LPoint3f pos = mat.get_row3(3);
LPoint3f pos;
mat.get_row3(pos,3);
::heads_up(mat, point - pos, up);
// Now reapply the scale and position.
mat.set_row(0, mat.get_row3(0) * scale[0]);
mat.set_row(1, mat.get_row3(1) * scale[1]);
mat.set_row(2, mat.get_row3(2) * scale[2]);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
x *= scale_0;
y *= scale_1;
z *= scale_2;
mat.set_row(0, x);
mat.set_row(1, y);
mat.set_row(2, z);
mat.set_row(3, pos);
set_mat(mat);
}
@ -1691,9 +1804,9 @@ get_scale(const NodePath &other) const {
// Extract the axes from the matrix.
LVector3f x, y, z;
x = mat.get_row3(0);
y = mat.get_row3(1);
z = mat.get_row3(2);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
// Now return the lengths of these axes as the scale.
return LVecBase3f(length(x), length(y), length(z));
@ -1733,90 +1846,6 @@ set_pos_hpr_scale(const NodePath &other,
set_mat(other, mat);
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_mat
// Access: Public
// Description: Converts the indicated matrix from the other's
// coordinate space to the local coordinate space, and
// applies it to the arc.
////////////////////////////////////////////////////////////////////
void NodePath::
set_mat(const NodePath &other, const LMatrix4f &mat) {
nassertv_always(has_arcs());
#ifndef NDEBUG
if (_graph_type == DataRelation::get_class_type()) {
sgmanip_cat.warning()
<< "Setting transform on data graph arc.\n"
<< "(This is probably meaningless. Did you mean to do this to the bottom node?)\n";
}
#endif
LMatrix4f new_mat;
NodeRelation *darc = arc();
// First, we perform a wrt to the node's parent, to get the
// conversion matrix.
NodeTransitionWrapper ntw(TransformTransition::get_class_type());
ForwardIterator from = begin();
++from;
if (other.is_empty()) {
wrt(NULL, darc->get_parent(), from, end(), ntw, _graph_type);
} else {
wrt(other.node(), other.begin(), other.end(),
darc->get_parent(), from, end(),
ntw, _graph_type);
}
const TransformTransition *tt;
if (!get_transition_into(tt, ntw)) {
// No relative transform.
new_mat = mat;
} else {
new_mat = mat * tt->get_matrix();
}
darc->set_transition(new TransformTransition(new_mat));
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::get_mat
// Access: Public
// Description: Returns the matrix that describes the coordinate
// space of the bottom node, relative to the other
// path's bottom node's coordinate space.
////////////////////////////////////////////////////////////////////
LMatrix4f NodePath::
get_mat(const NodePath &other) const {
NodeTransitionWrapper ntw(TransformTransition::get_class_type());
if (is_empty() && other.is_empty()) {
return LMatrix4f::ident_mat();
} else if (is_empty()) {
wrt(NULL, other.node(), other.begin(), other.end(),
ntw, _graph_type);
} else if (other.is_empty()) {
wrt(node(), begin(), end(), (Node *)NULL, ntw, _graph_type);
} else {
wrt(node(), begin(), end(),
other.node(), other.begin(), other.end(),
ntw, _graph_type);
}
const TransformTransition *tt;
if (!get_transition_into(tt, ntw)) {
// No relative transform.
return LMatrix4f::ident_mat();
} else {
return tt->get_matrix();
}
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::look_at
// Access: Public
@ -1883,13 +1912,17 @@ look_at_preserve_scale(const NodePath &other, const LPoint3f &point,
// Extract the axes from the matrix.
LVector3f x, y, z;
x = mat.get_row3(0);
y = mat.get_row3(1);
z = mat.get_row3(2);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
// The lengths of the axes defines the scale.
LVecBase3f scale(length(x), length(y), length(z));
LPoint3f pos = mat.get_row3(3);
float scale_0 = length(x);
float scale_1 = length(y);
float scale_2 = length(z);
LPoint3f pos;
mat.get_row3(pos,3);
NodePath parent(*this);
parent.shorten(1);
@ -1898,9 +1931,18 @@ look_at_preserve_scale(const NodePath &other, const LPoint3f &point,
::look_at(mat, rel_point - pos, up);
// Now reapply the scale and position.
mat.set_row(0, mat.get_row3(0) * scale[0]);
mat.set_row(1, mat.get_row3(1) * scale[1]);
mat.set_row(2, mat.get_row3(2) * scale[2]);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
x *= scale_0;
y *= scale_1;
z *= scale_2;
mat.set_row(0, x);
mat.set_row(1, y);
mat.set_row(2, z);
mat.set_row(3, pos);
set_mat(mat);
}
@ -1923,13 +1965,17 @@ heads_up_preserve_scale(const NodePath &other, const LPoint3f &point,
// Extract the axes from the matrix.
LVector3f x, y, z;
x = mat.get_row3(0);
y = mat.get_row3(1);
z = mat.get_row3(2);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
// The lengths of the axes defines the scale.
LVecBase3f scale(length(x), length(y), length(z));
LPoint3f pos = mat.get_row3(3);
float scale_0 = length(x);
float scale_1 = length(y);
float scale_2 = length(z);
LPoint3f pos;
mat.get_row3(pos,3);
NodePath parent(*this);
parent.shorten(1);
@ -1938,9 +1984,17 @@ heads_up_preserve_scale(const NodePath &other, const LPoint3f &point,
::heads_up(mat, rel_point - pos, up);
// Now reapply the scale and position.
mat.set_row(0, mat.get_row3(0) * scale[0]);
mat.set_row(1, mat.get_row3(1) * scale[1]);
mat.set_row(2, mat.get_row3(2) * scale[2]);
mat.get_row3(x,0);
mat.get_row3(y,1);
mat.get_row3(z,2);
x *= scale_0;
y *= scale_1;
z *= scale_2;
mat.set_row(0, x);
mat.set_row(1, y);
mat.set_row(2, z);
mat.set_row(3, pos);
set_mat(mat);
}
@ -1997,7 +2051,7 @@ get_color() const {
sgmanip_cat.warning()
<< "get_color() called on " << *this << " which has no color set.\n";
return Colorf(0.0, 0.0, 0.0, 0.0);
return Colorf(0.0f, 0.0f, 0.0f, 0.0f);
}
////////////////////////////////////////////////////////////////////

View File

@ -18,12 +18,15 @@ get_rel_pos(const Node *node, const Node *relative_to,
NodeTransitionWrapper ntw(TransformTransition::get_class_type());
wrt(node, relative_to, ntw, graph_type);
const TransformTransition *tt;
if (!get_transition_into(tt, ntw)) {
// No relative transform.
return LPoint3f(0.0, 0.0, 0.0);
}
return tt->get_matrix().get_row3(3);
LVector3f pos;
tt->get_matrix().get_row3(pos,3);
return pos;
}
////////////////////////////////////////////////////////////////////

View File

@ -30,20 +30,20 @@ get_rel_rot_mat(const Node *node, const Node *relative_to,
// Extract the axes from the matrix.
const LMatrix4f &rel_mat = tt->get_matrix();
LVector3f x, y, z;
x = rel_mat.get_row3(0);
y = rel_mat.get_row3(1);
z = rel_mat.get_row3(2);
rel_mat.get_row3(x,0);
rel_mat.get_row3(y,1);
rel_mat.get_row3(z,2);
// Normalize these axes to eliminate scale.
x = normalize(x);
y = normalize(y);
z = normalize(z);
x.normalize();
y.normalize();
z.normalize();
// Now build a new matrix which just represents these axes.
mat.set(x[0], x[1], x[2], 0.0,
y[0], y[1], y[2], 0.0,
z[0], z[1], z[2], 0.0,
0.0, 0.0, 0.0, 1.0);
mat.set(x[0], x[1], x[2], 0.0f,
y[0], y[1], y[2], 0.0f,
z[0], z[1], z[2], 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
}
@ -60,15 +60,15 @@ get_rel_scale(const Node *node, const Node *relative_to,
const TransformTransition *tt;
if (!get_transition_into(tt, ntw)) {
// No relative transform.
return LVecBase3f(1.0, 1.0, 1.0);
return LVecBase3f(1.0f, 1.0f, 1.0f);
}
// Extract the axes from the matrix.
const LMatrix4f &rel_mat = tt->get_matrix();
LVector3f x, y, z;
x = rel_mat.get_row3(0);
y = rel_mat.get_row3(1);
z = rel_mat.get_row3(2);
rel_mat.get_row3(x,0);
rel_mat.get_row3(y,1);
rel_mat.get_row3(z,2);
// Now return the lengths of these axes as the scale.

View File

@ -20,9 +20,9 @@ TypeHandle Trackball::_pixel_xyz_type;
TypeHandle Trackball::_button_events_type;
TypeHandle Trackball::_transform_type;
#define B1_MASK 1
#define B2_MASK 2
#define B3_MASK 4
#define B1_MASK 0x1
#define B2_MASK 0x2
#define B3_MASK 0x4
////////////////////////////////////////////////////////////////////
// Function: Trackball::Constructor
@ -54,8 +54,6 @@ Trackball(const string &name) : DataNode(name) {
_attrib.set_attribute(_transform_type, _transform);
}
////////////////////////////////////////////////////////////////////
// Function: Trackball::Destructor
// Access: Public, Scheme
@ -65,8 +63,6 @@ Trackball::
~Trackball() {
}
////////////////////////////////////////////////////////////////////
// Function: Trackball::reset
// Access: Public, Scheme
@ -438,7 +434,7 @@ reextract() {
m = _orig * rel_mat;
}
_translation = m.get_row3(3);
m.get_row3(_translation,3);
_rotation = m;
_rotation.set_row(3, LVecBase3f(0.0, 0.0, 0.0));
}