Collision Detection 2 - Point Circle

Posted on April 29, 2012

Point - Circle


Perhaps one of the most fundamental aspects to collision testing is to see if a point in space is within the bounds of a circle or sphere.


This is done by collapsing the line between the centre of the circle and point into a scalar length, and then comparing it with the radius of the circle.





more



Here we have 2 positions (Marked by the black dots), the Origin (Centre) of the circle and the Point. If we split the X and Y coordinates we can make a triangle. Pythagoras can then be used to get the Hypotenuse, giving us the length between the 2 points:



A

² =

B

² +

C

²





So:


CircleOriginToPoint²

=

(CircleOriginXToPointX)²

+

(CircleOriginYToPointY)²

Fill in the X and Y Distances:


CP² = (Cx – Px)² + (Cy – Py)²


To get

CP

from

CP

² we have to square root:



√(CP²) = Length of the Circle Origin to Point

We can now compare this

length

to the

radius

of the circle, If

CP <= Radius

a collision occurs as the point is inside the circle.





CP



Radius

In our example no collision occurs



This same method can be done with a sphere in 3D, we just add Z values in the Pythagoras step



CP² = (Cx – Px)² + (Cy – Py)² + (Cz - Pz)²

TIP:

You can increase performance of the distance calculation by negating the square root (Which is expensive), and instead squaring the radius for comparison. BE WARNED: know your limits when doing this, the max value of a square on int32 is about 2,000,000,000 that sounds a lot, but its only 46,340 squared, depending on your scale this could be as little as 460meters before your calculations will no longer work!


Remember the sphere's radius is largest at its origin no matter what direction the ray comes from, which allows the problem to be converted into a 2D point in Circle test.


[display-posts category="collision" posts_per_page="-1" include_date="true" order="ASC" orderby="title"]','Collision Detection 2 - Point Circle


Collision Detection 1 - Introduction

Posted on April 29, 2012

Preface

started writing these collision tutorials as I have recently learnt some of these techniques, and found many tutorials completely useless at explaining the core concepts to a novice. In this I aim to show you how I got my head around the concepts of collision detection, and response. Instead of providing you with code to blindly copy and paste, I hope this will give you enough information to go on to create your own code, and know how it works.

Stuff you should already know:



Parallel


 



Perpendicular



