没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论






#pragma once
#ifndef _COLLISION_H_
#define _COLLISION_H_
#include "stdafx.h"
#include "Object.h"
string checkCollision(const Object& obj1, const Object &obj2)
{
string state = "UNKNOWN";
if (obj1.radius + obj2.radius < distance(obj1.MovingCenter, obj2.MovingCenter))
{
return "NO_COLLISION";
}
for (int i = 0; i < obj1.stl.num; i++)
{
for (int j = 0; j < obj2.stl.num; j++)
{
vector3f vi1 = obj1.stl.triangle[i].point[0] - obj2.stl.triangle[j].point[0];
vector3f vi2 = obj1.stl.triangle[i].point[1] - obj2.stl.triangle[j].point[0];
vector3f vi3 = obj1.stl.triangle[i].point[2] - obj2.stl.triangle[j].point[0];
GLfloat di1 = dotProduct(vi1, obj2.stl.triangle[j].normal);
GLfloat di2 = dotProduct(vi2, obj2.stl.triangle[j].normal);
GLfloat di3 = dotProduct(vi3, obj2.stl.triangle[j].normal);
vector3f vj1 = obj2.stl.triangle[j].point[0] - obj1.stl.triangle[i].point[0];
vector3f vj2 = obj2.stl.triangle[j].point[1] - obj1.stl.triangle[i].point[0];
vector3f vj3 = obj2.stl.triangle[j].point[2] - obj1.stl.triangle[i].point[0];
GLfloat dj1 = dotProduct(vj1, obj1.stl.triangle[i].normal);
GLfloat dj2 = dotProduct(vj2, obj1.stl.triangle[i].normal);
GLfloat dj3 = dotProduct(vj3, obj1.stl.triangle[i].normal);
#ifndef _COLLISION_H_
#define _COLLISION_H_
#include "stdafx.h"
#include "Object.h"
string checkCollision(const Object& obj1, const Object &obj2)
{
string state = "UNKNOWN";
if (obj1.radius + obj2.radius < distance(obj1.MovingCenter, obj2.MovingCenter))
{
return "NO_COLLISION";
}
for (int i = 0; i < obj1.stl.num; i++)
{
for (int j = 0; j < obj2.stl.num; j++)
{
vector3f vi1 = obj1.stl.triangle[i].point[0] - obj2.stl.triangle[j].point[0];
vector3f vi2 = obj1.stl.triangle[i].point[1] - obj2.stl.triangle[j].point[0];
vector3f vi3 = obj1.stl.triangle[i].point[2] - obj2.stl.triangle[j].point[0];
GLfloat di1 = dotProduct(vi1, obj2.stl.triangle[j].normal);
GLfloat di2 = dotProduct(vi2, obj2.stl.triangle[j].normal);
GLfloat di3 = dotProduct(vi3, obj2.stl.triangle[j].normal);
vector3f vj1 = obj2.stl.triangle[j].point[0] - obj1.stl.triangle[i].point[0];
vector3f vj2 = obj2.stl.triangle[j].point[1] - obj1.stl.triangle[i].point[0];
vector3f vj3 = obj2.stl.triangle[j].point[2] - obj1.stl.triangle[i].point[0];
GLfloat dj1 = dotProduct(vj1, obj1.stl.triangle[i].normal);
GLfloat dj2 = dotProduct(vj2, obj1.stl.triangle[i].normal);
GLfloat dj3 = dotProduct(vj3, obj1.stl.triangle[i].normal);
//case 1
if ((di1 > 0 && di2 > 0 && di3 > 0) || (di1 < 0 && di2 < 0 && di3 < 0) || (dj1 > 0 && dj2 > 0 && dj3 > 0) || (dj1 < 0 && dj2 < 0 && dj3 < 0))
{
state = "NO_COLLISION";
}
//case 2
else if ((di1 == 0 && di2 == 0 && di3 == 0) || (dj1 == 0 && dj2 == 0 && dj3 == 0))
{
state = "NO_COLLISION";
}
//case 3
else if ((di1 == 0 && di2 == 0 && di3 != 0) ||
(di1 == 0 && di2 != 0 && di3 == 0) ||
(di1 != 0 && di2 == 0 && di3 == 0) ||
(dj1 == 0 && dj2 == 0 && dj3 != 0) ||
(dj1 == 0 && dj2 != 0 && dj3 == 0) ||
(dj1 != 0 && dj2 == 0 && dj3 == 0))
{
state = "NO_COLLISION";
}
//case 4
else //i dont sure should i write condition for this
{
state = "MAYBE";
}
///////////////////////////////////////////////////////
int step = 0, r1 = 0, r2 = 0, u = 0, v = 0;
if (state == "MAYBE")
{
if ((di1 > 0 && di2 > 0 && di3 > 0) || (di1 < 0 && di2 < 0 && di3 < 0) || (dj1 > 0 && dj2 > 0 && dj3 > 0) || (dj1 < 0 && dj2 < 0 && dj3 < 0))
{
state = "NO_COLLISION";
}
//case 2
else if ((di1 == 0 && di2 == 0 && di3 == 0) || (dj1 == 0 && dj2 == 0 && dj3 == 0))
{
state = "NO_COLLISION";
}
//case 3
else if ((di1 == 0 && di2 == 0 && di3 != 0) ||
(di1 == 0 && di2 != 0 && di3 == 0) ||
(di1 != 0 && di2 == 0 && di3 == 0) ||
(dj1 == 0 && dj2 == 0 && dj3 != 0) ||
(dj1 == 0 && dj2 != 0 && dj3 == 0) ||
(dj1 != 0 && dj2 == 0 && dj3 == 0))
{
state = "NO_COLLISION";
}
//case 4
else //i dont sure should i write condition for this
{
state = "MAYBE";
}
///////////////////////////////////////////////////////
int step = 0, r1 = 0, r2 = 0, u = 0, v = 0;
if (state == "MAYBE")
{
剩余7页未读,继续阅读
资源评论

chongkaechin
- 粉丝: 0
- 资源: 1

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制
