Hey bebi. It's very simple. Let's say u need to draw line between 2 points in 3d. 1st point: x1, y1, z1. 2nd point: x2, y2, z2. Camera 0, 0, 0.
int x1Screen = (int)(x1/z1*SCREEN_X_SIZE/2 + (SCREEN_X_SIZE/2));
int y1Screen = (int)(y1/z1*SCREEN_X_SIZE/2 + (SCREEN_X_SIZE/2));
int x2Screen = (int)(x2/z2*SCREEN_X_SIZE/2 + (SCREEN_X_SIZE/2));
int xyScreen = (int)(y2/z2*SCREEN_X_SIZE/2 + (SCREEN_X_SIZE/2));
Then just draw 2d line using Graphics class. Good luck. Have a question? Feel free to luck. I am mega mind in 3d gfx. U know...
r.hollenstein. I know everything i need to know about 3d gfx. 3d surface - no problem. there are many variants it could be done. if cam moves then the formulas for points is a little bit longer:
let's say we have point (x, y, z) and cam (xCam, yCam, zCam)
int xScreen = (int)((x-xCam) / (z-zCam) * X_SCREEN_SIZE /2 + (X_SCREEN_SIZE/2));
if cam turns the formula will be much more longer.
So, the formula would be:
int xScreen = (int)((x-xCam)/(z-zCam)*X_SCREEN_SIZE/2+(Y_SCREEN_SIZE/2));
int yScreen = (int)((y-yCam)/(z-zCam)*SCREEN_X_SIZE/2+(SCREEN_Y_SIZE/2));
Is this correct? Because I think in the formula you posted that considers the cam, the second SCREEN_X should be SCREEN_Y?
To which direction is the camera looking in this formula (anlge: x,y,z)?
R. Hollenstein
Hi MaxJust,
It sounds like you are just the person to help me out here.
I have a graphing requirement to render a data set in the same way as you can in Excel, using a 3d surface render.
I am a little stuck as to how to accomplish this. Say for example my data set is something like this:
1Y2Y3Y
1M11.417.918.9
2M12.618.519.5
3M13.718.919.8
4M16.519.920.6
I will assume my X are rows and Y are columns and Z is the value. I could calculate the X and Y using the screen size / number of points I think.
I saw your algorithm earlier in the group, I was wondering how I would apply that to this data set?
Cheers,
Steve