Normal 


   


  • Most 3D maths problems can be flattened into 2 Dimensional problems, If your stuck, solve it in 2D then move into the 3rd dimension.

  • Use a pen and paper to draw problems out.

  • Unit or normalised vector (Wikipedia makes it sound way more complicated than it is, just know the X and Y values fall only in the range of -1 to 1.
    Think of this as a percentage of direction, (1,0) will be 100% right 0% up, (-1,-1) will be moving bottom left at 100%.


Next:


Astral Catapult

Posted on April 24, 2012


Physics based Platformer for PC and Windows Phone 7
Game design by Jack Dye, developed by Silicon foundry (Matthew Harris, David Hart, David Armstrong, William Dann, Ashley Eglin, Jack Dye)

Design
The basic design was formed in a response to a brief set by aim higher, which was to create a short game to inspire prospective students the benefits of university education and debunk some urban myths about the type of people who go to university.

The game begins with the player as a ball on a starting platform, the player must execute a series of jumps to bypass obstacles and land on green safe platforms, the objective of the game is to make it through the level without dying.

The player loses if the ball lands on spikes, lava, or rolls to a stop without landing on a green platform.




Level Designs
To make the game more interesting 8 Powerups were designed to enhance gameplay:

Subject PowerUp Effect
Chemistry Sticky Ball (sticks to walls and ceilings)
Physics Adds an Aiming guide
Maths Calculates Reflections on wall collisions
Geography Displays a Mini Map of off-screen platforms
Art Adds partial effects to balls motion
Re Restores the ball from X turns ago
History Shows Previous shot"s guide
Biology X% chance of bird saving ball when falling
Music Subwoofer blast from below gives the ball a "double jump"


Along the way when the player collected powerups the player will be shown information about continuing the subject in higher education, a combination of powerups would adjust the possible degrees that can be taken with the a levels and in turn give different career paths.

The powerups are stackable so collecting more of a powerup increases its effectiveness.


Game:
The game was developed over a month with a university set deadline which we had to meet.
Our team was split up into 3 programmers, 1 graphics artist, 1 tool programmer and a documenter.

At the end of development, we had a fully functioning game with 5 levels, 5 powerups, 6 platform types and a level editor.


I coded most of the physics, ball, powerup and platform behaviors, and created 3 of the levels.


Download:
http://jackdye.co.uk/Uploads/AstralCatapult.zip 

Screenshots:
[gallery link="file"]



Level Editor
The level editor is fully functioning, with a test mode to directly start the game in the current level, and is used to place platforms and powerups, and change the level size and background allowing quick deployment of a large number of varying levels

 


Motion Capture FPS

Posted on April 20, 2012

This is an extract from my 3rd year dissertation

Introduction

Using a Vicon optical motion capture suite (which was available for use in my university) I wanted to take motion capture beyond the movies, and implement a fully interactive gaming experience in which the player is the controller, This allows 6 Degrees of freedom for the player to move in, so leaning around corners, ducking, view freedom from your gun and blind firing, are realised and more immersive than a traditional keyboard and mouse setup could ever be.

more

The Vicon suite was one of my primary reasons for choosing the University Of Hull, and I am beyond thrilled to be able to use it for my undergraduate dissertation.


The initial specification I drew up over the summer was for the player to wear a Head mounted LCD display, which allows 3D stereoscopic viewing of my virtual environment, attached to the HMD and gun are fiducial markers that enable optical tracking, the player aims with the toy gun (Which is modified with a wireless mouse) to shoot down virtual enemies.





Game engine progress


My game engine has been created from scratch in OpenGL and C++.


It Currently features:



  • 3D Stereoscopic rendering

  • First person tracking support (for HMD's)

  • Paralax Motion Head tracking support (for monitors/projectors)

  • GLSL shader support, with bump mapping and per fragment lighting

  • Skybox shader

  • OBJ model loader and texture support

  • Collision detection for the world, AI and gun (Ray-Sphere, AABB, OBB)

  • AI enemies which seek out the player avoiding world objects.

  • TCP communication with a Vicon motion capture suite

  •  Configurable files for tracking data transformations


It has been particular intensive in matrices with converting from the tracking coordinate system to OpenGL's co-ordinate system, I learnt openGL's shader pipeline to enable shaders that I created from my

GLSL battlefield

to work within the engine. Wrote an AI collision avoidance and steering algorithm based on vector maths.



Tools used


Visual Studio C++


FreeGlut


GLSL


Wavefront OBJ


Render Monkey - Shader design


Blender - Gun model design & model cleanup/UV mapping


Google Sketchup - Level design


Sculptris - Charater models


Photoshop - General texturing


Vicon Real time emulator



Screenshots



These screenshots are now outdated (See below!)



Clockwise: Spectator camera view of level, First person View, 'Flyray' flying enemy with bumpmapping





Close up of the players area in which they have to defend



10/03/11 Update



Rooftop level progress (Google Sketchup)


Google sketchup makes an interesting tool for level design, with the use of a 3rd party OBJ explorer the CAD tool could export models directly into my game, The texture mapping and dynamic geometry features of sketchup pretty much sold it to me as my weapon of choice to create my 3D rooftop.




20/03/2011 Update



Level is fully complete, Textures were aquired online, and bump maps were created using Nivida's Normal map plugin for photoshop. The GLM model class was modified to support 2 textures and a bumpmaped phong shader, with a fallback shader if there is no normal map for a texture. Normal maps are defined in the models .mtl file.





30/03/2011 Update



The HMD idea was scrapped due to the age of the hardware, mainly the LCD screens offered poor contrast.



Instead the game now runs on a 5x3m 3D Rear projection wall in the Vicon suite, and makes use of paralax motion tracking (Inspired from:

http://www.youtube.com/watch?v=Jd3-eiid-Uw

). It makes use of 3D ontop of the paralax to give an incredible effect of the world ajoining through the screen.





Video showing the paralax motion in action, notice how the effect is lost when tracking is lost in the 5th seccond. Although this is recoreded in 2D, the mouse seems to float far infront of the world purely by the paralax illusion. In 3D this effect is hightened, and the gun appears to float far infront of the screen as if the user is holding it.



[youtube=http://youtu.be/HEabUd_E-UM]','Motion Capture Parallax FPS


Hacking memory sticks

Posted on April 19, 2012
Into the unknown...


About a year ago, Humberside police were handing out free memory sticks, at our uni's fresher's fare. Great! I thought i'll have one of them. 1GB stick for nothing, can't go wrong...


So, I got it home, plugged it in, boom, fullscreen power point slideshow on how to protect your property...... borderline adaware! Into the draw the usb went and lived. Another fresher fare came and went and I got another 2 of these usbs, 3gb total, which I couldn't use without being shafted a load of adverts every time I plugged them in.

These 'promo' sticks worked by having 2 partitions, a CDFS partition (for the adverts) and a normal FAT32 partition (for files). As the name suggests the CDFS partition is derived from cds, with cds being read only, windows will not allow you to modify the partition; to the extent you cannot format the partition to kill it off. Another ghastly feature of CDFS is the autorun ability, which it's only use is to spread malware, in the form of Sony's spyware that appeared on a number legitimate cd's in 2005, to more recent appearing of household virus' spread via usb's.


For the purpose of promotion, this ugly feature was used to autorun the power point presentation.



Opening up...

So I sought to look onto how to remove the partition once and for all, grabbing a screwdriver I pried open the usb to get a look at the manufacture of this nobranded usb.



Captured using a life cam HD


We can see the manufacture is 'chipsbank' with a model code of 'CBM2091' digging around Google, I came across many forum posts asking how to get rid of the promo. 


I eventually stumbled across the manufacture tool that's given to companies to flash their promo material onto the sticks.


Fixing the unfixable...


This is called UMP Tool, not sure of the acronym, but never-the-less, I managed to obtain a copy for my chip (2091), simply by googling UMP tool 2091, which lead me to to a Russian site and finally the program itself (UMP TOOL V1.9.5). The current version of UMP tool goes to 4.1, however each version is specific to the version of the flash chip (so you'll need to open each usb, to get the chip version, to get the correct flasher).


Started the baby up, and being unflattered by the initial layout of the program, I went into the settings, and was quite blown away with the diversity of options:

 



As you can see, you can do quite allot, from making a password protected usb (which normally adds £5/£10 to the price of a retail stick) right up to tinkering the flash rate of the usb when its being read.


Excitedly, I flashed my first 'home brand' usb, which destroyed the evil promotional partition and gave me full access to the disk. Success! It worked. I could format it again burning an ISO as a CDFS partition, quite exciting stuff. 


But. not as exciting as when I got to my 2nd and 3rd usb....


Hidden Secret...


During formatting, I noticed it had 2048 blocks, and it would show the number of blocks as being corrupt/unusable.
Fine I thought, flash memory is prone to having a certain %age of corrupt/bad blocks.
 The manufacture had to compensate for this, had installed 2048 blocks (2GB). This allowed for a 50% corruption rate and still maintain the advertised 1GB to the consumer.

Now, here comes the fun part, by flashing using the UMP tool, It gave me access every single block that wasn't corrupt! Making my 1GB stick's grow to 1.46GB and 1.86GB!
(having about 25% and 8% bad blocks)


Quite a daunting realization occurred; people pay for the 2GB chip, but are only allowed 1GB of it, making a theoretical loss of 50% on their purchase.

 A consumer con? 


Well... due to the high volatility of flash memory, I can see why manufactures would rather guarantee 1GB than give consumers room to complain about their random amount of memory between 1GB and 2GB, after all it is at the customers expense. 


But I'm left with a thought, how much unused & hidden memory is in your shiny stick?
At this ratio, could a 8gb stick secretly contain a 16gb chip?



If you find out let me know!


 



Don't trust what's on the tin, after all you paid for what's on the inside.


Stick on the left now is enjoying life as a music usb for my car stereo, with it formatting to the largest size.


Sources:


UMPTOOL 1.95 For chip Version 2091:


http://flashboot.ru/old/index.php?name=Files&op=view_file&lid=81


UMPTOOL 4.02 (Not sure if backwards compatable with 2091)



http://www.filecrop.com/v4.02.rar-umptool.html

I also got a 2093 version for the v2.0 stick on the left from rapidshare.
I'm unsure on the legality of these tools, so I'm unable to host them myself, but a quick google for "UMPTool" and your CB number should point you where you need. 


You can also check out the flashboot.ru directory for a flasher if you have another other brand of USB:


http://flashboot.ru/iflash/

Red Alert 2 and Yuris Revenge on Windows 7

Posted on April 17, 2012

In this post I aim to explain how to get Red alert 2 and Yuri's revenge working on Windows 7


Contents:


1. Running on win 7


2. Lan Play


3. Lan Patch issues


4. Copyprotection


5. Maps



more

Getting RA2/YR to run on Windows 7:

If when starting RA2:YR on Windows vista or Windows 7 you are greeted with:


***FATAL*** String Manager Failed to Initialize Properly



Vista

In vista the simple trick was to right click and run the game as an administrator. This allowed the game to access the stringmanager dlls.



Windows 7

For me only disabling User account control (UAC) worked. This is because uac is a lot more forceful in windows 7 and won't allow RA2.exe to access the string manager .dll's in the windows directory.




 To do this fix:

1) Open control panel


2) Click users


3) Click Modify User access control settings.


4) Set the status to "Never notify"


