A simple raycast from 2D screen to a 3D object (simple and adjusted)

I’m recently working on an assignment where I must build a 3D game for the ipad or Android Tablet. The problem that I must resolve is how to detect collision using the multitouch screen in a 3D environment.

Every 3D environment has an camera that has interested information about the frustum (field of view) and position. The first problem is the conversion from 2D screen into a 3 dimensional space. I need to look-up the unit specs of opengl in order to make a successful conversion from floating points to a location that is pixel based.
1. Conversion (may differ if you use a specific engine).

When we have successfully established a begin point we can then make a end point by using the z-axis in the 3 dimensional space. The next problem is how to detect an intersection with a object using the 3D line constructed using as begin point your finger (2D screen) -> converted into 3D space (using position/center and conversion method). End point defined by a z-axis number (positionCam.z + 1000.0f).
2. Calculate if there is a intersection

The final problem you will face is how to return a pointer towards the object that intersect with the 3D line. There are multiple objects in a 3D environment. It is important that you manage those objects probably in a list or linked list (if you dynamically want to add objects). In my game I use a list with a defined amount of objects. There is no need for a linked list because certain objects will appear on the exact same location when destroyed by the game logic in the code.
3. Return the object who has a intersection with the line.

I described a bit in pseudo how to resolve the problem. Now it’s time to begin with the method’s and calculations. I will be using just a plain simple raycast method.

1. Define Starting position (pseudo)
Event touch called
Get the location (2D position screen)
Get Camera position
Get Perspective Camera
Use Perspective and position to detern the begin position of the line
End Position used with axis z = CamPos.z + 1000.0f.
Use vector on method Collision
Collision check if any objects are in a area around using the 2D method of collision
check x and y.
return object (pointer)

1. Define starting position (c++)
<code will be published soon ;-) >

Posted in Uncategorized | Leave a comment

Marmalade Template Game Project

I’ve been experimenting with the Marmalade API for some time. For those who haven’t heard about Marmalade. Marmalade is a specific cross-compiler for mobile applications. You can develop applications in c++ using visual studio from Microsoft. They have set up an environment to compile your code for Android, iOS or Any other platform that is supported. The newest version is also supporting web and HTML5.

It’s a easy and well documented platform for developers who are starting to develop a application for the smart phone. I can admit that certain functions that are OS specific are not available or not working properly but they try to implement those functions if the develop-community ask for it. There are many Android and iOS specific functions implemented into the Marmalade API. You can try them by compiling the examples (delivered with the API). Continue reading

Posted in C++/C | Comments Off

Framework vs Developer

The industry of software development is growing and growing, not only for the desktop market but also for the internet sector (web development). Everywhere you go as a back-end web developer you hear new frameworks being developed from scratch. Some of them are already big (example: Zend Framework) but others are supported by the open source community.

It’s crazy how many frameworks there are. Web developers must make a good decision on which platform to use. If they choose the wrong framework to put their work on. Knowing and learning the framework. The time invested in the framework would be for nothing.

There are many reasons that a framework will be a epic failure.
1. Development of the framework stops or slows down.
2. Support can be slow.
3. You as developer depend on the framework.
4. Sudden changes in the framework can lead to re-design the back-end of your own code.

The problem is that we want to develop a website in a eye-wink by using third party frameworks or cms solutions. It’s possible to do this but at the same time developers must learn the framework or cms before they can deploy the design into the cms or framework.

Do know what you are doing and make the code your own. It’s crucial that you learn/know how the framework works. If you don’t know… well then you can’t extent it towards the customers will (special feature requests).

Making your own framework depends on how much features you want. If it’s basic you can consider it. Basic in the layout of get, set and delete interacrions.

Next post I make a example of a framework based on the MVC model.

~ Barth steeg.

Posted in PHP, Theory | Tagged , | Comments Off

Marmalade SDK, 2D animation in a simple class

When creating a 2D game, most of them have animation in them creating the aesthetics of the game. How as a programmer are you going to develop a system that can handle animation? Looking back to the old consoles like the nes and snes of nintendo they use sprite’s.

Sprite’s are multiple images in one image. The image can be defined as a spritesheet. This
image contains information about every frame of animation. An example of a sprite is shown here below.

Example Spritesheet

 

You can see the animation of rotating.

How are we going to read and display the animation using Marmalade. There are serveral crucial functions needed to get the results you want.

- The function Iw2DDrawImageRegion
(used to draw a specific part of the image)

- The function s3eDeviceYield
(sets the amount of calls, we use it for limiting the number of drawings towards our defined frames per second. A normal game on a mobile phone will be drawn 25 times in a second). Continue reading

Posted in C++/C, Games, Mobile Games | Tagged , , , , , , , , | Comments Off