ASSIGNMENT 2 - COLLISION DETECTION
Introduction
The Separating Axis Theorem (SAT) provides a powerful and efficient method for detecting collisions between convex polygons in 2D (and 3D). A convex polygon is a shape where all internal angles are less than or equal to 180 degrees, ensuring it "bulges outwards" rather than inward. SAT simplifies collision detection by focusing on finding one axis (a line) along which the two shapes do not overlap.
In this individual assignment, you'll put your understanding of collision detection into practice by implementing SAT for convex polygons in 2D. This will give you a solid foundation for building more complex and engaging game mechanics in the future.
Requirements
Lecture material, various coding snippets and solutions provided by the course responsible and teachers can and should be used as a basis for the implementation of the assignment. Also, the course literature used in Linear Algebra (5SD901) will be useful as a reference on some mathematical operations.
Project requirements that must be implemented:
· Original C++ written by the student (any use of AI assistance is prohibited)
· A private repository in the 5SD814-2024 organization (See Repository below)
o Suggestion: Use playground as a starting point for the assignment
· Solution using Visual Studio Community 2022 (v17.10 or newer)
· Must use Visual Studio project settings
o Warning level 4 /W4
o Treat all warnings as errors /WX
o Ignoring warning 4100, 4189 and 4505 is allowed
· The project cannot have any memory leaks
· A good and consistent project directory- and file structure
o Separate code from project files, e.g. place code in a separate folder
§ E.g. src/ or source/ or code/ for header and source files
o Separate code in header and source files e.g. player.h and player.cpp
· Project uses SDL, SFML or raylib
o No additional external libraries other than the ones provided by the instructor
Assignment specific requirements that must be implemented:
· Implement Separating Axis Theorem collision detection between convex polygons in 2D
o I.e. you are not allowed to use raylib-collision functions, but implement the algorithm yourselves
· Each object should render their outline, use color green (#00FF00) for non-overlapping and red (#FF0000) when objects are colliding
· Animate each object over time, e.g. transform shapes to visualize collision between objects (move, rotate etc.)
Assignment general requirements that should be followed:
· Reduce complexity as much as possible, simpler is always better (KISS)
· Boy scout rule: Leave the campground cleaner than you found it
· Be consistent: If you do something a certain way, do all similar things in the same way
· Choose descriptive and unambiguous names
· Use pronounceable names
· Use searchable names
· Replace magic numbers with named constants
· Avoid encodings, don't append prefixes or type information
· Try to write small functions
· A function should do one thing and prefer fewer function arguments
· Use comments as explanation of intent or warning of consequences
· Comments shouldn't be redundant or add obvious noise
· Don't comment out code, just remove it!
· Don't break indentation, be consistent in how you align code (scopes etc.)
Repository
Give the repository a sensible name, e.g. 5SD814-Assignment2-<your-name-goes-here>. Commit frequently and try to always commit code that compiles and runs. At a bare minimum you should commit at least at the end of every programming session.
If you need: Ask the instructor for guidance while setting up the repository on our gitea server .
Grading
This assignment has Pass and Fail as grades. Successfully completing all assignment requirements will earn you a Pass. You will be graded on the last commit before the due date.
Hand-in
Failing to comply with any of the assignment requirements or hand-in steps will result in a Fail on the assignment.
The hand-in is a link to a commit in your repository, where the commit must be before the due date.
The repository must also include a readme.txt that contains the course name (with course code), the name of the student (i.e. your name), a short assignment description and a short usage description (i.e. how to use the program). Place this description text file in the root folder of the solution. The text file should also contain the name/names of other students you have collaborated with (if applicable for the assignment). You are allowed to - and encouraged - to talk to other students with regards to different approaches and implementations of the assignment; but obviously you must have implemented everything yourself.
Generative AI
Any use of generative AI is prohibited! See section "2.2 Use of Generative AI" in "Standards for the programmes at the Department of Game Design" on Studium > Modules > Department Standards 2024.
作业 2 - 碰撞检测
介绍
分离轴定理 (SAT) 提供了一种强大而有效的方法来检测 2D(和 3D)凸多边形之间的碰撞。凸多边形是所有内角都小于或等于 180 度的形状,确保它“向外凸出”而不是向内凸出。SAT 通过专注于查找两个形状不重叠的一个轴(一条线)来简化碰撞检测。
在这个单独的作业中,您将通过对 2D 凸多边形实施 SAT 来将您对碰撞检测的理解付诸实践。这将为您在未来构建更复杂和引人入胜的游戏机制打下坚实的基础。
要求
负责课程和教师提供的讲座材料、各种编码片段和解决方案可以而且应该用作实施作业的基础。此外,线性代数 (5SD901) 中使用的课程文献将用作某些数学运算的参考。
必须实施的项目要求:
· 源语言 由学生编写的 C++(禁止使用 AI 辅助)
· 5SD814-2024 组织中的私有存储库 (请参阅下面的存储库)
o 建议:使用 Playground 作为作业的起点
· 使用 Visual Studio Community 2022(v17.10 或更高版本)的解决方案
· 必须使用 Visual Studio 项目设置
o 警告级别 4 /W4
o 将所有警告视为错误 /WX
o 允许忽略警告 4100、4189 和 4505
· 项目不能有任何内存泄漏
· 良好且一致的项目目录和文件结构
o 将代码与项目文件分开,例如将代码放在单独的文件夹中
§ 例如,src/ 或 source/ 或 code/ 用于头文件和源文件
o 在头文件和源文件中分隔代码,例如 player.h 和 player.cpp
· 项目使用 SDL、SFML 或 raylib
o 除了教师提供的外部库外,没有其他外部库
必须实施的任务特定要求:
· 在 2D
凸多边形之间实现分离轴定理碰撞检测
o 即,不允许使用 raylib-collision 函数,但可以自己实现算法
· 每个对象都应渲染其轮廓,对于不重叠的物体使用绿色 (#00FF00),在物体碰撞时使用红色 (#FF0000)
· 随时间对每个对象进行动画处理,例如变换形状以可视化对象之间的碰撞(移动、旋转等)。
应遵循的作业一般要求:
· 尽可能降低复杂性,越简单越好 (KISS)
· 童子军规则:离开露营地时比你发现时更干净
· 保持一致:如果您以某种方式做某事,则以相同的方式做所有相似的事情
· 选择描述性和明确的名称
· 使用可发音的名称
· 使用可搜索的名称
· 将幻数替换为命名常量
· 避免编码,不要附加前缀或类型信息
· 尝试编写小函数
· 函数应该只做一件事,并且更喜欢较少的函数参数
· 使用注释作为意图的解释或后果的警告
· 评论不应多余或添加明显的噪音
· 不要注释掉代码,只需删除它!
· 不要中断缩进,在对齐代码的方式(范围等)上保持一致
存储 库
为存储库指定一个合理的名称,例如 5SD814-Assignment2-<your-name-goes-here>。经常提交并尝试始终提交可编译和运行的代码。至少您应该在每个编程会话结束时提交。
如果需要:在我们的 gitea 服务器上设置存储库时,请向讲师寻求指导.
分级
此作业的成绩为“通过”和“不及格”。成功完成所有作业要求将获得通行证。您将在截止日期之前的最后一次提交中评分。
交接
未能遵守任何作业要求或提交步骤将导致作业不及格。
提交是指向存储库中提交的链接,其中提交必须在截止日期之前提交。
存储库还必须包括一个readme.txt,其中包含课程名称(带有课程代码)、学生姓名(即您的姓名)、简短的作业描述和简短的使用描述(即如何使用该程序)。将此描述文本文件放在解决方案的根文件夹中。文本文件还应包含与您合作的其他学生的姓名(如果适用于作业)。你可以 - 并鼓励 - 与其他学生讨论作业的不同方法和实施情况;但显然你必须自己实施所有工作。
生成式 AI
禁止使用生成式 AI! 请参阅 2024 年 Studium > Modules 的“游戏设计系课程标准”中的“2.2 生成式 AI 的使用”部分>。