5) Accept the series of warnings.


6) Reboot your machine.



You can now run RA2:YR once your computer reboots.


If this fails to work first time, It might be an idea to enable windows 2000 compatibility mode on every exe in the ra2 folder.


After playing Yuri its recommended you turn UAC back on, Repeat the steps above, setting it back to the default setting:




Lan Play


Without the fuss of Hamachi 2.0

At the time of Vista, Microsoft had stopped supporting the IPX protocol, which is required by RA2 to perform network play. Luckily some bright sparks managed to hack the games code to make it run on the UDP protocol, which all machines support!


This is dubbed as the lan patch.


There are 2 ways to obtain the lan patch (depending on your boxed copy)



First Decade Patch


If you have "The first decade" version of Yuri, its easiest if you get the unofficial 1.03 patch. Google "TFD 1.03" or click below.


This allows you to play without the need of the TFD disk (unbelievably useful)!


More importantly, it contains the lan patch, and installs it all for you! It replaces the network dll (wsock.dll) to use UDP instead of IPX.


Download:
http://www.fileplay.net/file/4289/the-first-decade-patch-1-03






RA2:YR Boxset


If you are lucky enough to have the orignal box set, you'll need the stand alone IPX->UDP patch.


Download below, unzip, and place the wsock.dll in the ".../westwood/ra2" folder overwriting the existing wsock.dll.


Download:


http://jackdye.co.uk/Uploads/ts_ra2_lanpatch_1_00.zip



However, both methods share the same drawback:


2 modified wsock.dlls cannot talk to eachother in Internet play (lan play is fine however).


If you try, your game will disconnect as soon as you exit the game lobby with a black screen.



A simple fix however:



To Play over the internet:

Rename wsock.dll in the ra2 folder to disable it (i.e wsock.dis)



To Play over a LAN:

Then name wsock.dis back (wsock.dll)


Units blow up at the start of the game?


If your units blow up every time you start the game, you have to reinstall.


This is due to the anti piracy switch in the game; If same 2 cd keys see each other (LAN or Internet), as they will trigger the switch causing your units to blow up at the start of every game. I'm not sure if there's a registry key to revert the change without having to reinstall.



But for me a quick reinstall works, or you could download a crack to remove the piracy switch altogether.


Maps


If you ever want to install additional maps, Simply place the map file (.mix) in the ra2 folder:



".../westwood/ra2"

If you wish to make your own maps for Red Alert 2 Yuri's revenge, a official map editor exists:



http://jackdye.co.uk/Uploads/FA2YR101.zip

Using the map editor, you can create levels for Yuris Revenge and Red alert 2 in both single player and multiplayer.