Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 23rd, 2007, 09:59 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

Reply With Quote
  #2 (permalink)  
Old March 25th, 2007, 11:38 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please someone help me on this one!

Reply With Quote
  #3 (permalink)  
Old March 26th, 2007, 06:22 AM
Friend of Wrox
 
Join Date: Jan 2006
Location: Fort Wayne, Indiana, USA.
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Geo121
Default

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!
Reply With Quote
  #4 (permalink)  
Old March 27th, 2007, 01:02 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #5 (permalink)  
Old May 20th, 2007, 04:09 AM
Authorized User
 
Join Date: May 2007
Location: Seri Kembangan, Selangor, Malaysia.
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Peter_APIIT
Default

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.
Reply With Quote
  #6 (permalink)  
Old June 5th, 2007, 01:09 AM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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;

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to struct goscho C++ Programming 1 January 10th, 2008 07:23 AM
Constant pointer and pointer to a constant amit_mande@yahoo.com C++ Programming 2 June 5th, 2007 01:39 AM
Pointer reference perstam C++ Programming 5 April 29th, 2006 08:51 AM
NULL Pointer kumar_raj13 C++ Programming 0 July 15th, 2005 01:10 AM
pointer-to-function in C++ jacob C++ Programming 2 October 23rd, 2004 05:20 AM



All times are GMT -4. The time now is 06:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.