3D Graphics

Moderators: Sephiroth
Number of threads: 274
Number of posts: 896

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need a program to create a 3D square ? Posted by roselin on 23 Jul 2003 at 11:16 PM
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.

Report
Re: Need a program to create a 3D square ? Posted by JaguarZ on 3 Aug 2003 at 10:39 AM
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
Report
Re: Need a program to create a 3D square ? Posted by XLoom on 28 Aug 2003 at 6:38 AM
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
Report
Re: Need a program to create a 3D square ? Posted by roselin on 1 Sept 2003 at 9:07 PM
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
Report
Re: Need a program to create a 3D square ? Posted by gautam on 2 Sept 2003 at 7:28 AM
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
:

Report
Re: Need a program to create a 3D square ? Posted by XLoom on 2 Sept 2003 at 9:18 AM
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
Report
Re: Need a program to create a 3D square ? Posted by roselin on 5 Sept 2003 at 3:19 AM
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
:

Report
Re: Need a program to create a 3D square ? Posted by liviu2003 on 15 Dec 2003 at 4:01 AM
: 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();

Report
Re: Need a program to create a 3D square ? Posted by mitulgolakiya on 28 Aug 2008 at 8:16 PM
: 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 <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <iostream.h>

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();
}


Attachment: 3DVIEW.CPP (641 Bytes | downloaded 240 times)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.