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: -
/* ___________________________________________________________________
-
* Structures
-
*/
-
struct point
-
{
-
long signed int X, Y, Z; // Point at (X, Y, Z)
-
char Real; // A point is returned for the intersection of a plane and a line, and they may not intersect
-
};
-
-
struct line
-
{
-
short unsigned int P1, P2; // Line from P1 to P2
-
double A1, B1, C1, D1; // A line in three dimensions is defined as the intersection of two planes
-
double A2, B2, C2, D2; // A1*X + B1*Y + C1*Z = D1 and A2*X + B2*Y + C2*Z = D2
-
};
-
-
struct triangle
-
{
-
short unsigned int P1, P2, P3; // Verteces of the triangle
-
double A, B, C, D; // Formula of the plane: AX + BY + CZ + D
-
char Real; // A triangle is "real" unless the three points are colinear
-
};
-
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!): -
/* ___________________________________________________________________
-
* Find the point of intersection of a line and a plane
-
*/
-
point Intersect (triangle Triangle, line Line)
-
{
-
// Nessecary variables
-
point Result;
-
-
double EqMatrix[3][3];
-
double InvMatrix[3][3];
-
double ResMatrix[3];
-
double Det;
-
-
// Fill the equasion matrix
-
EqMatrix[0][0] = Triangle.A;
-
EqMatrix[0][1] = Triangle.B;
-
EqMatrix[0][2] = Triangle.C;
-
EqMatrix[1][0] = Line.A1;
-
EqMatrix[1][1] = Line.B1;
-
EqMatrix[1][2] = Line.C1;
-
EqMatrix[2][0] = Line.A2;
-
EqMatrix[2][1] = Line.B2;
-
EqMatrix[2][2] = Line.C2;
-
// Fill the result matrix
-
ResMatrix[0] = Triangle.D;
-
ResMatrix[1] = Line.D1;
-
ResMatrix[2] = Line.D2;
-
-
// Find the determinant
-
Det = EqMatrix[0][0] * (EqMatrix[1][1]*EqMatrix[2][2] - EqMatrix[1][2]*EqMatrix[2][1]);
-
Det -= EqMatrix[0][1] * (EqMatrix[1][0]*EqMatrix[2][2] - EqMatrix[1][2]*EqMatrix[2][0]);
-
Det += EqMatrix[0][2] * (EqMatrix[1][0]*EqMatrix[2][1] - EqMatrix[1][1]*EqMatrix[2][0]);
-
if (!Det) // If the determinant is zero, there is no intersection
-
{
-
Result.Real = 0;
-
return Result;
-
}
-
-
// Find the determinant
-
InvMatrix[0][0] = (EqMatrix[1][1]*EqMatrix[2][2] - EqMatrix[1][2]*EqMatrix[2][1]);
-
InvMatrix[1][0] = - (EqMatrix[1][0]*EqMatrix[2][2] - EqMatrix[1][2]*EqMatrix[2][0]);
-
InvMatrix[2][0] = (EqMatrix[1][0]*EqMatrix[2][1] - EqMatrix[1][1]*EqMatrix[2][0]);
-
InvMatrix[0][1] = - (EqMatrix[0][1]*EqMatrix[2][2] - EqMatrix[0][2]*EqMatrix[2][1]);
-
InvMatrix[1][1] = (EqMatrix[0][0]*EqMatrix[2][2] - EqMatrix[0][2]*EqMatrix[2][0]);
-
InvMatrix[2][1] = - (EqMatrix[0][0]*EqMatrix[2][1] - EqMatrix[0][1]*EqMatrix[2][0]);
-
InvMatrix[0][2] = (EqMatrix[0][1]*EqMatrix[1][2] - EqMatrix[0][2]*EqMatrix[1][1]);
-
InvMatrix[1][2] = - (EqMatrix[0][0]*EqMatrix[1][2] - EqMatrix[0][2]*EqMatrix[1][0]);
-
InvMatrix[2][2] = (EqMatrix[0][0]*EqMatrix[1][1] - EqMatrix[0][1]*EqMatrix[1][0]);
-
-
// Divide the adjugate by the determinant in order to find the inverse matrix
-
int i, j;
-
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
-
-
// Multiply the inverse by the result to get the resulting point
-
Result.X = (int)(InvMatrix[0][0]*ResMatrix[0] + InvMatrix[0][1]*ResMatrix[1] + InvMatrix[0][2]*ResMatrix[2]);
-
Result.Y = (int)(InvMatrix[1][0]*ResMatrix[0] + InvMatrix[1][1]*ResMatrix[1] + InvMatrix[1][2]*ResMatrix[2]);
-
Result.Z = (int)(InvMatrix[2][0]*ResMatrix[0] + InvMatrix[2][1]*ResMatrix[1] + InvMatrix[2][2]*ResMatrix[2]);
-
Result.Real = 1;
-
-
// Return a result
-
return Result;
-
}
-
5 1679 Savage 1,764
Recognized Expert Top Contributor
Can we see that call?
Savage
-
point P; // A point
-
triangle Tri; // A triangle
-
triangle T[3]; // An array of triangles
-
line L; // A line
-
-
P = Intersect (Tri, L); // This works
-
P = Intersect (T[0], L); // This doesn't
-
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().
Savage 1,764
Recognized Expert Top Contributor -
point P; // A point
-
triangle Tri; // A triangle
-
triangle T[3]; // An array of triangles
-
line L; // A line
-
-
P = Intersect (Tri, L); // This works
-
P = Intersect (T[0], L); // This doesn't
-
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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);
|
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...
|
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");
|
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?
| |
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...
|
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.
}
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |