Game Development Community

Item CastRay?

by Maddermadcat · in Torque Game Engine · 01/04/2008 (9:42 am) · 11 replies

This resource tells me to give ItemObjectType a CastRay function if I want the control to work with items. How would I do this?

#1
01/12/2008 (9:41 am)
Bump, really need some help here.
#2
01/27/2008 (2:39 pm)
...bump, once again.
#3
02/04/2008 (6:16 am)
I'm probably wrong, but wouldn't Item simply use the ShapeBase castRay function when a ray got cast at it? If not, here's a quick idea. It's probably not 100% right, so beware (and hope for more replies).
In item.h
class Item: public ShapeBase
{
	typedef ShapeBase Parent;
...
...
...
public:

	Point3F mStickyCollisionPos;
	Point3F mStickyCollisionNormal;

	[b]bool castRay(const Point3F &start, const Point3F &end, RayInfo* info); //<- Add this[/b]
...
...
...
}

In item.cc, right at the bottom
[b]bool Item::castRay(const Point3F &start, const Point3F &end, RayInfo* info)
{
	Parent::castRay(start,end,info);
}[/b]
That should basically just call the usual ShapeBase::castRay.
#4
05/03/2009 (11:07 am)
I know I am resurrecting an old thread again, but I just had a question about this. Item is derived from ShapeBase, and ShapeBase has a castRay function declared globally already. Why would you need to declare it again in item when item inherits ShapeBase?

I could be wrong, but I believe he is saying that if you add another Sim object type, then that object would need a castRay function. Someone tell me if I am wrong.
#5
05/03/2009 (12:09 pm)
That's a good question, and one I really can't answer, since I'm not trained in real C++ :P. The resource does specify Items, but maybe he was wrong about that. If I were using this resource, I'd give it a try without changing Item, and then see what difference my changes made.
#6
05/04/2009 (8:18 am)
> if you add another Sim object type, then that object would need a castRay function
true but only if it doesn't already have one by virtue of inheritence.
so if you're adding a new type derived from GameBase, yeah, you might need to provide castRay(), but if you're deriving from ShapeBase it should already be there. sounds like a small oversight in the resource. daniel's advice is quite good - try the easy thing first.
#7
05/04/2009 (3:30 pm)
Yeah that was kind of my point. Inheritance would take care of the solution described in the resource, but yes if you add another sim object type where the parent has no castRay() then you would definitely need to add one, and that is what it sounded like the resource was trying to say. I just didn't know if there was something about TGE/TGEA that would override the inheritance. I can't imagine anyone would break inheritance like that, so I figured maybe the resource was just unclear.

I am updating this resource for TGEA 1.7.1 because there were some differences, specifically with functions that now exist in GFX. I will also update it for 1.8.1 if I get time, and if there are differences between 1.7.1 and 1.8.1 that affect the resource.
#8
05/04/2009 (6:29 pm)
You probably want to verify that the way castRay is implemented in ShapeBase works/makes sense for Item, but I would expect it to work fine.
#9
05/04/2009 (9:44 pm)
I think the LOS-collision mesh is the just the key point.
Months ago, i had tried to use raycast to take an item, but failed.
When i track the source code I found that the stock item(e.g. health kit) doesn't have LOS, or Any collision data.
if you can model item yourself, remember add LOS on it, it'll be raycast supported.

Also, modify the raycast implementation of Item is a better choice.
#10
05/04/2009 (10:00 pm)
Good tip. Thanks!
#11
05/05/2009 (7:06 pm)
Hey, I updated the guiObjectSelectionHud.cpp to be in accordance with TGEA 1.7.1 if anyone wants it. I also moved everything out of the IF statement "if (obj->getShapeName()) " except the call to drawName(), as someone suggested earlier. It will now draw a box around anything you allow in the mask, and it will only attempt to draw the object's name if it has a name.

I might add health, shields, armor to this as well specifically for our project. I didn't know how to upload it here again, so here it is: starduel.digitalkingdomgames.com/files/tgea_files/guiObjectSelectionHud.cpp

Also, if you want to be able to adjust the distance at which you can see the selection boxes, change the following:


Within the class declaration, find this:

S32 mOffset;

... and add this below it:

S32 mDistance;

Within the constructor "GuiObjectSelectionHud::GuiObjectSelectionHud()":

... add this:

mDistance = 10.0f;


Within the function "void GuiObjectSelectionHud::initPersistFields()":

... add this:

addField( "Distance", TypeS32, Offset( mDistance, GuiObjectSelectionHud ) );

Within the function "void GuiObjectSelectionHud::onRender(Point2I offset, const RectI &updateRect)"

change this: endPos *= 10.0f;
... to this: endPos *= mDistance;

The original resource had you adding the GuiObjectSelectionHud GUI control at the bottom of your playGUI. And now you can specify the distance in the GUI control when you define it, or create an object of that gui control and assign the distance at any time like so:

new GameTSCtrl(PlayGui)
{

... the rest of this is left out for simplicity ...

// This is our new GuiObjectSelectionHud.  
   new GuiObjectSelectionHud(objSelectHud) {
         canSaveDynamicFields = "0";
         Profile = "GuiDefaultProfile";
         HorizSizing = "relative";
         VertSizing = "relative";
         Position = "0 0";
         Extent = "640 480";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         hovertime = "1000";
         TextColor = "1 1 1 1";
         TextOutlineColor = "1 1 1 1";
         TextFillColor = "0.3 0.3 0.3 0.75";
         OutlineColor = "1 1 1 1";
         Offset = "10";
      }; 
};

... now at any time you can set the distance like this:

objSelectHud.Distance = 30.0;
objSelectHud.Distance = 90.0;
etc.