3D plotting

TaleofTimes
05-04-2006, 07:32 PM
Hello

I've looked at several sites regarding 3d plotting using gdi+, but i haven't been able to find what i'm really looking for.

My final goal, if ur interested, is to create a cube and be able to rotate it on the x and y axis from it's perfect center (so when cube rotates up and down or to the sides it doesn't change position).

i'm starting off with plotting a (x, y, z) point, but i'm having trouble

anyone know of good resources for this kind of thing?

Rockoon
05-05-2006, 04:21 AM
Terminology (for you to research):

Rotation, Translation, and Projection.
Vector and Matrix math.
Painters algorithm.

Do not confuse these terms with any GDI+ functions which perform these tasks in 2D.

Notes:

Mathematically, rotation always happens around the origin.

Converting a 3D coordinate into a 2D coordinate is called projection.

Once you learn the math involved and perform the necessary computations in your own code, you can use GDI+'s polygon routines to actualy draw on the graphics surface (or you can write your own.)

Moohasha
05-07-2006, 09:35 PM
As Rockoon mentioned, rotation occurs around the origin. That means that if you want to rotate a cube without "moving" it, and the cube's center is positioned at (5, 2, 2), you would need to translate (move) the cube to the origin, rotate it, and move it back to (5, 2, 2). This translation-rotation-translation process would need to be performed each time the cube is rotated.
The same thing goes for scaling and shearing (sp?). All performed around the origin. Once you start looking into all of this, you'll find you can create Translation Matrices and Rotation Matricies that you can just multiply against each point in your object to translate or rotate the entire object. Makes things MUCH easier to deal with.

jeroen1990
05-31-2006, 12:14 PM
a good way to draw a 3d cube with gdi+ is by using 2 rectangle and 4 lines. i preferr using point to point drawing:

e.graphics.drawrectangle(pens.blue,x,y,100,100)
e.graphics.drawrectangle(pens.blue,x + 30,y -30,100,100)
Dim points As Point() = { _
New Point(x, y), _
New Point(x + 30, y + 30)}
....
....'repeat this for the 4 lines that are between the rectangles
....
Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawCurve(pen, points, 0F)

Chris Ara
06-07-2006, 01:17 PM
Some time ago I was learning direct3d and 3d geometry to help me better understand it I built an application that renders 3d wire frame models(no textured) you can translate,rotate,and scale the models with the application. If you would like I could e-mail the code or I might just paste it on my web site. Here the basic math though for converting a 3d point into 2d space

pointX = -(pointX - camera.position.x)/(pointZ - camera.position.Z) * Zoom +
screen.width / 2

pointY = (pointY - cameraposition.y)/(pointz - camera.position.z) * Zoom + screen.height/2

here is a basic breakdown of this first your x and y screen co-ordinates to get the 3d position just divide them by Z(depth).

x = -x/z
y = y/z

depending on your up direction -y or +y either the x or y co-ordinate must be negative.

Now you must make an origin(center point) to render from this will be the center of your screen so just add half the width to x and half the height to y

x = x/z + screenwidth/2
y = y/z + screenheight/2

this will allow you to render basic 3d shapes, yet in order for them to be moved(translated , rotated , or scaled) you must have a camera position(your eyes view) to reference where the shape is being moved to. basically subtract each point from the camera position.


x = -(x - cameraX)/(z - cameraZ) + screenwidth / 2
y = (y - cameraY)/(z - cameraZ) + screenheight / 2

Finally your zoom wich is the length your camera lens can see in the x and y directions. Zoom usaully will be the screenwidth / 1.5 or 2 depending on the width of your rendering area you might want to change it lower or higher. just multiply your values by the zoom you can also use a zoomX and ZoomY if you rendering on a irregular area like a widescreen view.

x = -(x - cameraX)/(z - cameraZ) * zoom + screenwidth / 2
y = (y - cameraY)/(z - cameraZ) * zoom + screenheight / 2

o.k. there you have that is little much for one short reply Check my site later and I will post this tutorial in the .net programming section. With a little more detail of course. www.cesvisualbasic.com

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum