b2Math.cpp
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
00003 *
00004 * This software is provided 'as-is', without any express or implied
00005 * warranty.  In no event will the authors be held liable for any damages
00006 * arising from the use of this software.
00007 * Permission is granted to anyone to use this software for any purpose,
00008 * including commercial applications, and to alter it and redistribute it
00009 * freely, subject to the following restrictions:
00010 * 1. The origin of this software must not be misrepresented; you must not
00011 * claim that you wrote the original software. If you use this software
00012 * in a product, an acknowledgment in the product documentation would be
00013 * appreciated but is not required.
00014 * 2. Altered source versions must be plainly marked as such, and must not be
00015 * misrepresented as being the original software.
00016 * 3. This notice may not be removed or altered from any source distribution.
00017 */
00018 
00019 #include <Box2D/Common/b2Math.h>
00020 
00021 const b2Vec2 b2Vec2_zero(0.0f, 0.0f);
00022 
00025 b2Vec3 b2Mat33::Solve33(const b2Vec3& b) const
00026 {
00027         float32 det = b2Dot(ex, b2Cross(ey, ez));
00028         if (det != 0.0f)
00029         {
00030                 det = 1.0f / det;
00031         }
00032         b2Vec3 x;
00033         x.x = det * b2Dot(b, b2Cross(ey, ez));
00034         x.y = det * b2Dot(ex, b2Cross(b, ez));
00035         x.z = det * b2Dot(ex, b2Cross(ey, b));
00036         return x;
00037 }
00038 
00041 b2Vec2 b2Mat33::Solve22(const b2Vec2& b) const
00042 {
00043         float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
00044         float32 det = a11 * a22 - a12 * a21;
00045         if (det != 0.0f)
00046         {
00047                 det = 1.0f / det;
00048         }
00049         b2Vec2 x;
00050         x.x = det * (a22 * b.x - a12 * b.y);
00051         x.y = det * (a11 * b.y - a21 * b.x);
00052         return x;
00053 }
00054 
00056 void b2Mat33::GetInverse22(b2Mat33* M) const
00057 {
00058         float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
00059         float32 det = a * d - b * c;
00060         if (det != 0.0f)
00061         {
00062                 det = 1.0f / det;
00063         }
00064 
00065         M->ex.x =  det * d;     M->ey.x = -det * b; M->ex.z = 0.0f;
00066         M->ex.y = -det * c;     M->ey.y =  det * a; M->ey.z = 0.0f;
00067         M->ez.x = 0.0f; M->ez.y = 0.0f; M->ez.z = 0.0f;
00068 }
00069 
00071 void b2Mat33::GetSymInverse33(b2Mat33* M) const
00072 {
00073         float32 det = b2Dot(ex, b2Cross(ey, ez));
00074         if (det != 0.0f)
00075         {
00076                 det = 1.0f / det;
00077         }
00078 
00079         float32 a11 = ex.x, a12 = ey.x, a13 = ez.x;
00080         float32 a22 = ey.y, a23 = ez.y;
00081         float32 a33 = ez.z;
00082 
00083         M->ex.x = det * (a22 * a33 - a23 * a23);
00084         M->ex.y = det * (a13 * a23 - a12 * a33);
00085         M->ex.z = det * (a12 * a23 - a13 * a22);
00086 
00087         M->ey.x = M->ex.y;
00088         M->ey.y = det * (a11 * a33 - a13 * a13);
00089         M->ey.z = det * (a13 * a12 - a11 * a23);
00090 
00091         M->ez.x = M->ex.z;
00092         M->ez.y = M->ey.z;
00093         M->ez.z = det * (a11 * a22 - a12 * a12);
00094 }


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 22:08:34