Free website sponsorship

Recent Forum Topics

View Discussion beeen a while

since i been oon here :( - summer break = me away from computer.... - how was everyones summer..... - ....any1 have ideas for a csharp project

View Discussion How to setup php so I can use mail() function?

You can set it up in php.ini. http://www.w3schools.com/PHP/php_ref_mail.asp has information on the configuration options required.

View Discussion Creating Identical Tables: HTML and CSS Article

http://programming-designs.com/page/editorials/item/6 - It was under the articles/editorials section of the main site, not the most logical place but PD only had one html tut...

View Discussion LISP

Lisp is cool in a few ways, but the one that strikes most people is that everything is a list. Hence, it is a pretty good list processor. When the first element of a list is not escaped (quoted - described below), th...

View Discussion Review Script: New Job Board Software

We are happy to announce the release of [url=http://www.smartjobboard.com]SmartJobBoard[/url] job board software. [url=http://www.smartjobboard.com]SmartJobBoard[/url] i...


3D Rotation in VB

Before you start reading this tutorial we'd like to point out there is a zip file on the bottom of the page that contains an example of the tutorial so that you can get an idea of how to apply what you've learned.

This works on the same concept as the camera movement. Just set the camera to the origin (0,0,0) and have it facing forwards. To get the camera facing forwards we have to spin the dots round the camera. We actually spin it in 2D on 2 planes to keep things simple.

To do this we use trigonometry because with a right angled triangle we can keep the hypotenuse the same and change the side lengths. We need 3 pieces of information to do this, the hypotenuse the starting angle of the point and the angle it has to be rotated.

To get the hypotenuse we just use pythagorus a^2 = b^2 + c^2. Applying this to the context we get:

hyp = sqr( x^2 + y^2 )

Next we need the origional angle. To get this we need to use inverse trig.

ang = sin-1 * x / hyp or ang = cos-1 * y / hyp

However in VB its different because you have to use the ATN function.

The ATN function gives you the angle from the ration of 2 sides of a triangle. Don't forget that this is in radians(2 pi radians=360) because that is what VB does. So you just type in the ratio and hey presto (almost):

atn(x/y)

The problem is that VB can't work out whether it's upside down so you can mess around a bit like I did to get it working. Also it doesn't like 0's so you have to filter then out as well.

The two planes that I usually use for rotation are the x,z and y,z. The x,z spins it left and right, z,y spins it up and down and x,y does a barrel roll which I don't care for.

After that the trig is very simple just:

X = Sin(AngY - CamY) * HypY
Z = Cos(AngY - CamY) * HypY

This piece is for rotation around the y axis (so no y coordinate). Which is Sin as which is Cos depends on which you divided by which in the ATN() function.

Conversions

Radians * 180 / pi = Degrees

Degrees * pi/180 = Radians

pi = 4 * atn(1)

Download the source code for this tutorial.