-
-
#include <windows.h>
-
#include <gl\gl.h>
-
#include <gl\glut.h>
-
#include <stdlib.h>
-
#include <math.h>
-
#include <vector>
-
#include <iostream.h>
-
#include <fstream.h>
-
#include <stdio.h>
-
-
-
-
struct Point3D
-
{
-
float x, y, z;
-
};
-
-
struct Triangle
-
{
-
char name[10];
-
Point3D point[3];
-
};
-
-
istream & operator >> (istream & in , Point3D & pt)
-
{
-
char c;
-
-
in >> c >> pt.x >> c >> pt.y >> c >> pt.z >> c;
-
-
return in;
-
}
-
-
istream & operator >> (istream & in, Triangle & tri)
-
{
-
in >> tri.name >> tri.point[0] >> tri.point[1] >> tri.point[2];
-
-
return in;
-
}
-
-
ostream & operator << (ostream & out , const Point3D & pt)
-
{
-
out << "(" << pt.x << "," << pt.y << "," << pt.z << ")";
-
-
return out;
-
}
-
-
ostream & operator << (ostream & out , const Triangle & tri)
-
{
-
out << tri.name << " " << tri.point[0] << " " << tri.point[1] << " " << tri.point[2];
-
-
return out;
-
}
-
-
float read ()
-
{
-
-
std::vector<Triangle> v;
-
-
ifstream in ("sample.txt", ios::in);
-
-
if (!in)
-
-
{
-
cout << "could not open" << endl;
-
return 1;
-
}
-
-
return 1;
-
}
-
-
void draw (const Triangle)
-
{
-
Triangle triangle;
-
-
while (in >> triangle)
-
{
-
v.push_back(triangle);
-
}
-
-
glBegin(GL_TRIANGLES);
-
-
for (int i = 0, i<v.size(), i++)
-
{
-
glVertex3f(v[i]);
-
}
-
-
glEnd;
-
-
glutSwapBuffers();
-
-
return 0;
-
-
}
-
-
int main (int argc, char **argv)
-
{
-
glutInit(&argc, argv);
-
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
-
glutInitWindowSize(640, 480);
-
glutInitWindowPosition(10,10);
-
glutCreateWindow("Triangle");
-
//init();
-
glMatrixMode(GL_PROJECTION);
-
glutDisplayFunc(draw);
-
//glutKeyboardFunc(keyboard);
-
-
glutMainLoop ();
-
-
return 0;
-
-
}
-
-
How do I pass the value from the read( ) into draw ( ) so I can retain the x,y,z value. So I can draw the point into triangle.
This is ther first time I combine both graphic programming and OO. So, explaination will be helpful.
8 4989
not sure what you wish to do? I assume some form of animation - have you seen the spinning triangle example?
http://www.lighthouse3d.com/opengl/glut/index.php?4
This is part of code where I want to read a Triangle table from textfile and plot it to draw a triangle. From there, i would like to texture the triangle and build a camera movement.
But now, i'm stuck at the point where a i couldnt pass the x,y,z valu for drawing.
This is part of code where I want to read a Triangle table from textfile and plot it to draw a triangle. From there, i would like to texture the triangle and build a camera movement.
But now, i'm stuck at the point where a i couldnt pass the x,y,z valu for drawing.
some initial ideas - not sure if it is what you required - but it compiles and starts to run -
-
// ** read trianges into vector v
-
std::vector<Triangle> v; // moved - make global for now????
-
-
float read ()
-
{
-
-
//std::vector<Triangle> v;
-
-
ifstream in ("sample.txt", ios::in);
-
-
if (!in)
-
-
{
-
cout << "could not open" << endl;
-
return 1;
-
}
-
Triangle triangle; // **** moved to here
-
-
while (in >> triangle)
-
{
-
v.push_back(triangle);
-
}
-
-
return 1;
-
}
-
-
void draw () // ** removed const Triangle)
-
{
-
-
glBegin(GL_TRIANGLES);
-
-
for (int i = 0; i<v.size(); i++) // ** replaced , with ;
-
{
-
glVertex3f(v[i].point[0].x, v[i].point[0].y, v[i].point[0].z); // pass first vertex
-
// <<< call glVertex3f() to pass other two vertexs here
-
}
-
-
glEnd();
-
-
glutSwapBuffers();
-
-
return;
-
-
}
-
-
int main (int argc, char **argv)
-
{
-
read(); // ** read triangles
-
glutInit(&argc, argv);
-
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
-
glutInitWindowSize(640, 480);
-
glutInitWindowPosition(10,10);
-
glutCreateWindow("Triangle");
-
//init();
-
glMatrixMode(GL_PROJECTION);
-
glutDisplayFunc(draw);
-
//glutKeyboardFunc(keyboard);
-
-
glutMainLoop ();
-
-
return 0;
-
-
}
-
read() reads the triangle data into vector v - call it from main() make v global
draw() can then read the vertex data from v
does that help?
Thanks. It does help a bit. I'll modify 2-3 things before posting the code back. I'll keep this updated.
I have finish created a fully fuctioniol OpenGL program with some camera movement. Now how do I texture the triangle? -
-
-
#include <windows.h>
-
#include <gl\gl.h>
-
#include <gl\glut.h>
-
#include <stdlib.h>
-
#include <math.h>
-
#include <vector>
-
#include <iostream.h>
-
#include <fstream.h>
-
#include <stdio.h>
-
-
float zoom = 15.0f;
-
float rotx = 0;
-
float roty = 0.001f;
-
float tx = 0;
-
float ty = 0;
-
int lastx=0;
-
int lasty=0;
-
unsigned char Buttons[3] = {0};
-
-
struct Point3D
-
{
-
float x, y, z;
-
};
-
-
struct Triangle
-
{
-
char name[10];
-
Point3D point[3];
-
};
-
-
istream & operator >> (istream & in , Point3D & pt)
-
{
-
char c;
-
-
in >> c >> pt.x >> c >> pt.y >> c >> pt.z >> c;
-
-
return in;
-
}
-
-
istream & operator >> (istream & in, Triangle & tri)
-
{
-
in >> tri.name >> tri.point[0] >> tri.point[1] >> tri.point[2];
-
-
return in;
-
}
-
-
ostream & operator << (ostream & out , const Point3D & pt)
-
{
-
out << "(" << pt.x << "," << pt.y << "," << pt.z << ")";
-
-
return out;
-
}
-
-
ostream & operator << (ostream & out , const Triangle & tri)
-
{
-
out << tri.name << " " << tri.point[0] << " " << tri.point[1] << " " << tri.point[2];
-
-
return out;
-
}
-
-
std::vector<Triangle> v;
-
-
float read ()
-
{
-
-
//std::vector<Triangle> v;
-
-
ifstream in ("sample.txt", ios::in);
-
-
if (!in)
-
-
{
-
cout << "could not open" << endl;
-
return 1;
-
}
-
-
Triangle triangle;
-
-
while (in >> triangle)
-
{
-
v.push_back(triangle);
-
}
-
-
return 1;
-
-
}
-
-
void init()
-
{
-
//glEnable(GL_DEPTH_TEST);
-
//glClearColor(0.0,0.0,0.0,0.0);
-
//glColor3f(1.0, 1.0, 1.0);
-
glLoadIdentity();
-
//glOrtho(-10,10,-10,10,-10,10);
-
-
}
-
-
-
void draw ()
-
{
-
-
glClear(GL_COLOR_BUFFER_BIT);
-
-
glLoadIdentity();
-
-
glTranslatef(0,0,-zoom);
-
glTranslatef(tx,ty,0);
-
glRotatef(rotx,1,0,0);
-
glRotatef(roty,0,1,0);
-
-
-
glBegin(GL_TRIANGLES); // I would like to texture this
-
// combination of multiple triangle
-
-
for ( int i = 0; i<v.size(); ++i)
-
{
-
glVertex3f(v[i].point[0].x, v[i].point[0].y, v[i].point[0].z);
-
glVertex3f(v[i].point[1].x, v[i].point[1].y, v[i].point[1].z);
-
glVertex3f(v[i].point[2].x, v[i].point[2].y, v[i].point[2].z);
-
-
}
-
-
glEnd();
-
-
glutSwapBuffers();
-
-
glBegin(GL_LINES);
-
for(int j=-10;j<=10;++j)
-
{
-
glVertex3f(j,0,-10);
-
glVertex3f(j,0,10);
-
-
glVertex3f(10,0,j);
-
glVertex3f(-10,0,j);
-
}
-
-
glEnd();
-
-
glutSwapBuffers();
-
}
-
-
void reshape(int w, int h)
-
{
-
-
if(w==0)
-
h = 1;
-
-
glViewport(0,0,w,h);
-
glMatrixMode(GL_PROJECTION);
-
glLoadIdentity();
-
gluPerspective(100,(float)w/h,1,100);
-
glMatrixMode(GL_MODELVIEW);
-
glLoadIdentity();
-
}
-
-
void Motion(int x,int y)
-
{
-
int diffx=x-lastx;
-
int diffy=y-lasty;
-
lastx=x;
-
lasty=y;
-
-
if( Buttons[0] && Buttons[1] )
-
{
-
zoom -= (float) 0.05f * diffx;
-
}
-
else
-
if( Buttons[0] )
-
{
-
rotx += (float) 0.5f * diffy;
-
roty += (float) 0.5f * diffx;
-
}
-
else
-
if( Buttons[1] )
-
{
-
tx += (float) 0.05f * diffx;
-
ty -= (float) 0.05f * diffy;
-
}
-
glutPostRedisplay();
-
}
-
-
void Mouse(int b,int s,int x,int y)
-
{
-
lastx=x;
-
lasty=y;
-
switch(b)
-
{
-
case GLUT_LEFT_BUTTON:
-
Buttons[0] = ((GLUT_DOWN==s)?1:0);
-
break;
-
case GLUT_MIDDLE_BUTTON:
-
Buttons[1] = ((GLUT_DOWN==s)?1:0);
-
break;
-
case GLUT_RIGHT_BUTTON:
-
Buttons[2] = ((GLUT_DOWN==s)?1:0);
-
break;
-
default:
-
break;
-
}
-
glutPostRedisplay();
-
}
-
-
int main (int argc, char **argv)
-
{
-
read();
-
glutInit(&argc, argv);
-
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
-
glutInitWindowSize(640, 480);
-
glutInitWindowPosition(10,10);
-
glutCreateWindow("Triangle");
-
-
init();
-
glMatrixMode(GL_PROJECTION);
-
-
glutDisplayFunc(draw);
-
glutReshapeFunc(reshape);
-
glutMouseFunc(Mouse);
-
glutMotionFunc(Motion);
-
-
glutMainLoop ();
-
-
return 0;
-
-
}
-
-
Any help will be highly appreciated.
have you seen this example in the codeproject?
http://www.codeproject.com/opengl/openglstruct.asp
have you seen this example in the codeproject?
http://www.codeproject.com/opengl/openglstruct.asp
That does not even come close to my requirement. But thanks. I just want to wrap a combination of Triangle.
Any help? I'm practically stuck here..
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rick Muller |
last post by:
I have a problem that I would like to get some advice on from other
Pythonistas. I currently manage a (soon to be) open source project for
displaying molecular graphics for a variety of different...
|
by: oracle411 |
last post by:
Hi I'm new to OpenGL, but have an OpenGL application written in CPP
that I would like to display on a web browser.
Was wondering how this could be done?
Thank you very much
|
by: john townsley |
last post by:
Hi
I want to do some OpenGl stuff with c++ on a winXP (home) machine.
I have Borland c++ 5, MVS c++ 5
What C++ do you recommend (any others?)and where do you get the OpenGL
stuff.
thanks
|
by: Shi Mu |
last post by:
is there any sample code to triangulation? many thanks!
|
by: Bad_Kid |
last post by:
which is better for what?
|
by: tobfon |
last post by:
I'm creating a scientific visualization application with rather high
demands on performance. I've created a nice rendering engine for it in
C++/OpenGL and a python interface to the rendering...
|
by: jg.campbell.ng |
last post by:
I'm beginning learning Python and OpenGL in Python.
Python fine. But difficulties with OpenGL; presumably with the
installation of OpenGL.
OS = Linux FC5.
Python program gl_test.py:
from...
|
by: Achim Domma |
last post by:
Hi,
I'm developing a GUI app in Python/C++ to visualize numerical results.
Currently I'm using Python 2.4 with wx and PyOpenGLContext, but there
are no windows binaries for Python 2.5 for quite...
|
by: McGruber |
last post by:
Hi, guys. Currently I am researching the optimised algorithms of building triangulations of 3D surfaces. And I faces the problem with visualization of the 3D triangulation. I tried to do it with...
|
by: Grant Edwards |
last post by:
Can anybody point me to a Delaunay triangulation module (for
Win32)? I'm currently using http://flub.stuffwillmade.org/delny/ under Linux, but I have
been unable to find a build for Windows. I...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |