Wednesday, September 19, 2007

A Slight Tangent

I mentioned that if I find something interesting or get a request, I would write an article or tutorial about it. Well the latter has happened, kinda. I often spent time in the C/C++ forums at 3DBuzz.com. Ostamo2, a fellow member, recently brought up a tutorial I started a few years back.

This tutorial covered packaged files, that is collecting a number of files and packaging them into one. I only covered bitmap files but I plan to fix this by re-writing it.

The idea is to use Visual Studio 2005 C++ Express Edition to create an easy to uses package system. This means a GUI packager and class for uses in other programs. I'm still working on which file that will be supported files to be viewable in the Packager. Bitmaps and Obj files as I've done them before.

If anyone has any request for file types or know of any easy to use libraries for file support, please let me know in the comments.

I'm current working on designing and creating a decent package class, and hope to have console based tutorial up in the not to distance future, but it might take a while to finish the final program.

thing2k

Monday, September 10, 2007

Project Focus

As I said as few posts back I was unsure of exactly where I'm heading with this project. Well I've spent sometime thinking about what I want to do and why.

The why overall is pretty straight forward, experience. Also I want to know how things work, how it fits together. The what, is a bit more complex. The plan of attack is to create a Real-Time 3D Graphics Engine. I use Graphics Engine instead of Game Engine as, I hope, it to be flexible enough to work in many situation, including Games and Level Editors. Once the base engine is set up then I might branch it to different genres.

Here are the main features:
  • Graphics Interface independent of API
  • Graphical User Interface Framework
  • Scene/Object Management
  • Collision Detection System
  • Rigid Body Dynamic System
  • Scripting Language
I know the above is still not that specific, but it a start and a direction. The more I work at it the clearing it should become.

As I said previously, I'm starting with a toolbox, a number of common used classes and function that can be used throughout this project. I know I could create these utilities as I went along, but I want a good firm oundation to build upon. Thats why I'm starting with the maths Section.

thing2k

Thursday, September 06, 2007

Toolbox Design

I'm spent the last few days deciding on where to start, I said the toolbox would be first but the question remaining, was which part. The maths system seem the obvious choice, as a number of other systems will rely on them.

The vector class, now this should be relatively straight forward, a class that holds 4 floats, x, y, z and w. Throw in a couple of functions and operators and your done.

Now wait right there, as this class will be used often through out this project, such a gun'ho attitude just won't cut it. A small mistake here would lead to countless error further down the line. So as I plan to treat this project professionally, I'll be designing each class, in reasonable detail, before any coding. Actually I plan to design each system before I start coding.

What this means is sitting down with pen and paper, quite a bit of paper, and thinking about how the system is going to work. The main parts to consider are:
  • The classes and the what they will represent
  • The public, private and protected properties
  • Testing Methods
  • How they interact
  • Just about anything else
When finished, it time to type it up nice and neat, clear and concise.

For the maths section there will be, initially, 3 objects, a vector, a matrix and a quaternion, and these will be represented by the classes cVector, cMatrix and cQuat. Also there will be a number of helper functions, for things like creating a rotation matrix.

Also I say initially as the project progresses there may be a need to come back and add more to this system. Maybe some more helper functions, some slight changes to the classes or even add a new class that I didn't consider before.

For the most part this advise applies for any system, and I'll go through the same routine for each system of the toolbox, and beyond.


thing2k

Thursday, August 30, 2007

A New Project

I'm just starting a new, large and probably over ambitious, project. This project, will be a collections of smaller relatively independent projects that will come together in a final application. For the moment I haven't quite decided what this application will be, just that it will be based around a Real-Time 3D graphics Engine.

I plan to try to design the each part of the project in detail, and to try and keep this blog up-to-date on progress. The starting point will be the Toolbox. The idea behind the Toolbox is for a collection of classes and functions that could be used in most graphical programs. This would include common maths classes for things like vectors and matrices, also useful graphics classes such as Mesh and Texture wrappers and maybe File Handling functions for loading images or model files.

Next in line is a Rendering Engine, I hope to make a interface that will support different rendering APIs, like OpenGL or DirectX. Initially it will have an OpenGL implementation, as my experience in greater and more recent the DX. Also I'm going to consider creating a Software Rastering system from near scratch, this is more a 'just to see if I can' than a feature of the project. From there I'm not sure where I'll go next, maybe a GUI, but as that could be a number of months away, I should have an idea by then.

To finish, if I discover something I think might be of interest or I get a related request, I'll write an article or tutorial about it here.

thing2k

Sunday, March 25, 2007

Sorry I didn't post this before, but this blog is suspended as at the moment with university and my new Son, I just don't have the time. I do hope to come back once I finish uni in June, but I won't be back before that. Sorry thing2k

Thursday, October 05, 2006

Delay Apologies for the delay, this week I've just started back at university so I've been busy. I've got a new tutorial, still with excel, lined up that I hope to post by this weekend. As for future tutorials, which way would you like me to go: I can keep with excel and cover more maths, looking at physics and graphics, or I can make a move into programming C++/OpenGL. Also I've changed the comment options here, now anyone can comment. Cheers thing2k

