473,785 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't call my function using an array elemant as a parametre

5 New Member
I wrote a function to find the point of intersection of a line and a plane in three-space. This function works fine and returns the correct result.

However, when I call it using an element from an array of triangles for the first param I get a compile error:
error: no match for call to ‘(point) (triangle&, line&)’

Any ideas what may be causing this?

Compiled (or not) with G++:
g++ -Wall "MovesShootDete ct.cpp" -lGL -lGLU `sdl-config --cflags --libs` -lSDL_image -o MovesShootDetec t
under Linux (Ubuntu 7.10) on my PC.



These structures are all used by the function:
Expand|Select|Wrap|Line Numbers
  1. /*  ___________________________________________________________________
  2.  *  Structures
  3.  */
  4. struct point
  5. {
  6.     long signed int X, Y, Z;  // Point at (X, Y, Z)
  7.     char Real;  // A point is returned for the intersection of a plane and a line, and they may not intersect
  8. };
  9.  
  10. struct line
  11. {
  12.     short unsigned int P1, P2;  //  Line from P1 to P2
  13.     double A1, B1, C1, D1;  // A line in three dimensions is defined as the intersection of two planes
  14.     double A2, B2, C2, D2;  // A1*X + B1*Y + C1*Z = D1 and A2*X + B2*Y + C2*Z = D2
  15. };
  16.  
  17. struct triangle
  18. {
  19.     short unsigned int P1, P2, P3;  // Verteces of the triangle
  20.     double A, B, C, D;  // Formula of the plane: AX + BY + CZ + D
  21.     char Real;  // A triangle is "real" unless the three points are colinear
  22. };
  23.  
This is the function that finds the intersection. Nobody has to check my math, I already have and I know it works (and it took me an hour!):
Expand|Select|Wrap|Line Numbers
  1. /*  ___________________________________________________________________
  2.  *  Find the point of intersection of a line and a plane
  3.  */
  4. point Intersect (triangle Triangle, line Line)
  5. {
  6.     //  Nessecary variables
  7.     point Result;
  8.  
  9.     double EqMatrix[3][3];
  10.     double InvMatrix[3][3];
  11.     double ResMatrix[3];
  12.     double Det;
  13.  
  14.     //  Fill the equasion matrix
  15.     EqMatrix[0][0] = Triangle.A;
  16.     EqMatrix[0][1] = Triangle.B;
  17.     EqMatrix[0][2] = Triangle.C;
  18.     EqMatrix[1][0] = Line.A1;
  19.     EqMatrix[1][1] = Line.B1;
  20.     EqMatrix[1][2] = Line.C1;
  21.     EqMatrix[2][0] = Line.A2;
  22.     EqMatrix[2][1] = Line.B2;
  23.     EqMatrix[2][2] = Line.C2;
  24.     //  Fill the result matrix
  25.     ResMatrix[0] = Triangle.D;
  26.     ResMatrix[1] = Line.D1;
  27.     ResMatrix[2] = Line.D2;
  28.  
  29.     //  Find the determinant
  30.     Det = EqMatrix[0][0] * (EqMatrix[1][1]*EqMatrix[2][2] - EqMatrix[1][2]*EqMatrix[2][1]);
  31.     Det -= EqMatrix[0][1] * (EqMatrix[1][0]*EqMatrix[2][2] - EqMatrix[1][2]*EqMatrix[2][0]);
  32.     Det += EqMatrix[0][2] * (EqMatrix[1][0]*EqMatrix[2][1] - EqMatrix[1][1]*EqMatrix[2][0]);
  33.     if (!Det)  // If the determinant is zero, there is no intersection
  34.     {
  35.         Result.Real = 0;
  36.         return Result;
  37.     }
  38.  
  39.     //  Find the determinant
  40.     InvMatrix[0][0] = (EqMatrix[1][1]*EqMatrix[2][2] - EqMatrix[1][2]*EqMatrix[2][1]);
  41.     InvMatrix[1][0] = - (EqMatrix[1][0]*EqMatrix[2][2] - EqMatrix[1][2]*EqMatrix[2][0]);
  42.     InvMatrix[2][0] = (EqMatrix[1][0]*EqMatrix[2][1] - EqMatrix[1][1]*EqMatrix[2][0]);
  43.     InvMatrix[0][1] = - (EqMatrix[0][1]*EqMatrix[2][2] - EqMatrix[0][2]*EqMatrix[2][1]);
  44.     InvMatrix[1][1] = (EqMatrix[0][0]*EqMatrix[2][2] - EqMatrix[0][2]*EqMatrix[2][0]);
  45.     InvMatrix[2][1] = - (EqMatrix[0][0]*EqMatrix[2][1] - EqMatrix[0][1]*EqMatrix[2][0]);
  46.     InvMatrix[0][2] = (EqMatrix[0][1]*EqMatrix[1][2] - EqMatrix[0][2]*EqMatrix[1][1]);
  47.     InvMatrix[1][2] = - (EqMatrix[0][0]*EqMatrix[1][2] - EqMatrix[0][2]*EqMatrix[1][0]);
  48.     InvMatrix[2][2] = (EqMatrix[0][0]*EqMatrix[1][1] - EqMatrix[0][1]*EqMatrix[1][0]);
  49.  
  50.     //  Divide the adjugate by the determinant in order to find the inverse matrix
  51.     int i, j;
  52.     for (i=0;  i<3;  i++)  for (j=0;  j<3;  j++)  InvMatrix[i][j] /= Det;  // I didn't think you could do that xD
  53.  
  54.     //  Multiply the inverse by the result to get the resulting point
  55.     Result.X = (int)(InvMatrix[0][0]*ResMatrix[0] + InvMatrix[0][1]*ResMatrix[1] + InvMatrix[0][2]*ResMatrix[2]);
  56.     Result.Y = (int)(InvMatrix[1][0]*ResMatrix[0] + InvMatrix[1][1]*ResMatrix[1] + InvMatrix[1][2]*ResMatrix[2]);
  57.     Result.Z = (int)(InvMatrix[2][0]*ResMatrix[0] + InvMatrix[2][1]*ResMatrix[1] + InvMatrix[2][2]*ResMatrix[2]);
  58.     Result.Real = 1;
  59.  
  60.     //  Return a result
  61.     return Result;
  62. }
  63.  
