程序示例精选
C++OpenGL物体碰撞检测实例
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!
前言
这篇博客针对《C++OpenGL物体碰撞检测实例》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。
运行结果
文章目录
一、所需工具软件
二、使用步骤
1. 主要代码
2. 运行结果
三、在线协助
一、所需工具软件
1. VS,Qt
2. OpenGL
二、使用步骤
主要代码如下(示例):
#ifndef AABB_H
#define AABB_H
#include <assert.h>
#include "vector.h"
using namespace vec;
class TAABB
{
// ATTRIBUTES
public:
TVector minv; // Min point of bounding box
TVector maxv; // Max point of bounding box
// METHODS
public:
// Common constructor
TAABB() {}
// Initialization constructor
TAABB(const TVector& mn, const TVector& mx) : minv(mn), maxv(mx) {}
// Empty the box so that it contains no points
void Empty()
{
minv = TVector(100000.0f, 100000.0f, 100000.0f);
maxv = -minv;
}
// Expand the box to contain the point passed as a parameter
void Add(const TVector& point)
{
if (point.x < minv.x) minv.x = point.x;
if (point.x > maxv.x) maxv.x = point.x;
if (point.y < minv.y) minv.y = point.y;
if (point.y > maxv.y) maxv.y = point.y;
if (point.z < minv.z) minv.z = point.z;
if (point.z > maxv.z) maxv.z = point.z;
}
// Function which returns all the vertices of the bounding
// as found in AABB3.cpp from 3D Math Primer for Games and Graphics Development
// Return one of the 8 corner points. The points are numbered as follows:
//
// 2 3
// ------------------------------
// /| /|
// / | / |
// / | / |
// / | / |
// / | / |
// / | / |
// / | / |
// / | / |
// / | / |
// 6 / | 7 / |
// /----------------------------/ |
// | | | |
// | | | | +Y
// | 0 | | |
// | |-----------------|----------| |
// | / | / 1 |
// | / | / | -Z
// | / | / |
// | / | / | /
// | / | / | /
// | / | / | /
// | / | / | /
// | / | / | /
// | / | / |/
// |/ |/ ----------------- +X
// ------------------------------
// 4 5
//
// Bit 0 selects min.x vs. max.x
// Bit 1 selects min.y vs. max.y
// Bit 2 selects min.z vs. max.z
TVector GetVertex(int i) const
{
// Make sure parameter is within range
assert (i >= 0);
assert (i <= 7);
return TVector (
(i & 1) ? maxv.x : minv.x,
(i & 2) ? maxv.y : minv.y,
(i & 4) ? maxv.z : minv.z );
}
};
class TBox : public TAABB
{
// ATTRIBUTES
public:
TVector vel; // Velocity of box
TVector accel; // Acceleration of box
int color; // ID specifying global colour to choose
int texture; // ID specifying global texture to choose
// METHODS
#endif
运行结果
三、在线协助:
如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作
5)云服务器申请
6)网站制作
当前文章连接:https://blog.csdn.net/alicema1111/article/details/132666851
个人博客主页:https://blog.csdn.net/alicema1111?type=blog
博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog
博主推荐:
Python人脸识别考勤打卡系统:
https://blog.csdn.net/alicema1111/article/details/133434445
Python果树水果识别:https://blog.csdn.net/alicema1111/article/details/130862842
Python+Yolov8+Deepsort入口人流量统计:https://blog.csdn.net/alicema1111/article/details/130454430
Python+Qt人脸识别门禁管理系统:https://blog.csdn.net/alicema1111/article/details/130353433
Python+Qt指纹录入识别考勤系统:https://blog.csdn.net/alicema1111/article/details/129338432
Python Yolov5火焰烟雾识别源码分享:https://blog.csdn.net/alicema1111/article/details/128420453
Python+Yolov8路面桥梁墙体裂缝识别:https://blog.csdn.net/alicema1111/article/details/133434445
Python+Yolov5道路障碍物识别:https://blog.csdn.net/alicema1111/article/details/129589741
Python+Yolov5跌倒检测 摔倒检测 人物目标行为 人体特征识别:https://blog.csdn.net/alicema1111/article/details/129272048