Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Collision Detection using OpenGL

Trying to make pinball using OpenGL the collision detection I am using in the code is not working at all 

The collision detection i have implemented is in the layout.cpp and all the variables used is in ball.cpp(i have attached files with it)

I am using this formula to find the shortest distance of ball from the line:-

distance = |(p - a) * (p - b)| / |b - a|

( * operator used in the equation is cross product )

where p is position vector of center of ball , a and b are position vectors of endpoints of a line

please share if anyone have any other way of detecting collision in CPP.

layout.txt

ball.txt

9ff77faa33b1e9e4acc4bdec5cbde7d4.png

My PC specs :- CPU i7- 8700k, Motherboard Maximus XI Hero,  RAM 32 GB Gskill Trident Z RGB, GPU Asus Rog Strix RTX 2080 , Case Phanteks enthoo evolv atx - tg edition, Storage 2 TB Seagate baracuda + 512GB samsung SSD, PSU corsair RMX 1000 Watt Gold PSU, Display(s) Acer Predator Z271U 27" WQHD Curved and Benq Zowie XL 2456, Cooling Asus ROG RYUO 240.

 

My Laptop :- Lenovo Y50-70 -CPU i7- 4710HQ, RAM 16 GB , GPU Gtx 860m 4GB, Storage 1TB HDD + 128GB SSD

Link to comment
Share on other sites

Link to post
Share on other sites

The cross product only makes sense in 3d space.

 

You might have misread this answer; the formula you need is

 

[(p - a) . (p - b)] / |b - a|2

 

Where . is the dot product; this gives you the projection of the point on the line extended from the segment; you can then clamp the projection to the segment and work out the distance between that and the point.

image.png

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

I did some 2D graphics using STD DRAW and when I did collision I only really worried about circles. 

Basically to stop from going to the edge I did

 


If (location + radius >= screen width)

//bounce. 

 

I did have a few other things but I don’t recall what I did. If I have the files, I’ll post what I did. Java is close enough to C++ that you’ll understand what's going on. 

 

Edit 

I saw some books for cheap on amazon about 2D collision. Might be worth it. 

LTT Fan Fiction:

My new favourite thread:

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×