• 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.

MarcusLM

pixel level collision detection using VB/DX7

1 post in this topic

I am writing a simple tile game and I already have it doing collision detection using bounding boxes but now I want to go further and put in some pixel perfect collision detection. Anyone know where I can get some good VB/DX7 source code for this?? I haven''t been able to find any on the net so far. Help please. Thanks. Marcus
0

Share this post


Link to post
Share on other sites
I am having the same trouble and this still is not accurate enough. It is pretty damn close. If anyone finds out an answer to better collision detection then please post it

The way the code works
It uses 3 slope intercept equations to check if the point is inside of a 2D triangle. To check a 3D triangle it checks 3 triangles from one 3D triangle. Look at In3DPoly()


If you cannot read this code then sorry
''-------------------Codes starts here---------------------
Option Explicit
Private Type PointAPI
X As Single
Y As Single
End Type
Function InTriangle(Ray As PointAPI, V1 As PointAPI, V2 As PointAPI, V3 As PointAPI, Optional Accuracy As Single = 1) As Boolean
''this function uses Accuracy really badly and inaccurately so you can try to change it later
On Error Resume Next
Const TapVertex As Single = 1
Dim M As Single
Dim B As Single
Dim Temp As Single
Dim Intersected(2) As Boolean

''Tap verticies if necessary (this method can result to inaccuracy)
If (V1.X) = (V2.X) Then V1.X = V1.X + (TapVertex)
If (V1.X) = (V3.X) Then V3.X = V3.X + (TapVertex)
If (V2.X) = (V3.X) Then V2.X = V2.X + (TapVertex)
''1
M = (V1.Y - V3.Y) / (V1.X - V3.X)
B = V1.Y - (M * V1.X)
Temp = (M * Ray.X + B)
If V2.Y >= (M * V2.X + B) Then
If Not Ray.Y >= Temp - Accuracy Then Exit Function
Else
If Not Ray.Y <= Temp + Accuracy Then Exit Function
End If

''2
M = (V2.Y - V3.Y) / (V2.X - V3.X)
B = V2.Y - (M * V2.X)
Temp = (M * Ray.X + B)
If V1.Y >= (M * V1.X + B) Then
If Not Ray.Y >= Temp - Accuracy Then Exit Function
Else
If Not Ray.Y <= Temp + Accuracy Then Exit Function
End If

''3
M = (V1.Y - V2.Y) / (V1.X - V2.X)
B = V1.Y - (M * V1.X)
Temp = (M * Ray.X + B)
If V3.Y >= (M * V3.X + B) Then
If Not Ray.Y >= Temp - Accuracy Then Exit Function
Else
If Not Ray.Y <= Temp + Accuracy Then Exit Function
End If

If Err = 0 Then InTriangle = True
End Function
Function Get_Y_Int(Ray As D3DVECTOR, RayDirUp As Boolean, V1 As D3DVERTEX, V2 As D3DVERTEX, V3 As D3DVERTEX, ReturnValue As Long) As Boolean
On Error Resume Next
''First check if point is within the x and z of the triangle
If InTriangle(MakePoint(Ray.X, Ray.Z), MakePoint(V1.X, V1.Z), MakePoint(V2.X, V2.Z), MakePoint(V3.X, V3.Z)) = False Then Exit Function


Get_Y_Int = True
End Function
Function In3DPoly(Ray As D3DVECTOR, V1 As D3DVERTEX, V2 As D3DVERTEX, V3 As D3DVERTEX) As Boolean
If noclip = True Then Exit Function
If InTriangle(MakePoint(Ray.X, Ray.Y), MakePoint(V1.X, V1.Y), MakePoint(V2.X, V2.Y), MakePoint(V3.X, V3.Y)) = False Then ''Go down z
Exit Function
End If
If InTriangle(MakePoint(Ray.X, Ray.Z), MakePoint(V1.X, V1.Z), MakePoint(V2.X, V2.Z), MakePoint(V3.X, V3.Z)) = False Then ''Go down y
Exit Function
End If
If InTriangle(MakePoint(Ray.Z, Ray.Y), MakePoint(V1.Z, V1.Y), MakePoint(V2.Z, V2.Y), MakePoint(V3.Z, V3.Y)) = False Then ''Go down x
Exit Function
End If
In3DPoly = True
End Function
Private Function MakePoint(X As Single, Y As Single) As PointAPI
With MakePoint
.X = X
.Y = Y
End With
End Function

Questions or better solutions? Please mail me
ManilaThrilla@juno.com
0

Share this post


Link to post
Share on other sites