Game Development Community

Adding scene objects via C++

by Gerald Fishel · in Torque Game Engine · 05/17/2004 (7:31 am) · 5 replies

Hi all,

There is one (hopefully) simple thing that is eluding me here.

When I load one of my own object types, I would like to be able to add other objects to the scene. For instance, if the object has lights associated with it, I would like to add an fxLight object to the scene for each light, instead of implementing the code for the lights myself within the object.

How would I go about doing this in C++?

I tried creating a new fxLightData object, setting the relevent fields that I would otherwise set in a script file, then creating an fxLight object, using setDataBlock to set the datablock, and then using gClientSceneGraph->addObjectToScene to add the fxLight to the scene, adding the position of the object to the position of the light relative to the object.

This doesn't seem to have any effect though. I don't get any errors, but I don't get the fxLight either.

Any tips would be great.

Thanks

#1
05/17/2004 (8:42 am)
This should get you started (not sure about fxLight thou):
tork.beffy.de/tge_snipits/view_snipits_in_category.php?fk_tge_snipit_category_id...
#2
05/17/2004 (2:12 pm)
Thanks Stefan, that was exactly what I needed to see ;) All is working well now.

Peace
#3
12/02/2008 (7:22 pm)
I acctually have somthing very similar i am trying to do and the link seems to be dead does anyone know how to do this or know what happened to the article on that page i would like to read it if i could.
#4
12/02/2008 (7:37 pm)
Wayback machine is a savour:

Cached webpage (URL not used as link text since its so long)

It might take a few minutes for the webpage to load though. :)


Here I'll just repost the content here just in case wayback machine suddenly dies:

GG Forum discussion on this particular code snippet post here,

Remember to add the include file "item.h"

Also remember to remove all the Items you created before shutting the engine down or you will get an error.



Snipit Code:
#include "item.h"

// ...

Item *pItem = new Item;
ItemData *pHealthKit = dynamic_cast(Sim::findObject("HealthKit"));
pItem->onNewDataBlock( pHealthKit );
pItem->setPosition(Point3F(300,300,300));
if (pItem->registerObject())
{
	delete pItem;
	pItem = 0;
}

// Here is code to remove a Item that was created from the function above.

if( pItem )
{
	Con::printf("Deleting object %s", pItem->getShapeName());
	pItem->deleteObject();
}
#5
12/03/2008 (4:25 pm)
Thanks alot. Looks just like what i have been looking for. I am kinda surprised i would ever find a need to create an object outside of script. But for realitivly complex objects that have inter object dependencies it seems to be a requirement.

Thier seem to be quite a few interesting pieces of code on that site.

I am going to assume the process for creating other object types in C++ is pretty similar.
And for an object without a datablock i am hopeing i can just omit the part about the datablock.