|
-
October 13th, 2003, 05:01 AM
#1
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.
-
October 13th, 2003, 05:42 AM
#2
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]);
?
-
October 13th, 2003, 06:21 AM
#3
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.
-
October 13th, 2003, 06:45 AM
#4
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)
-
October 13th, 2003, 06:56 AM
#5
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)
-
October 13th, 2003, 07:45 AM
#6
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
-
October 13th, 2003, 11:53 PM
#7
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)
-
October 14th, 2003, 03:05 AM
#8
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.
-
October 17th, 2003, 03:40 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|