Friday, September 22, 2006

Bouncing Ball
In this tutorial I will show you how to create a simple 2D bouncing ball simulation in Excel. For those who know Mechanics, we'll be looking at the Increamental/Numerical Method. This is where you have an initial value and calculate the change per frame. For this model the values we need are an initial position, velocity and an acceleration.
The starting position for the ball is -5 meters horizontal and 5 meters above the ground. A small horizontal velocity so the ball move slowly across. For the acceration the gravitial constant of 9.81 has been set, and as that for goes down it's set to minus.
This is where we are going to store the values calculated each frame, the new velocity and the new position. Now to setup the macro, first we need some control values and two buttons Run and Reset.
Cell 'frame' is the number of the current frame, 'sec/frame', is how much a frame is worth in seconds for the calculation you might want to play about with this depending on the speed of the machine. 'total' is the end frame, 'Coefficient' is to do with friction and collision, put basicly it is the percentage of the energy thats left after a collision. Now last time we refered to each cell via absolute methods, "A1", "B1", etc. This time we'll give each cells names. The reason for names is once we've set up this model, we can move the cells around, but will still be linked via the name. Select cell B4 and in the dropdown box where it says B4 type 'Position' and press enter. You have now assigned the name 'Position' to Cell B4. Now select B5 and call it 'Velocity', B6 - 'Acceleration', B9 - 'SimVel' B10 - 'SimPos', F3 - 'frame', F5 - 'total' and F6 - 'Coefficient'. Now the buttons, control can also be given a name, one thats more useful that 'CommandButton1'. In design mode right click on a button and select properties.
In the properties window change the name and caption to 'Run', select the other button and change it to 'Reset'. While still in Design Mode double click on the Reset button and Enter the following: Private Sub Reset_Click() Range("frame") = 0 Range("SimVel")(1, 1) = Range("Velocity")(1, 1) Range("SimVel")(1, 2) = Range("Velocity")(1, 2) Range("SimPos")(1, 1) = Range("position")(1, 1) Range("SimPos")(1, 2) = Range("position")(1, 2) End Sub The above code resets the frame count and the simulation position and velocitys. Now if you double click on the Run button and Enter the following code: Private Sub Run_Click() Call Reset_Click While (Range("frame") < Range("total")) Range("SimVel")(1, 1) = Range("SimVel")(1, 1) + Range("Acceleration")(1, 1) * Range("frame")(2) Range("SimVel")(1, 2) = Range("SimVel")(1, 2) + Range("Acceleration")(1, 2) * Range("frame")(2) Range("SimPos")(1, 1) = Range("SimPos")(1, 1) + Range("SimVel")(1, 1) * Range("frame")(2) NewY = Range("SimPos")(1, 2) + Range("SimVel")(1, 2) * Range("frame")(2) If (NewY < 0) Then Range("SimVel")(1, 2) = -Range("SimVel")(1, 2) * Range("Coefficient") Range("SimPos")(1, 2) = Range("SimPos")(1, 2) + Range("SimVel")(1, 2) * Range("frame")(2) Else Range("SimPos")(1, 2) = NewY End If DoEvents Range("frame") = Range("frame") + 1 Wend End Sub
Now the above code might look very scary, trust me it's not. This is what it does: First we Resets the simulation, then start the while loop. In the loop we calculate the new velocity and position and check that this position hasn't gone below the X-axis. if it has we invert the current velocity reduce it by the coefficient and re-calculate the position. Lastly we refresh the spreadsheet and increament 'frame'. Now thats the simulation done, you have now modeled a ball bouncing, all we need to do is display the results. Select the Simulated Position Values and click on the chart wizard. Select a scatter chart, click next and select the series tab. Now make the 'X Values' point to the X simulated position cell and do the equivlent for the 'Y Values'. If you click on finish you'll now have a chart. Almost finish, now Excel Chart auto size the scales of the axis, what we need to do is lock them down. Select the X-axis of the chart and double click it, this should bring up the format axis dialog, now select the scale tab.
Untick the top four checkboxes set min and max to -5 and 5, the major unit to 1 and the minor to 0.5. Max and min is the range of the axis, major unit is the increament of the scale, set to 1 it will go -5, -4, -3, etc. If you have a small chart you might want to increase this value. Minor unit is only seen if minor gridlines are displayed, this should be set as a fraction of Major unit, a half, fifth, etc. or just left as Auto. Now click Ok and do the same to the y-axis the only difference is the minimum can stay as zero, but remember to untick auto.
Hopefully your final chart will look like the across. Make sure you not in design mode and click run. You should now see the ball bounce. Things for you to try: Different initial settings Adding another ball Collision with the Y-Axis I'll be continuing the Excel theme and post another tutorial some time next week. Not sure what about yet. If you have any requests, leave it in the comments or PM on 3dbuzz.com and I'll see what I can do.
Cheers thing2k