Projection

Can anyone offer a suggestion as to what is happening here?

http://imgur.com/bHq67

I have been using this coordinate projection code for a while using basic lines
to draw...and it always seemed to work. It wasn't until I started to implement
the painters algorithm that i realised something must be wrong with the
projection code.

The following values were used. I have drawn lines from different vertices to
each point in a different colour in the picture in an attempt to show where
these points lie in my 3d image.

1
2
3
4
5
6
7
//Red lines
CameraPosition = coordinate(0, 20, 100);

//Green lines
ViewerPosition = coordinate(0, 10, 100);

//Blue lines = coordinate(0, 0, 0) 


This is the function I use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
plot RotateScaleTranslate3D::plot3DCoordinate(ProjectionSettings * ps, coordinate c) {
	plot coorTemp;
	vector<float> d;
	coordinate a = coordinate(c.X * ps->Scaler.X * ps->Zoom.X,
								c.Y * ps->Scaler.Y * ps->Zoom.Y,
								c.Z * ps->Scaler.Z * ps->Zoom.Z);
	coordinate cp = ps->CameraPosition;
	eulerAngles cr = ps->CameraRotation;
	coordinate vp = ps->ViewerPosition;
	float temp = myMaths::cosine(cr.Y) * (a.Z - cp.Z) + myMaths::sine(cr.Y) * (myMaths::sine(cr.Z) * (a.Y - cp.Y) + myMaths::cosine(cr.Z) * (a.X - cp.X));
	d.X = myMaths::cosine(cr.Y) * (myMaths::sine(cr.Z) * (a.Y - cp.Y) + myMaths::cosine(cr.Z) * (a.X - cp.X)) - myMaths::sine(cr.Y) * (a.Z - cp.Z);
	d.Y = myMaths::sine(cr.X) * temp + myMaths::cosine(cr.X) * (myMaths::cosine(cr.Z) * (a.Y - cp.Y) - myMaths::sine(cr.Z) * (a.X - cp.X));
	d.Z = myMaths::cosine(cr.X) * temp - myMaths::sine(cr.X) * (myMaths::cosine(cr.Z) * (a.Y - cp.Y) - myMaths::sine(cr.Z) * (a.X - cp.X));
	if (ps->CoordinateInvertX) { d.X = 0 - d.X; };
	if (ps->CoordinateInvertY) { d.Y = 0 - d.Y; };
	if (ps->CoordinateInvertZ) { d.Z = 0 - d.Z; };
	coorTemp.x = (plotElement) ((d.X - vp.X) * (vp.Z / d.Z));
	coorTemp.y = (plotElement) ((d.Y - vp.Y) * (vp.Z / d.Z));
	coorTemp.x += ps->Offset.x + ps->ManualOffset.x; //manual is shit. get rid.
	coorTemp.y += ps->Offset.y + ps->ManualOffset.y;
	return coorTemp;
};


I don't understand why the viewerposition is within the scene and not where I am
viewing. i would expect the green lines to come toward me.

The cube is not rendered properly because the z buffer values are calculated
from the viewerposition coordinate which is in the middle of the image.

Any ideas, please?
Last edited on
In case anyone wants to see the value of the cubes coordinates...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

		model3D * objBase = new model3D();
		objBase->triangleList.addItem(mappedTriangle(0, 1, 3, cRed));
		objBase->triangleList.addItem(mappedTriangle(1, 2, 3, cRed));
		objBase->triangleList.addItem(mappedTriangle(4, 5, 6, cGreen));
		objBase->triangleList.addItem(mappedTriangle(4, 6, 7, cGreen));
		objBase->triangleList.addItem(mappedTriangle(2, 3, 7, cBlue));
		objBase->triangleList.addItem(mappedTriangle(2, 6, 7, cBlue));
		objBase->triangleList.addItem(mappedTriangle(0, 4, 5, cPurple));
		objBase->triangleList.addItem(mappedTriangle(0, 1, 5, cPurple));
		objBase->triangleList.addItem(mappedTriangle(3, 4, 7, cOrange));
		objBase->triangleList.addItem(mappedTriangle(0, 3, 4, cOrange));
		objBase->triangleList.addItem(mappedTriangle(1, 2, 5, cYellow));
		objBase->triangleList.addItem(mappedTriangle(2, 5, 6, cYellow));
		objBase->pointList.addItem(coordinate(-50, -60, -50));
		objBase->pointList.addItem(coordinate(-50, -20, -50));
		objBase->pointList.addItem(coordinate(50, -20, -50));
		objBase->pointList.addItem(coordinate(50, -60, -50));
		objBase->pointList.addItem(coordinate(-50, -60, 50));
		objBase->pointList.addItem(coordinate(-50, -20, 50));
		objBase->pointList.addItem(coordinate(50, -20, 50));
		objBase->pointList.addItem(coordinate(50, -60, 50));
		dModel->modelList.addItem(objBase);
Topic archived. No new replies allowed.