calling derived using base* with base* as parameter

Pages: 12
@ Disch: What makes you think I still don't understand the problem? It's basically collision detection, the OP wants to avoid clipping. The "solution" that the majority of the world has excepted for the past twenty and some odd years is to off load these computations to function specific hardware that has it's own processor with a specialized instruction set, dedicated RAM and a slot tied to the north bridge on the PC. If there was a software solution to this then companies like Nvidia wouldn't exist.
Last edited on
The GPU doesn't compare the points against one and other and perform any actual collision detection but the concept of drawing thousands of individual points to the screen and keeping track of what should be visible, what should be hidden behind something else and when it should be visible again or what is off screen at that specific time has enough in common with what the OP is trying to do for me to make the comparison.

EDIT:
I honestly don't know whether or not you understood it since, in each of your last 3 posts, you made a point to mention how OP kept adding to/changing the problem.

Point taken, I do whine quite a bit.
Last edited on
I removed my previous post because it's inflammatory and unhelpful.

Computergeek... you are getting overly defensive (and my previous post that I deleted was hostile as a knee-jerk reaction to that. If you saw it, I apologize... I should not have posted it)


I'm genuinely interested in OP's problem because it's a problem I've struggled with in the past. I certainly welcome any input you have on it.

EDIT:

Doh... I see you did see my post and actually ninja replied to it.

Sorry again. =( We're still friends, right?
Last edited on
I honestly don't know why people get worked up over the arguing that goes on here, it's never bothered me. I don't take any of it personally and I didn't mean to get you angry either.

The post you made did touch on some points, it is possible to do this with software. But the similarities between what the OP wants to do and what the GPU already does are too many to ignore. If part of shape A is behind part of shape B then the GPU doesn't blit that part to the buffer. Also it determines whether or not to do that with fewer instructions then a normal CPU does. That is basically a collision detection and that's really what I was getting at with my comparison.

EDIT: I'll say that I am sorry as well.
Last edited on
whoa, calm down :)
@Disch:
For those of you who don't understand the problem:
...
this describes exactly what I'm talking about, sorry if I gave a too abstract problem description (and then additional details trying to help you understand), I just tried to make it easier for you.
Actually, the: maintain an id in the base class that describes what exact type the derived is, and then route using a switch would be a good solution. I think it would have the same performance as this virtual function type of thing.
To add I think one can't skip writing the backend functions for all permutations, so I guess an optimal solution would be to keep the number of types down to a minimum (say 4), like: sphere, aabb, obb, arbitrary mesh. This would give 24 functions to write. But for 5 one would have to write 120, so 4 will definitely be the limit.
currently I have sphere, aabb, plane, frustum, but not all classes support each type of test (is this on the right side of a plane, is A inside B (order matters here), does A intersect B (order doesn't matter)), I wrote so far 12 backend functions alltogether, plus the virtual functions that route to the correct one.
here's the full source of what I have:
http://pastebin.com/SEaZNPcF
Chapter 11 of 'Modern C++ Design: Generic Programming and Design Patterns Applied' by Alexandrescu
http://www.amazon.in/Modern-Design-Generic-Programming-Patterns/dp/0201704315
discusses three different solutions to this problem.
Indeed!

Something I wrote once upon a time, inspired by that book:
http://www.cplusplus.com/forum/general/33296/#msg179194
Last edited on
thank you both, I'm looking at them now.
the fast dispatcher perfectly suits my needs I think.
no dynamic casts, no rtti (if I remove that assert), and constant time.
thank you all for your contributions!
Last edited on
Disch wrote:
Also... how do you call addDispatch without a central list of classes?
You only need the two involved classes to be in scope?
Topic archived. No new replies allowed.
Pages: 12