Sphere without fill in 3D graphic
I want to draw a cube and circles like开发者_如何转开发 this (sphere without fill). I'm using OpenTK
http://farm7.static.flickr.com/6074/6097051938_cb0b798ce0_z.jpg
I've been having issue as below: I've try to draw a circle at the top of Cube. But when we rotate Oy the cube and the circle, the circle become Ellipse.
I've try to draw sphere instead circle. But can not make it like the image above. Anybody have the solution? Thanks in advance!
And this is mine http://farm7.static.flickr.com/6061/6096573967_22d56b2c2a_z.jpg
Draw a circle that always faces the camera, drawing a circle is easy. Just create a ring of vertices and use GL_LINE_STRIP to draw it. Creating a transformation matrix that always looks at the camera is a bit involved. Here is the code that does this. Simply set this one as your world matrix.
Matrix4 createBillbordMatrix(Vector3 position, Vector3 cameraPosition, vector3 up)
{
Vector3 Z = Vector3.Normalize(direction - cameraPosition);
Vector3 X = Vector3.Normalize(Vector3.Cross(up, Zaxis));
Vector3 Y = Vector3.Cross(ZAxis, XAxis);
Vector3 T = cameraPosition;
return new Matrix4(X.X, X.Y, X.Z, 0,
Y.X, Y.Y, Y.Z, 0,
Z.X, Z.Y, Z.Z, 0,
T.X, T.Y, T.Z, 1);
}
If you know how matricies work, you should be able to figure it how it works ;). Otherwise don't worry about it, you shouldn't have a problem implementing it.
Draw a circle on a 2D plane.
Use a special 2D transform, and since these are just wire mesh looking renderings and all the same color, you can draw the 2D part last.
So:
1. Draw the 3D part
2. Transform the corners to the 2D coords
3. Draw the circles.
Im assuming you want the circles to be constant shape and size, no matter the rotation of the cube.
This may help get you started: http://www.opentk.com/node/2478
This will be by far faster than attempting to let it help you draw a sphere, even an unshaded one.
精彩评论