A Couple Inquiries

Expanding and utilizing the engine via C++.
4 posts Page 1 of 1
TorqueFan
Posts: 130
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Sat Jun 20, 2015 8:46 pm
I've been messing with a custom class in C++ for T3D and ran into a couple snags that, hopefully, might be cleared up by someone with a bit more knowledge around the engine and the use of its source.

1 - The first thing I'm having problems with is when the Player performs a rayCast onto the object he's stepping on. What I'd like to do is 'grab ahold' of the object the player has stepped on and then call to functions within that object's class. For example:

Code: Select all

if (&Player::steppedOnMyObject) { Con::printf("Stepped on my Object"); }
Using the above I can have the console echo come through, no problems there. But what if I wanted to do this:

Code: Select all

if (&Player::steppedOnMyObject) { MyObject* myObject = getMyObject(); myObject.doStuff(); }
How could this be accomplished? The rayInfo from the sceneContainer's rayCast() is only returning a sceneObject in the rInfo.object data field, so I can't just use something like:

Code: Select all

SceneObject* myObject = getMyObject();
I guess what I'm looking for is how would I write the 'getMyObject()' function from within the Player class to retrieve the other class object?

2- The next issue I'm trying to figure out is how players present in the scene are retrieved or indexed. Consider this, in 'myObject.h':

Code: Select all

Player* mActivePlayer; VectorPtr<Player*> mPlayers;
How could that list of players be filled? Or is there some already existing way to retrieve players from the scene?

Thanks to anyone who can enlighten me a bit.
TorqueFan
Posts: 130
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Sat Jun 20, 2015 10:43 pm
Well I believe I found what I need for #2. Tracked down the SceneContainer and SimpleQueryList which I think will meet my needs fine for indexing objects.

For #1 I've implemented a custom callback, so I can call the functions to the other class via script...which is kinda what I was trying to avoid but oh well.
buckmaster
DEVGRU
Posts: 321
Joined: Thu Feb 05, 2015 1:02 am
by buckmaster » Mon Jun 22, 2015 2:00 am

Code: Select all

if (&Player::steppedOnMyObject)
What's this supposed to do? Looks like you're getting a reference to a... static property? Anyway where are you doing the raycast? Essentially you should keep the result of the raycast (which has the object the cast hit), then you can check its type mask to see what sort of object it is (and then do a static_cast if you're sure you know what class it has), or do some dynamic_casts and see if they work.
TorqueFan
Posts: 130
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Mon Jun 22, 2015 6:03 am

Code: Select all

if (&Player::steppedOnMyObject)
What's this supposed to do? Looks like you're getting a reference to a... static property? Anyway where are you doing the raycast? Essentially you should keep the result of the raycast (which has the object the cast hit), then you can check its type mask to see what sort of object it is (and then do a static_cast if you're sure you know what class it has), or do some dynamic_casts and see if they work.
Dude, that's just me trippin' all around trying to figure out the way some of these things work in Torque source. There I had added a bool to the player class (before I discovered the details I'm about to describe).

I finally did find a much more 'solid' solution, after poking around and digging to find out exactly what pieces I was missing. I ended up extending the collision struct with some extra fields I needed to pass the data from my custom object. In my object's castRay I added the pointers to the new fields as part of the rInfo result. Then, ultimately, and without needing a callback I just ended up plugging this in:

Code: Select all

// Stepped on MyObject if (rInfo.object->getTypeMask() & MyObjectType) myCustomFunction(rInfo.myNewField);


Oh, I also had to setup a new TypeMask for the custom object. Works like a charm!
4 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests