 |
| C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

March 23rd, 2007, 09:59 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Pointer
I got a problem using pointer.
I got two table in two different file.
First one:
x y z
7 6 5
1 3 4
2 1 4
the other one:
node1 node2 node3
1 2 3
2 3 1
3 1 2
My problem is, how do i point table two to take the value of table one.
let say table two says node1 = 1, node2 = 2 and node3 = 3
so the out put will be:
(7,6,5)(1,3,4)(2,1,4)
it means that the number in table two will refer to line in table one.
Thanx.
Note: I have posted in many forum, but still no solution. I hope I can get some help here.
|

March 25th, 2007, 11:38 PM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Please someone help me on this one!
|

March 26th, 2007, 06:22 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
|
|
As far as I can tell the function you are trying to get your program to perform doesn't require pointers and the output description is a little hazy, I think I understand what you are trying to do but it would be better if you used a better description and just a hint you will never get any help by asking how to do it you must post the code you have tryed and ask what you are doing wrong
~ Geo
~ Don't take life too seriously, you'll never get out alive!
|

March 27th, 2007, 01:02 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok. I did this.
Code:
#include <iostream.h>
#include <vector>
#include <fstream.h>
using namespace std;
struct Point
{
double x,y,z;
};
struct Tin
{
int node1, node2, node3;
};
istream & operator >> (istream & in, Point & pt)
{
in >> pt.x >> pt.y >> pt.z;
return in;
}
ostream & operator << (ostream & out , const Point & pt)
{
out << "(" << pt.x <<","<< pt.y << "," << pt.z << ")" ;
return out;
}
Point *ReadVertexFile (char *filename, int &vertexArraySize)
{
ifstream in (filename, ios::in);
if (!in.is_open())
{
return NULL;
}
in >> vertexArraySize;
Point *vertexArray = new Point[vertexArraySize];
if (vertexArray == NULL)
{
return NULL;
}
int index = 0;
while (in >> vertexArray[index])
{
index ++;
}
return vertexArray;
}
Tin *ReadTinFile(char *filename, int &TinArraySize)
{
ifstream in (filename, ios::in);
if (!in.is_open())
{
return NULL;
}
in >> TinArraySize;
Tin *TinArray = new Tin[TinArraySize];
if (TinArray == NULL)
{
return NULL;
}
int index = 0;
while (in >> TinArray[index].node1 >> TinArray[index].node2 >> TinArray[index].node3)
{
index ++;
}
return TinArray;
}
int main()
{
int TinArraySize;
int VertexArraySize;
Point *vertexArray = ReadVertexFile("lochass.txt", VertexArraySize);
Tin *TinArray = ReadTinFile("lochas.txt", TinArraySize);
for ( int i = 0; i < TinArraySize; i++)
{
Point vertexA = vertexArray[ TinArray[i].node1 ];
Point vertexB = vertexArray[ TinArray[i].node2 ];
Point vertexC = vertexArray[ TinArray[i].node3 ];
cout << vertexA << "," << vertexB << "," << vertexC << endl;
}
return 0;
}
However, one problem. When i wanted to plot the vertex line, it became a problem. OpenGL needs 3 parameter while i have only one for each three coordinates which is vertexA, vertexB and vertexC.
So how could I break those so i can plot it with something like this:
Code:
glVertex3f(node1.x[1],node1.y[1],node1.z[1])
glVertex3f(node2.x[1],node2.y[1],node2.z[1])
glVertex3f(node3.x[1],node3.y[1],node3.z[1])
Thanks.
|

May 20th, 2007, 04:09 AM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I don't understand this program. why you never specified the function prototype and
don't add .h behind the header file instead of this <iostream>
The <iostream.h> and <iostream.h is totally different
because the <iostream> is packed in a std namespace.
The newer compiler will complaint this mistake.
Please coding in stadard C++ in order to enhance portable.
I hope this help.
Linux is the best OS in the world.
|

June 5th, 2007, 01:09 AM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
in opengl the is a corresponding fucntion glVertex3fv which takes a
pointer to an array where u have stored ur x,y,z co-ordinates.
try using it here's an example
int vert[] = {1,1,1};
glVertex3iv(vert);
in case of float just replace i by f in glVertex*v;
|
|
 |