papl_yaobi / c_yaobi / papl_yaobi.cpp

Full commit
  Copyright (c) 2012 Anders Lau Olsen.
  See LICENSE file for terms and conditions.

#include "papl_yaobi.h"

#include <yaobi/yaobi.h>
#include <yaobi/yaobi_mesh_interface.h>
#include <malloc.h>
#include <iostream>

using namespace yaobi;

struct Yaobi_CollModel
    CollModel model;
    double* vertices;
    int* triangles;
    int own_data;

        TriMeshInterface* mesh,
        double* vertices,
        int* triangles,
        int own_data) :
        model(mesh, OWN_DATA),

        if (own_data) {
            // Since we pretend to be a C library the arrays must have been
            // allocated with malloc(), so we delete them with free().

    Yaobi_CollModel(const Yaobi_CollModel&);
    Yaobi_CollModel& operator=(const Yaobi_CollModel&);

Yaobi_CollModel* yaobi_buildCollModel(
    int num_vertices, double* vertices,
    int num_triangles, int* triangles,
    int triangle_stride,
    int own_data)
    TriMeshInterface* mesh =
        new TriMeshInterface(
            num_vertices, vertices,
            num_triangles, triangles,
            triangle_stride, SHARE_DATA);
    Yaobi_CollModel* model = new Yaobi_CollModel(
        mesh, vertices, triangles, own_data);

    build_obb_tree(model->model, OWN_DATA);
    return model;

void yaobi_freeCollModel(Yaobi_CollModel* model)
    delete model;

int yaobi_isColliding(
    double ta_[][4], Yaobi_CollModel* a,
    double tb_[][4], Yaobi_CollModel* b)
    float ta[3][4];
    float tb[3][4];
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            ta[i][j] = static_cast<float>(ta_[i][j]);
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            tb[i][j] = static_cast<float>(tb_[i][j]);

    CollideResult res;
    Collide(res, ta_, a->model, tb_, b->model, FIRST_CONTACT_ONLY);
    return res.IsColliding();