# Need a program to create a 3D square ?

Hai all,

I am initiating a simple project in 3D graphics.I want to do the following things:

1)creating a simple square in 3D
2)Move the sqaure to the given final position through some intermediate position already given.

Please give your suggestions to do these things.

## Comments

• I would sugguest using OpenGL.

Making a square is simple enough.
You specify the points (either hardcoded or in variable form) for the
corners of the first plain, then simply shift it back for the back panel. Rotate 90 degrees on the Y axis and shift 1/2 way left/right for the 2 side panels. Rotate 90 degrees on the X axis and shift 1/2 way up/down for the top and bottom panels.

I haven't actually coded moving an object place to place in OpenGL yet, so I'm not sure how it works, but it shouldn't be hard. Rotating all the planes on the cube (if you wanted to do so) is just one command, not one for each plane. I'm thinking movement should be similar.

www.gametutorials.com has some very nice tutorials on OpenGL.

Hope this helps,
JaguarZ
• I would sugguest using OpenGL as well.
Command for moving objects is
glTranslate(x,y,z);
Nothing more to do after calling that than drawing whatever you want to draw.

XLoom
• hai,
thanks for u'r reply.i have created the 3D object using opengl commands.now i want to recognize it as a sphere or cube or...
How can i do it?Is there any command to scan the lines or pixels and to measure the angle between the lines?
roselin
• No, there is no way (from OpenGL point of view), there may be other ways to recognize as cube or sphere. All OpenGL does is render triangles on screen. The system doesn't have any notion of sphere cube or anything. And No there is no function to calculate the angle between two line in OpenGL - its purely a graphical API, you need to use trignometry to do that. Its not that difficult.

: hai,
: thanks for u'r reply.i have created the 3D object using opengl commands.now i want to recognize it as a sphere or cube or...
: How can i do it?Is there any command to scan the lines or pixels and to measure the angle between the lines?
: roselin
:

• Hi,

I don't quite understand the question. Do you mean that you want to draw the cube or sphere first and pretend you don't know what you have drawn and then try to make computer to recognize whether it is a cube or sphere? If so then first you need to get the image to memory with

void glReadPixels(GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
GLvoid *pixels);

(Description of this function can be found from
http://www.mevis.de/~uwe/opengl/glReadPixels.html)

And after doing this, you find the edges of the object and check whether they are on one line (for cube edge) or do any two farthest edgepoints have the same average (for sphere) or whatever you need to find out.
Is this what you meant?
Anyway I hope it helps , even if it has no connection to the question

XLoom
• hai,

Thank u very much for u'r reply.It's really what i am seeking.Now i got it.if i have any doubt i will contact u.Agin ,lot of thanks...

roselin

: Hi,
:
: I don't quite understand the question. Do you mean that you want to draw the cube or sphere first and pretend you don't know what you have drawn and then try to make computer to recognize whether it is a cube or sphere? If so then first you need to get the image to memory with
:
: void glReadPixels(GLint x,
: GLint y,
: GLsizei width,
: GLsizei height,
: GLenum format,
: GLenum type,
: GLvoid *pixels);
:
: (Description of this function can be found from
: http://www.mevis.de/~uwe/opengl/glReadPixels.html)
:
: And after doing this, you find the edges of the object and check whether they are on one line (for cube edge) or do any two farthest edgepoints have the same average (for sphere) or whatever you need to find out.
: Is this what you meant?
: Anyway I hope it helps , even if it has no connection to the question
:
: XLoom
:

• : Hai all,
:
: I am initiating a simple project in 3D graphics.I want to do the following things:
:
: 1)creating a simple square in 3D
: 2)Move the sqaure to the given final position through some intermediate position already given.
:
: Please give your suggestions to do these things.
:
:

Hello, there

You say you want to make a simple square in 3D(a cube or square?)
and that's simple. You either use the command "auxWireCube()" for a wireframe cube or "auxSolidCube" for a solid cube or either you create your own cube with the "glVertex3f(x,y,z)" function(The prefferable option).
For a square you colud also use the "gl Vertex(x,y,z)" function as follows:

glBegin(GL_SQUARE); //you could also use GL_POLYGON
{
glVertex3f(0.0,0.0,0.0);
glVertex3f(0.0,1.0,0.0);
glVertex3f(1.0,1.0,0.0);
glVertex3f(1.0,0.0,0.0);
}
glEnd();

• : Hai all,
:
: I am initiating a simple project in 3D graphics.I want to do
: the following things:
:
: 1)creating a simple square in 3D
: 2)Move the sqaure to the given final position through
: some intermediate position already given.
:
: Please give your suggestions to do these things.
:
:
I am giving code for 3D square in turbo c

/* Program for 3D square

By:
Mitul Golakiya

E-Mail ID : mitulgolakiya@yahoo.com
mitul.gorkiya@avinashi.com

*/
#include
#include
#include
#include
#include
#include

void main()
{
int x = 250, y = 200;
int gd = DETECT, gm;
initgraph(&gd, &gm, "E:\TC\BGI");
moveto(x, y+100);
lineto(x, y);
lineto(x+25, y-25);
lineto(x+125, y-25);
line(x, y, x+100, y);
line(x, y+100, x+100, y+100);

moveto(x+100, y);
lineto(x+100, y+100);
lineto(x+125, y+75);
lineto(x+125, y-25);
lineto(x+100, y);

setlinestyle(2, 1, 1);
line(x+25, 175, x+25, y+75);
line(x+25, 275, x, y+100);
line(x+25, 275, x+125, y+75);

getch();
getch();
closegraph();
}

Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!