• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

nes8bit

Collision Detection Needs Fixing

2 posts in this topic

I need help with my function In3DTriangle. It does not correctly check if the point you specify is in the triangle. I have a feeling that it has something to do with my dotproducts. This function checks if the point is in the triangle by creating 3 planes arround the triangle and checking if the point is on all the planes front sides. The other function below works. It is just there for readibility. Sorry for no HTML formatting. Function In3DTriangle(PointToCheck As D3DVECTOR, CircleRadius As Single, p1 As D3DVECTOR, p2 As D3DVECTOR, p3 As D3DVECTOR) As Boolean On Error Resume Next Dim PlaneNormals(2) As D3DVECTOR Dim OpposingVector As D3DVECTOR ''Check Bounding Circle First If Not Abs(GetPlaneDistance(PointToCheck, p1, p2, p3)) < CircleRadius Then Exit Function ''Do this for Side One OpposingVector.X = (p1.X + p3.X) / 2 OpposingVector.Y = (p1.Y + p3.Y) / 2 OpposingVector.Z = (p1.Z + p3.Z) / 2 PlaneNormals(0).X = p2.X - OpposingVector.X PlaneNormals(0).Y = p2.Y - OpposingVector.Y PlaneNormals(0).Z = p2.Z - OpposingVector.Z ''Do this for Side Two OpposingVector.X = (p1.X + p2.X) / 2 OpposingVector.Y = (p1.Y + p2.Y) / 2 OpposingVector.Z = (p1.Z + p2.Z) / 2 PlaneNormals(1).X = p3.X - OpposingVector.X PlaneNormals(1).Y = p3.Y - OpposingVector.Y PlaneNormals(1).Z = p3.Z - OpposingVector.Z ''Do this for Side Three OpposingVector.X = (p2.X + p3.X) / 2 OpposingVector.Y = (p2.Y + p3.Y) / 2 OpposingVector.Z = (p2.Z + p3.Z) / 2 PlaneNormals(2).X = p1.X - OpposingVector.X PlaneNormals(2).Y = p1.Y - OpposingVector.Y PlaneNormals(2).Z = p1.Z - OpposingVector.Z ''This is just to fix my vectors dx.VectorNormalize PlaneNormals(0) dx.VectorNormalize PlaneNormals(1) dx.VectorNormalize PlaneNormals(2) ''now check if it is in the triangle If dx.VectorDotProduct(PointToCheck, PlaneNormals(0)) > 0 And _ dx.VectorDotProduct(PointToCheck, PlaneNormals(1)) > 0 And _ dx.VectorDotProduct(PointToCheck, PlaneNormals(2)) > 0 Then In3DTriangle = True End If End Function Function GetPlaneDistance(PointToCheck As D3DVECTOR, p1 As D3DVECTOR, p2 As D3DVECTOR, p3 As D3DVECTOR) As Single On Error Resume Next Dim V1 As D3DVECTOR, V2 As D3DVECTOR, CP As D3DVECTOR Dim TempSingle As Single V1.X = p1.X - p2.X V1.Y = p1.Y - p2.Y V1.Z = p1.Z - p2.Z V2.X = p1.X - p3.X V2.Y = p1.Y - p3.Y V2.Z = p1.Z - p3.Z dx.VectorCrossProduct CP, V1, V2 TempSingle = (V1.X ^ 2 + V1.Y ^ 2 + V1.Z ^ 2) CP.X = CP.X / TempSingle CP.Y = CP.Y / TempSingle CP.Z = CP.Z / TempSingle GetPlaneDistance = dx.VectorDotProduct(PointToCheck, CP) End Function It is using DX7 with Visual Basic. Object DX is valid also.
0

Share this post


Link to post
Share on other sites
Actually you're computing your PlaneNormals wrong, the way you do it only works if all sides are of equal length.

What you wan't to do is to compute the triangles normal first (like you do in GetPlaneDistance) then for each PlaneNormal do a crossproduct with the triangle normal and the edge. There is no need to normalize these as you only want to see if the point is inside or outside.

(I don't know any VB so I write it in pseudo code instead)

Compute the normals like this:


VECTOR E0, E1, E2, TriangleNormal;
VECTOR PlaneNormals[3];

E0 = P1 - P0;
E1 = P2 - P1;
E2 = P0 - P2;
TriangleNormal = Normalize(CrossProduct(E0, E1));

PlaneNormals[0] = CrossProduct(E0, TriangleNormal);
PlaneNormals[1] = CrossProduct(E1, TriangleNormal);
PlaneNormals[2] = CrossProduct(E2, TriangleNormal);


You must also do the testing like this:


VectorDotProduct(PointToCheck - P0, PlaneNormals(0)) > 0
VectorDotProduct(PointToCheck - P1, PlaneNormals(1)) > 0
VectorDotProduct(PointToCheck - P2, PlaneNormals(2)) > 0


Your GetPlaneDistance is also wrong in the last test:


GetPlaneDistance = DotProduct(PointToCheck - P0, CP)




Edited by - Spellbound on 2/21/00 5:52:35 PM

Edited by - Spellbound on 2/22/00 4:53:26 PM
0

Share this post


Link to post
Share on other sites
I figured some calculation was kinda weird. Also I thought I replied to this post? Oh well. I was wondering if GetPlaneDistance was wrong. Is that what you are talking about? I tried and it works. Trust me. Anyhoo, I''ll continue trying to understand the new math concepts you posted for the next hour.
0

Share this post


Link to post
Share on other sites