mat3 operator +(const mat3 &_lhs, const mat3 &_rhs)
{
    mat3 m;
    for(int i = 0; i < 9; ++i)
        m.set( i, _lhs.get(i) + _rhs.get(i) );
    return m;
}
bool operator ==(const mat3 &_lhs, const mat3 &_rhs)
{
    for(int i = 0; i < 9; ++i)
        if(_lhs.get(i) != _rhs.get(i))
            return false;
    return true;
}
float determinant(const mat3 &_m)
{
    float a = _m.get(0,0);
    float b = _m.get(1,0);
    float c = _m.get(2,0);
    float d = _m.get(0,1);
    float e = _m.get(1,1);
    float f = _m.get(2,1);
    float g = _m.get(0,2);
    float h = _m.get(1,2);
    float i = _m.get(2,2);

    return a * (e*i - f*h) -
            b * (d*i - f*g) +
            c * (d*h - e*g);
}
mat3 operator /(const mat3 &_lhs, const float &_rhs)
{
    mat3 m;
    for(int i = 0; i < 9; ++i)
        m.set( i, _lhs.get(i) / _rhs );
    return m;
}
mat3 transpose(const mat3 &_m)
{
    mat3 r;
    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
            r.set(j, i, _m.get(i, j));
		return r;
}
mat3 operator *(const mat3 &_lhs, const mat3 &_rhs)
{
    mat3 m;
    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
        {
            vec3 l (
                        _lhs.get( 0, j ),
                        _lhs.get( 1, j ),
                        _lhs.get( 2, j )
                        );
            vec3 r (
                        _rhs.get( i, 0 ),
                        _rhs.get( i, 1 ),
                        _rhs.get( i, 2 )
                        );
            m.set(i, j, dot(l, r));
        }
    return m;
}
コード例 #7
0
ファイル: Direct3D9.cpp プロジェクト: KTXSoftware/Kha-haxelib
void Graphics::setMatrix(ConstantLocation location, const mat3& value) {
	if (location.shaderType == -1) return;
	float floats[12];
	for (int y = 0; y < 3; ++y) {
		for (int x = 0; x < 3; ++x) {
			floats[y * 4 + x] = value.get(y, x);
		}
	}
	if (location.shaderType == 0) device->SetVertexShaderConstantF(location.reg.regindex, floats, 3);
	else device->SetPixelShaderConstantF(location.reg.regindex, floats, 3);
}
コード例 #8
0
ファイル: RHI.cpp プロジェクト: Disar/Kore
void Graphics::setMatrix(ConstantLocation location, const mat3& value) {
	FRHICommandListImmediate& commandList = GRHICommandList.GetImmediateCommandList();
	TShaderMapRef<FVertexShaderExample> VertexShader(GetGlobalShaderMap(ERHIFeatureLevel::SM5));
	mat3 value2 = value.Transpose();
	float floats[12];
	for (int y = 0; y < 3; ++y) {
		for (int x = 0; x < 3; ++x) {
			floats[y * 4 + x] = value.get(y, x);
		}
	}
	commandList.SetShaderParameter(VertexShader->GetVertexShader(), location.parameter.GetBufferIndex(), location.parameter.GetBaseIndex(), 4 * 12, floats);
}
コード例 #9
0
ファイル: mat3.cpp プロジェクト: solomonchild/opengl_samples
mat3 mat3::operator *(const mat3& rhs)
{
	float a[VEC_DIM*VEC_DIM] = {0.0f};
	for(int i = 0; i < VEC_DIM; i++) {
		for(int j = 0; j < VEC_DIM; j++) {
			for(int z = 0; z < VEC_DIM; z++) {
				a[i * VEC_DIM + j] += v[i].v[z] * rhs.get(z , j);
			}
		}
	}
	return mat3(a);
}
コード例 #10
0
void XmlSceneLoader::parseTransformation(TiXmlElement* elem, vec3& tr, vec3& sc, mat3& rot, Collider* collider)
{
    tr={0,0,0};
    sc={1,1,1};
    rot=mat3::IDENTITY();

    elem = elem->FirstChildElement();

    while(elem)
    {
        if(elem->ValueStr() == std::string("translate"))
            tr = toVec<3>(StringUtils::str(elem->GetText()));
        else if(elem->ValueStr() == std::string("scale"))
            sc = toVec<3>(StringUtils::str(elem->GetText()));
        else if(elem->ValueStr() == std::string("rotate"))
        {
            Vector<float, 9> r = toVec<9>(StringUtils::str(elem->GetText()));

            for(int i=0 ; i<9 ; ++i)
                rot.get(i) = r[i];
        }
        else if(elem->ValueStr() == std::string("collider") && collider)
        {
            int col = Collider::NONE;
            elem->QueryIntAttribute("type", &col);

            elem->QueryFloatAttribute("mass", &collider->mass);
            elem->QueryFloatAttribute("restitution", &collider->restitution);
            elem->QueryFloatAttribute("friction", &collider->friction);
            elem->QueryFloatAttribute("rollingFriction", &collider->rollingFriction);

            if(col < Collider::USER_DEFINED)
                collider->type = col;
            else
                collider->type = Collider::NONE;
        }

        elem = elem->NextSiblingElement();
    }
}