CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2002
    Location
    UK
    Posts
    200

    Unhappy A strange program

    hello guys:

    When I do my program, I found a very strange code. Hopefully, you can help me to find out what's wrong with it.The codes are as follows:
    GLdouble *SWinCoorX;
    GLdouble *SWinCoorY;
    GLdouble *SWinCoorZ;
    //In the constructor, I declared these:
    SWinCoorX = new double [10000];
    SWinCoorY = new double [10000];
    SWinCoorZ = new double [10000];
    // In the distructor, I declared these:
    delete [] SWinCoorX;
    delete [] SWinCoorY;
    delete [] SWinCoorZ;
    //In the ...View.cpp, I wrote the codes as :
    void CAMUNURBSView::OnLButtonDown(UINT nFlags, CPoint point)
    {
    int i;
    double TempWinCoorX[10000],TempWinCoorY[10000],TempWinCoorZ[10000];
    ....
    ....
    for(i = 0;i < pDoc->S3DSModel->p3DS_Object[0]->a_NumVts;i++)
    {
    SObjectCoorX[i] = pDoc->S3DSModel->p3DS_Object[0]->a_dVt[i].x;
    SObjectCoorY[i] = pDoc->S3DSModel->p3DS_Object[0]->a_dVt[i].y;
    SObjectCoorZ[i] = pDoc->S3DSModel->p3DS_Object[0]->a_dVt[i].z;
    ::glGetDoublev(GL_MODELVIEW_MATRIX, SmodelMatrix);
    ::glGetDoublev(GL_PROJECTION_MATRIX, SprojMatrix);
    ::glGetIntegerv(GL_VIEWPORT, SpVport->Port);
    gluProject(SObjectCoorX[i], SObjectCoorY[i], SObjectCoorZ[i], SmodelMatrix, SprojMatrix, SpVport->Port,
    SWinCoorX, SWinCoorY, SWinCoorZ);
    TempWinCoorX[i] = SWinCoorX[i];
    TempWinCoorY[i] = SWinCoorY[i];
    TempWinCoorZ[i] = SWinCoorZ[i];
    ....}
    ....
    }
    Now you can see, in the function "gluProject()", the last three parameters are "SWinCoorX,SWinCoorY, SWinCoorZ". I defined them as pointers. However, when I used debug to check their values, I found that their addresses are not changed, and the values wich they point to are changed. So can you find what is the problem? I really confuse now. Thank you very much.

  2. #2
    Join Date
    Nov 1999
    Location
    Copenhagen, Denmark
    Posts
    265
    I'm not sure what you're trying to accomplish, but you declare

    Code:
    SWinCoorX = new double [10000];
    and then continually use this pointer a a an argument to the gluProject method. Altough it happens inside a loop you don't actually change the value of SWinCoorX. Maybe what you meant was:

    Code:
    gluProject(SObjectCoorX[i], SObjectCoorY[i], SObjectCoorZ[i], SmodelMatrix, SprojMatrix, SpVport->Port,
    SWinCoorX[i], SWinCoorY[i], SWinCoorZ[i]);
    ?
    Best regards,
    S. Bro

    "I would be happy to deal with my problems one at the time if they would only line up!"
    -Paul Cilwa, "Borland C++ Insider".

    Other useful fora some of which I ruthlessly clipboarded from other peoples footers.

    MSDN: http://search.microsoft.com/us/dev/default.asp
    WIN 32 Assembler: http://board.win32asmcommunity.net/
    RDBMS: http://www.dbforums.com
    Robert's Perl Tutorial: http://www.sthomas.net/roberts-perl-tutorial.htm
    Merriam-Webster Online: http://www.m-w.com/home.htm
    Writing Unmaintainable Code: http://mindprod.com/unmain.html

  3. #3
    Join Date
    Oct 2002
    Location
    UK
    Posts
    200

    Smile Reply

    Yes, now you know what I means. But The function "gulProject" requires the last three parameters are pointers. That is why I wrote like
    gluProject(SObjectCoorX[i], SObjectCoorY[i], SObjectCoorZ[i], SmodelMatrix, SprojMatrix, SpVport->Port,
    SWinCoorX, SWinCoorY, SWinCoorZ),
    If I wrote the last three parameters as SWinCoorX[i],SWinCoorY[i],SWinCoorZ[i], it won't go through when it is built.

  4. #4
    Join Date
    Jan 2003
    Location
    Punjab, India
    Posts
    103
    Its indeed a very strange code. It seems that there is a coding error as told by sbrothy.

    Can you please explain some thing more about what do you want to do
    Santosh Thankachan
    "Fear of God is the Beginning of Wisdom" (Proverbs 1:7)

  5. #5
    Join Date
    Jan 2003
    Location
    Punjab, India
    Posts
    103
    If I am not wrong the result of transformation is stored in SWinCoorX, SWinCoorY, SWinCoorZ. So it should not surprise you when the values which these pointers have are changed during execution.

    But still I am confused regarding the usage of function. If any function requires some pointer values then that does not mean that we should make an array and then pass it as such in the function. May be I am wrong but I think you should pass the particular SWinCoorX, SWinCoorY, SWinCoorZ as pointed by sbrothy. To bypass the compilation errors you can pass it as alias(I wonder whether that will get you through your compilation properly )
    Last edited by santoshthankach; October 13th, 2003 at 07:03 AM.
    Santosh Thankachan
    "Fear of God is the Beginning of Wisdom" (Proverbs 1:7)

  6. #6
    Join Date
    Nov 1999
    Location
    Copenhagen, Denmark
    Posts
    265
    It seems the gluProject method maps object coordinates to window coordinates. It's C declaration is:


    Code:
    GLint gluProject  ( GLdouble objX , GLdouble objY , GLdouble objZ , const GLdouble *model , const GLdouble *proj , const GLint *view , GLdouble* winX , GLdouble* winY , GLdouble* winZ );
    and winX, winY and winZ are indeed output variables according to:

    Parameters
    objX, objY, objZ
    Specify the object coordinates.
    model
    Specifies the current modelview matrix (as from a glGetDoublev call).
    proj
    Specifies the current projection matrix (as from a glGetDoublev call).
    view
    Specifies the current viewport (as from a glGetIntegerv call).
    winX, winY, winZ
    Return the computed window coordinates.


    Question is: Does it transform one coordinate at a time? If this is the case you should do:

    Code:
    GLdouble SWinCoorX; 
    GLdouble SWinCoorY;
    GLdouble SWinCoorZ

    and use them as:

    Code:
    ...
    gluProject(SObjectCoorX[i], SObjectCoorY[i], SObjectCoorZ[i], SmodelMatrix, SprojMatrix, SpVport->Port,
    &SWinCoorX, &SWinCoorY, &SWinCoorZ);

    See this example:












    gluProject sample
    Best regards,
    S. Bro

    "I would be happy to deal with my problems one at the time if they would only line up!"
    -Paul Cilwa, "Borland C++ Insider".

    Other useful fora some of which I ruthlessly clipboarded from other peoples footers.

    MSDN: http://search.microsoft.com/us/dev/default.asp
    WIN 32 Assembler: http://board.win32asmcommunity.net/
    RDBMS: http://www.dbforums.com
    Robert's Perl Tutorial: http://www.sthomas.net/roberts-perl-tutorial.htm
    Merriam-Webster Online: http://www.m-w.com/home.htm
    Writing Unmaintainable Code: http://mindprod.com/unmain.html

  7. #7
    Join Date
    Jan 2003
    Location
    Punjab, India
    Posts
    103
    Yes I agree with sbrothy and precisely this is what I also meant by passing the arguments as alias if that is what the function requires.
    I would appreciate Xiaolei Shang to let us know if the things workout with suggestions given by sbrothy.
    Santosh Thankachan
    "Fear of God is the Beginning of Wisdom" (Proverbs 1:7)

  8. #8
    Join Date
    Oct 2002
    Location
    UK
    Posts
    200

    Wink reply!!

    Even though I haven't try this way, I think it should be work. I am very grateful to you. I will feedback the result after I do it. Thank you very much.

  9. #9
    Join Date
    Oct 2002
    Location
    UK
    Posts
    200

    Thumbs up

    It works now!! Thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured