Hey guys! Sorry if this has been asked in the forums before, cos I did a search and nothing that came up could help me.
I was wondering how do I make models disappear and reappear on certain conditions. For example:
When the player reaches a certain point on the map, a 3D arrow appears in front of the player.
What I had in mind is:
- initially set 3D arrow visibility to false OR scale it to 0
- always get camera position
- set Z coordinate to trigger (just took Z coordinate so there is a 'line' that will be the trigger), for instance: -400.
- when camPos.Z = -400, set the 3D arrow to visible OR rescale to 1
Is this the correct way to do it? Or is there a better way?
I did try the simple (but obviously useless) logic by putting the codes in the while(device->run()) loop so that the camPos will always be updated, but somehow the IF statement always returns true from the start, therefore making the model visible.
If there was a similar thread to this query, could you direct me to it? Thanks all, help appreciated!
:)
[SOLVED] Making objects dis/reappear on certain conditions
-
- Posts: 14
- Joined: Wed Mar 15, 2006 9:52 am
[SOLVED] Making objects dis/reappear on certain conditions
Last edited by Sd-RawK-Cab25 on Wed Apr 19, 2006 1:47 am, edited 1 time in total.
Well first off, you won't want to test a floating point value for equality. The chances that the camera height will be exactly 400 are very slim.
If you are writing an actual game, you might want to consider abstracting some of the condition stuff out so you can reuse it. I have used a condition/trigger/callback system for things like this in the past. It is a little complicated to explain, but here goes...
The system starts out as what I call a trigger. The trigger is a template that has a pointer to a condition, a pointer to an object and a member function to invoke on that object when the condition is met.
The conditions can be built up into a heirarchy, so you can require multiple conditions be set [using boolean logic] before the trigger is executed. All you need to do is periodically check the trigger condition and reset it if necessary.
Travis
If you are writing an actual game, you might want to consider abstracting some of the condition stuff out so you can reuse it. I have used a condition/trigger/callback system for things like this in the past. It is a little complicated to explain, but here goes...
The system starts out as what I call a trigger. The trigger is a template that has a pointer to a condition, a pointer to an object and a member function to invoke on that object when the condition is met.
The conditions can be built up into a heirarchy, so you can require multiple conditions be set [using boolean logic] before the trigger is executed. All you need to do is periodically check the trigger condition and reset it if necessary.
Travis
-
- Posts: 14
- Joined: Wed Mar 15, 2006 9:52 am
uhh sorry vitek, i don't think i fully understand the terms you're using since i'm quite new to c++.
what i understand from what u posted is - create a function which accepts parameters such as current camera position and the object node. then in this function, have a check on the needed camera position and set the object to visible or not depending on condition (true or false).
Is this what u meant? :oops: sorry, i'm a bit slow when trying to understand c++ concepts by theory only. it would really help me if you could give me a very simple example so that i can try and understand your concept. :)
Anyway, about the code:
yeah, it's possibly the simplest and stupidest code/logic ever but i'm a n00b, so cut me some slack. :D :lol:
what i understand from what u posted is - create a function which accepts parameters such as current camera position and the object node. then in this function, have a check on the needed camera position and set the object to visible or not depending on condition (true or false).
Is this what u meant? :oops: sorry, i'm a bit slow when trying to understand c++ concepts by theory only. it would really help me if you could give me a very simple example so that i can try and understand your concept. :)
Anyway, about the code:
Code: Select all
while(device->run())
if(device->isWindowActive())
{
driver->beginScene(true,true,0);
smgr->drawAll();
driver->endScene();
core::vector3df camPos = camera->getAbsolutePosition();
int x = camPos.X;
int y = camPos.Y;
int z = camPos.Z;
if (z = -430)
{
arrowNode->setVisible(true);
}
}
"z = -430" means "set z equal to -430",
what you meant was "z == -430" or "is z equal to -430"
but what you need is "z < -430" meaning "is z less than -430" (like Travis said)
you should brush up on your c++ operators, if not read the whole c++ manual
what you meant was "z == -430" or "is z equal to -430"
but what you need is "z < -430" meaning "is z less than -430" (like Travis said)
you should brush up on your c++ operators, if not read the whole c++ manual
Last edited by bitplane on Wed Apr 19, 2006 1:48 am, edited 1 time in total.
-
- Posts: 14
- Joined: Wed Mar 15, 2006 9:52 am