I Need To Create Function To Load A Mesh
I Need To Create Function To Load A Mesh
Hello,
i need help with creating my own function..
so it can be called later..
i am using : Microsoft Visual C++ 2005 Express Edition.
i need a function to load mesh.. without writing the addsceneNode ,addMesh ,etc commands again & again.
so..it will be like as : LoadObject(nodeName,"Model.X")
so i can use it like this.
LoadObject(player1,"player1.X")
LoadObject(enemy,"ghost.X")
LoadObject(player2,"opn.X")
PS : is it possible to do like this . can nodes be created at runtime ?
Thank You.
i need help with creating my own function..
so it can be called later..
i am using : Microsoft Visual C++ 2005 Express Edition.
i need a function to load mesh.. without writing the addsceneNode ,addMesh ,etc commands again & again.
so..it will be like as : LoadObject(nodeName,"Model.X")
so i can use it like this.
LoadObject(player1,"player1.X")
LoadObject(enemy,"ghost.X")
LoadObject(player2,"opn.X")
PS : is it possible to do like this . can nodes be created at runtime ?
Thank You.
Venkadesan V Tharshan
-
- Posts: 83
- Joined: Wed May 23, 2007 6:11 pm
Am I mistaken in saying that
Produces the same result as what you are trying to do and that you seem to be too used to a BASIC-style language?
If you were to use your 'own function' it would have to return the name of your node. Therefore why would 'nodeName' be a parameter in your function? Alternitvly you could have created the node names as global variables and then change there value within your function but this isnt a very clever thing to do.
I don't think I understand your logic here? Or have I misunderstood your question?
Code: Select all
ISceneNode* player1 = scenemgr->addAnimatedMeshSceneNode(
scenemgr->getMesh("player1.X"));
If you were to use your 'own function' it would have to return the name of your node. Therefore why would 'nodeName' be a parameter in your function? Alternitvly you could have created the node names as global variables and then change there value within your function but this isnt a very clever thing to do.
I don't think I understand your logic here? Or have I misunderstood your question?
Last edited by GuerillaSoftworks on Tue Jun 19, 2007 6:16 pm, edited 2 times in total.
Guerilla Softworks
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
thank you,
you are correct.
but.
ex: if i create the function / call it like this..
LoadObject(player1,"opn.X")
player1 : node name
opn.x (string) : file name to load..
if we create a function it will be easier than normal.
example :
if you want to assign the same materials for your meshes.
Or you can set the scale of mesh in function.
no need to write it like :
ISceneNode* player1 = scenemgr->addAnimatedMeshSceneNode(
scenemgr->getMesh("player1.X"));
player1->setScale(1,1,......
player1->setMaterialFlag.....
etc..
i want that function to do this thing automaticly.
Thank You.
you are correct.
but.
ex: if i create the function / call it like this..
LoadObject(player1,"opn.X")
player1 : node name
opn.x (string) : file name to load..
if we create a function it will be easier than normal.
example :
if you want to assign the same materials for your meshes.
Or you can set the scale of mesh in function.
no need to write it like :
ISceneNode* player1 = scenemgr->addAnimatedMeshSceneNode(
scenemgr->getMesh("player1.X"));
player1->setScale(1,1,......
player1->setMaterialFlag.....
etc..
i want that function to do this thing automaticly.
Thank You.
Venkadesan V Tharshan
-
- Posts: 83
- Joined: Wed May 23, 2007 6:11 pm
Surely though, the nodes 'player1' and 'player2' would have different settings. So a function to automate this would be useless.
But if you would want to do this then the following should work if ive understood you correctly. It's untested though so I cant say i will just work.
function declaration:
function use (e.g. in 'int main()' function):
If you want it to look more BASIC-like, i.e. without 'ISceneNode *player1 = ' before the function call, then declare the node in a separate statement or use global variables for your nodes. If you use global variables then use this function instead.
And this function call.
Note that you would have to declare all nodes you are going to use, globally before all this.
I'd would advise strongly against this method though.
Good luck.
But if you would want to do this then the following should work if ive understood you correctly. It's untested though so I cant say i will just work.
function declaration:
Code: Select all
ISceneNode LoadObject(wchar_t fileName)
{
ISceneNode* node = scenemgr->addAnimatedMeshSceneNode(
scenemgr->getMesh(fileName));
node->setScale(1,1,...... );
node->setMaterialFlag.....);
// ...other irrlicht functions follow as approiate...
return node;
};
Code: Select all
ISceneNode *player1 = LoadObject("player1.x");
Code: Select all
void LoadObject(nodeName, wchar_t fileName)
{
nodeName = scenemgr->addAnimatedMeshSceneNode(
scenemgr->getMesh(fileName));
nodeName->setScale(1,1,...... );
nodeName->setMaterialFlag.....);
// ...other irrlicht functions follow as approiate...
};
Code: Select all
LoadObject(player1,"player1.x");
I'd would advise strongly against this method though.
Good luck.
Last edited by GuerillaSoftworks on Tue Jun 19, 2007 7:06 pm, edited 1 time in total.
Guerilla Softworks
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
thank you for your reply & example..
its enough.
but i have a question..
ISceneNode *player1..
do we need to declare that node pointer in global.. ? before using the LoadObject() function ?
if yes.. its better to do it in normal way without functions..
cannot a node created from inside a function ?
void LoadObject(ISceneNode* nodeName, wchar_t fileName)
{
>>> nodeName = scenemgr->addAnimatedMeshSceneNode(
can we declare the Node pointer here ?
Thanks !!
its enough.
but i have a question..
ISceneNode *player1..
do we need to declare that node pointer in global.. ? before using the LoadObject() function ?
if yes.. its better to do it in normal way without functions..
cannot a node created from inside a function ?
void LoadObject(ISceneNode* nodeName, wchar_t fileName)
{
>>> nodeName = scenemgr->addAnimatedMeshSceneNode(
can we declare the Node pointer here ?
Thanks !!
Venkadesan V Tharshan
-
- Posts: 83
- Joined: Wed May 23, 2007 6:11 pm
Try changing
to
and make sure you have
at the beginning of your 'int main()' or further back if required.
Ill reply to your previous post soon.
Code: Select all
nodeName = smngr->addAnimatedMeshSceneNode(smngr->getMesh(fileName));
Code: Select all
nodeName = scenemgr->addAnimatedMeshSceneNode(scenemgr->getMesh(fileName));
Code: Select all
ISceneManager* scenemgr = device->getSceneManager();
Ill reply to your previous post soon.
Guerilla Softworks
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
-
- Posts: 83
- Joined: Wed May 23, 2007 6:11 pm
A node can be created from within a function but it is does not exist outside that function that's a pointer to the node is returned from the function.
However, if you must do it the global way, then I think you could declare a global from within a function like so:
but im not sure about this as ive never tryed to do it.
Also I have changed some code i posted. Check the 'void LoadObject()' declaration.
However, if you must do it the global way, then I think you could declare a global from within a function like so:
Code: Select all
static ISceneNode node;
Also I have changed some code i posted. Check the 'void LoadObject()' declaration.
Last edited by GuerillaSoftworks on Wed Jun 20, 2007 1:06 am, edited 1 time in total.
Guerilla Softworks
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
-
- Posts: 83
- Joined: Wed May 23, 2007 6:11 pm
No problems.
It would be interesting to see just how your using this code. So if possible is there any chance you could post your project when complete. I'm interested in seeing what would require this somewhat uncommon method of doing things. Thanks.
It would be interesting to see just how your using this code. So if possible is there any chance you could post your project when complete. I'm interested in seeing what would require this somewhat uncommon method of doing things. Thanks.
Guerilla Softworks
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
yes.
Yes.
Sure !
i will post that soon..
my idea is..
read a text file & create objects from that..
so it can be used as simple level data for games ,etc
Thank You For Your Support
Sure !
i will post that soon..
my idea is..
read a text file & create objects from that..
so it can be used as simple level data for games ,etc
Thank You For Your Support
Venkadesan V Tharshan
Sounds a heck of a lot like what is done with smgr->loadScene() and smgr->saveScene(). In case you didn't know, you can generate XML files that describe an entire scene using irrEdit, and you can load them with a single line of code.my idea is.. read a text file & create objects from that.. so it can be used as simple level data for games ,etc
Travis
-
- Posts: 83
- Joined: Wed May 23, 2007 6:11 pm
@ vitek... yeh this is something I was wondering about also. There must be some reason why hes doing things this way. Though I cant see what Im sure itll become apparent when hes done.
Guerilla Softworks
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com
New Guerilla Softworks website under construction - http://guerillasoftworks.awardspace.com