Source

KODE / src / collision / TrimeshInternal.hpp

Full commit
/*
   KODE Physics Library
   Copyright 2013-2014 Daniel Kohler Osmari

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#ifndef KODE_TRIMESH_INTERNAL_H
#define KODE_TRIMESH_INTERNAL_H

#include <cstdint>
#include <vector>

#include <kode/AxisAlignedBox.hpp>

#include "OPCODE/Opcode.h"

namespace kode {
    
    struct Trimesh::Data::Impl {
        Opcode::Model BVTree;
        Opcode::MeshInterface Mesh;

        /* aabb in model space */
        AxisAlignedBox aabb;

        // data for use in collision resolution
        const void* normals;
        std::vector<std::uint8_t> useFlags;

        std::vector<Vector3> vertices;
        std::vector<TriIndex> indices;

        void build(const float* vertices, unsigned vertexCount,
                   const TriIndex* indices, unsigned triCount);

        void build(const double* vertices, unsigned vertexCount,
                   const TriIndex* indices, unsigned triCount);

        void preprocess();


        unsigned triangleCount();

        void fetchTriangle(int index, const Vector3& position,
                           const Matrix3& rotation,
                           Vector3 out[3]) const;

    };


    inline
    IceMaths::Matrix4x4&
    MakeMatrix(const Vector3& pos, const Matrix3 rot, IceMaths::Matrix4x4& out)
    {
        out.m[0][0] = rot(0,0);
        out.m[1][0] = rot(0,1);
        out.m[2][0] = rot(0,2);

        out.m[0][1] = rot(1,0);
        out.m[1][1] = rot(1,1);
        out.m[2][1] = rot(1,2);

        out.m[0][2] = rot(2,0);
        out.m[1][2] = rot(2,1);
        out.m[2][2] = rot(2,2);

        out.m[3][0] = pos.x;
        out.m[3][1] = pos.y;
        out.m[3][2] = pos.z;

        out.m[0][3] = 0;
        out.m[1][3] = 0;
        out.m[2][3] = 0;
        out.m[3][3] = 1;

        return out;
    }

}

#endif