Jump to content

A Couple Inquiries


TorqueFan

Recommended Posts

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:

			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:

			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:

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':

	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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

 

			// 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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...