C++OpenGL物体碰撞检测实例

程序示例精选
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

  • 14
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荷塘月色2

您的鼓励将是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值