]> git.tdb.fi Git - libs/gl.git/commitdiff
Adapt to the new vector/matrix slicing API in mspmath
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 21:22:04 +0000 (23:22 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 21:35:27 +0000 (23:35 +0200)
source/camera.cpp
source/environmentmap.cpp
source/lighting.cpp
source/matrix.cpp
source/renderer.cpp
source/shadowmap.cpp
source/zsortedscene.cpp

index a0c89e0efb6c2129354efa273545bb20605008b6..6cbcf6f492680f537559206d311049f26af5f1db 100644 (file)
@@ -82,7 +82,7 @@ void Camera::look_at(const Vector3 &p)
 Vector3 Camera::project(const Vector4 &p) const
 {
        Vector4 r = proj_matrix*(view_matrix*p);
-       return Vector3(r)/r.w;
+       return r.slice<3>(0)/r.w;
 }
 
 Vector3 Camera::project(const Vector3 &p) const
@@ -121,10 +121,10 @@ void Camera::update_object_matrix()
 {
        Vector3 right_dir = normalize(cross(look_dir, up_dir));
        Vector4 columns[4];
-       columns[0] = Vector4(right_dir, 0.0f);
-       columns[1] = Vector4(cross(right_dir, look_dir), 0.0f);
-       columns[2] = Vector4(-look_dir, 0.0f);
-       columns[3] = Vector4(position, 1.0f);
+       columns[0] = compose(right_dir, 0.0f);
+       columns[1] = compose(cross(right_dir, look_dir), 0.0f);
+       columns[2] = compose(-look_dir, 0.0f);
+       columns[3] = compose(position, 1.0f);
        object_matrix = Matrix::from_columns(columns);
        view_matrix = invert(object_matrix);
 }
index ec406d157681baec5689ef07538f44f6e6f2dd82..1e6f639a3eb8f89bb1037b94f386fe8c59cfaf1d 100644 (file)
@@ -79,19 +79,8 @@ void EnvironmentMap::render(Renderer &renderer, const Tag &tag) const
        shdata.uniform("environment", static_cast<int>(unit));
        Bind _bind_env(env_tex, unit);
 
-       const Matrix &view_matrix = renderer.get_camera()->get_matrix();
-       // XXX The camera should maybe have store its own object matrix
-       float env_mdata[9];
-       env_mdata[0] = view_matrix[0];
-       env_mdata[1] = view_matrix[4];
-       env_mdata[2] = view_matrix[8];
-       env_mdata[3] = view_matrix[1];
-       env_mdata[4] = view_matrix[5];
-       env_mdata[5] = view_matrix[9];
-       env_mdata[6] = view_matrix[2];
-       env_mdata[7] = view_matrix[6];
-       env_mdata[8] = view_matrix[10];
-       shdata.uniform_matrix3("env_eye_matrix", env_mdata);
+       const Matrix &camera_matrix = renderer.get_camera()->get_object_matrix();
+       shdata.uniform("env_eye_matrix", camera_matrix.block<3, 3>(0, 0));
 
        renderer.add_shader_data(shdata);
        renderer.render(renderable, tag);
index d1fd9a70ffc0febe50bd9335b753c87418e32549..239bdc19d0d03fdb9d0bcfaf58902d4c12abf4f6 100644 (file)
@@ -62,7 +62,7 @@ void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix
 {
        shdata.uniform("ambient_color", ambient);
        shdata.uniform("sky_color", sky_color);
-       shdata.uniform("eye_sky_dir", Vector3(view_matrix*Vector4(sky_direction, 0.0f)));
+       shdata.uniform("eye_sky_dir", view_matrix.block<3, 3>(0, 0)*sky_direction);
        shdata.uniform("horizon_limit", horizon_angle.radians());
 
        for(unsigned i=0; i<lights.size(); ++i)
index b05d4bbc8ab6ff3de95e4f9cb6a35dacea80285d..ece99e344b903381a2a3dfc013ecdbff1571cffb 100644 (file)
@@ -60,7 +60,7 @@ Vector4 Matrix::operator*(const Vector4 &vec) const
 
 Vector3 Matrix::operator*(const Vector3 &vec) const
 {
-       return Vector3((*this)*Vector4(vec, 1.0f));
+       return ((*this)*compose(vec, 1.0f)).slice<3>(0);
 }
 
 float Matrix::operator[](unsigned i) const
index bc49b0f802941f3ae2a7509ae86351dc51a67ca8..184d326928381722e5766eed46e030b572278771 100644 (file)
@@ -257,10 +257,7 @@ void Renderer::apply_state()
                        {
                                const Matrix &m = mtx_stack.top();
                                standard_shdata.uniform("eye_obj_matrix", mtx_stack.top());
-                               LinAl::SquareMatrix<float, 3> nm;
-                               for(unsigned i=0; i<3; ++i)
-                                       for(unsigned j=0; j<3; ++j)
-                                               nm(i, j) = m(i, j);
+                               LinAl::SquareMatrix<float, 3> nm = m.block<3, 3>(0, 0);
                                nm = transpose(invert(nm));
                                standard_shdata.uniform_matrix3("eye_obj_normal_matrix", &nm(0, 0));
                                changed &= ~MODERN_MATRIX;
index 372fa1130c6ccf8836992b154cbb3ea9dbb31f95..bc46f2c1b298827738a9db5c6d5140c1362edb50 100644 (file)
@@ -70,10 +70,10 @@ void ShadowMap::setup_frame() const
        {
                /* XXX Not really proper way to support positional lights, but good
                enough when the light source is far away */
-               back = Vector3(lpos)-target;
+               back = lpos.slice<3>(0)-target;
        }
        else
-               back = Vector3(lpos);
+               back = lpos.slice<3>(0);
        back.normalize();
 
        Vector3 up;
@@ -85,10 +85,10 @@ void ShadowMap::setup_frame() const
        Vector3 right = normalize(cross(up, back));
 
        Vector4 columns[4];
-       columns[0] = Vector4(right, 0.0f);
-       columns[1] = Vector4(normalize(cross(back, right)), 0.0f);
-       columns[2] = Vector4(back, 0.0f);
-       columns[3] = Vector4(target, 1.0f);
+       columns[0] = compose(right, 0.0f);
+       columns[1] = compose(normalize(cross(back, right)), 0.0f);
+       columns[2] = compose(back, 0.0f);
+       columns[3] = compose(target, 1.0f);
        light_matrix = Matrix::from_columns(columns);
        view_matrix = invert(light_matrix);
 
index da406b7ef0074f19a0e125c328d93595ed43d03d..5cbd202133902d1581c7c1be3e2ea118c38ae7da 100644 (file)
@@ -44,7 +44,7 @@ void ZSortedScene::render(Renderer &renderer, const Tag &tag) const
                        if(const Matrix *model_matrix = (*i)->get_matrix())
                        {
                                if(const Geometry::BoundingSphere<float, 3> *bsphere = (*i)->get_bounding_sphere())
-                                       z = (view_matrix**model_matrix*Vector4(bsphere->get_center(), 1.0f)).z+bsphere->get_radius()*radius_factor;
+                                       z = (view_matrix**model_matrix*compose(bsphere->get_center(), 1.0f)).z+bsphere->get_radius()*radius_factor;
                                else
                                        z = (view_matrix**model_matrix*Vector4(0.0f, 0.0f, 0.0f, 1.0f)).z;
                        }