Jan 5 '08 #1
5 1679
Savage
1,764 Recognized Expert Top Contributor
Can we see that call?

Savage
Jan 5 '08 #2
Envergure
5 New Member
Expand|Select|Wrap|Line Numbers
  1. point P;  // A point
  2. triangle Tri;  // A triangle
  3. triangle T[3];  // An array of triangles
  4. line L;  // A line
  5.  
  6. P = Intersect (Tri, L);  // This works
  7. P = Intersect (T[0], L);  // This doesn't
  8.  
Jan 5 '08 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code compiles and links OK with Visual Studio.NET 2005.

I had your code in this order:

1) the structs
2) the intersect function
3) main().
Jan 5 '08 #4
Savage
1,764 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. point P;  // A point
  2. triangle Tri;  // A triangle
  3. triangle T[3];  // An array of triangles
  4. line L;  // A line
  5.  
  6. P = Intersect (Tri, L);  // This works
  7. P = Intersect (T[0], L);  // This doesn't
  8.  
This should work..have you tried writing same function,but with references as the parameters?
In worst case,copy data from array to a new variable and then call the function..
(maybe the worst thing would be rather changing compiler and/or OS)

Savage
Jan 5 '08 #5
Envergure
5 New Member
to weaknessforcats :
Yeah, I just did the same and it worked... Maybe it's just a weird artifact.


I should maybe have said earlier this is just part of a much larger program (550 lines so far, it's eventually going to be a shooter engine).

In the past I've found it sometimes works just to erase part of a program and rewrite it, so I'll try that and post back.


In the meantime, what does "error: no match for call to ‘(point) (triangle&, line&)’" actually mean? I've never seen this error before. Also, ‘(point) (triangle&, line&)’ looks more like a typecast than a function.
Jan 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2837
by: fdsl ysnh | last post by:
--- python-list-request@python.orgдµÀ: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body > 'help' to
3
5233
by: Philippe Mesmeur | last post by:
J'ai eu une longue discussion hier au sujet des parametres de fonction const. La personne etait pour mettre "const" devant TOUS les parametres ne devant pas etre modifies. A mon avis, il faut le faire que SI le parametre est un pointeur ou une référence. int fct1(const int* i);
8
3688
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was static; if the input file contained more than entries, tough. This time I want to do it right - use a dynamic array that increases in size with each word read from the file. A few test programs that make use of **List and realloc( List, blah...
8
1961
by: Berhack | last post by:
I am not too familiar with C# interop so please help me out. I need to call the following C function (in a DLL): // this creates an array of strings // LPTSTR is just char * void C_Func(LPTSTR **pszStrings) { (*pszStrings) = reinterpret_cast<LPTSTR *>(malloc(2 * sizeof(LPTSTR))); (*pszStrings) = _T("A test");
9
3349
by: WRH | last post by:
Hello I am new to asp but I made some Jscript functions which work fine. The functions contain some strings used as a registration key for some apps. It is important that these strings not be visible to a client using a browser. My question is...can a knowledgeable browser user view Jscript source code in an asp file?
6
4902
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
5
1898
by: Sunil Varma | last post by:
Hi, I've to write a function similar to this. int process(const vector<int>& vct,int key) { // Here I've to find the position of key in the vector and do some processing. }
1
2569
SamKL
by: SamKL | last post by:
Hey, I'm no expert on PHP, and I have somewhat of an understanding of object oriented code. Anyway, getting right to the problem. I'm using PHP4, so base it off of that. Basically I have 2 classes in this code. Link_Structure, which is composed of Node classes (it's a linked list data structure), and of course the Node class. In class Node: function setActive( $i ) { $this->_data = $i; } This function is designed to set the array...
4
4587
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
0
9645
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9952
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.