reading file data and making models move accordingly
reading file data and making models move accordingly
hello,
am new 2 this engine. I am doing a visualization on it. I have the coordinates of the model at each step.
I want to know of a tutorial to read the file and make the object move accordingly.
My file is as follows:
RUN,ID,x,y,z,time
...
....
....
Can anyone give me a good tutorial on this or some hints n help to start on this.
Thhanks
am new 2 this engine. I am doing a visualization on it. I have the coordinates of the model at each step.
I want to know of a tutorial to read the file and make the object move accordingly.
My file is as follows:
RUN,ID,x,y,z,time
...
....
....
Can anyone give me a good tutorial on this or some hints n help to start on this.
Thhanks
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Re: reading file data and making models move accordingly
Spline animators don't have any concept of 'time' though; they just move at a fixed speed through all of their points.delinkx wrote:RUN,ID,x,y,z,time
Can you explain a little more about what all the parameters mean? In fact, if you can provide specific requirements and a sample resource file, I'll likely just write some sample code for it, since it looks like fun.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Re: reading file data and making models move accordingly
rogerborg wrote:Spline animators don't have any concept of 'time' though; they just move at a fixed speed through all of their points.delinkx wrote:RUN,ID,x,y,z,time
Can you explain a little more about what all the parameters mean? In fact, if you can provide specific requirements and a sample resource file, I'll likely just write some sample code for it, since it looks like fun.
rogerborg.. i sent u a PM with more details. thx.
JP,
wat i need to do is do the animated walk every 0.05 seconds. i need to construct the followsplieanimator every 0.05 seconds.
wat i need to do is do the animated walk every 0.05 seconds. i need to construct the followsplieanimator every 0.05 seconds.
JP wrote:The Demo tutorial shows you how to use the follow spline animator which allows you to move a node along a set path automatically so just read in your list of positions and construct a follow spline animator from those points, then add the animator to the object you want to move.
no tat is not wat i really need. the one in demo tutorial is user controlled movement. ok wat i need to do basically is as follows:JP wrote:why do you need to construct the follow spline animator more than once?
check out the demo tutorial in the SDK and see if what the camera does on start up (fly around the quake map on a preset, automated path) is the sort of thing you think you need.
- i have a file which has a set of cordinates for a no. of objects to be moved. At every 0.05 second, the no. of objects are moved according to the x,y,z values given.
- suppose we have 10 objects to be moved.
- reading the file is ok.
- at time 0,
CREATE 10 OBJECTS AT THE POINTS GIVEN IN THE FILE
- at time = time + 0.05 seconds,
for(i=0, i<10; i++)
{
move object from current position to position set in file;
}
wait(0.05 sec);
go back to for loop until EOF.
--------------------------------
the file reading n storing values in the array is fine.
only the movement every 0.05 secs i have problem.
No, look at irrlicht-1.4.1\bin\Win32-VisualStudio\Demo.exe
When the app starts the camera starts flying around the quake map itself, no user interaction at all.
To me that sounds exactly what you're after. So all you need to do is read in the necessary points from your file and create the follow spline animator (as can be seen in the demo's source code) and then everything will be animated along their paths for you.
When the app starts the camera starts flying around the quake map itself, no user interaction at all.
To me that sounds exactly what you're after. So all you need to do is read in the necessary points from your file and create the follow spline animator (as can be seen in the demo's source code) and then everything will be animated along their paths for you.
ok. i read the tat. but the problem here now is i have to create the whole set of path.JP wrote:No, look at irrlicht-1.4.1\bin\Win32-VisualStudio\Demo.exe
When the app starts the camera starts flying around the quake map itself, no user interaction at all.
To me that sounds exactly what you're after. So all you need to do is read in the necessary points from your file and create the follow spline animator (as can be seen in the demo's source code) and then everything will be animated along their paths for you.
my file is huge. i can have 200 + objects. and storing the values for every 0.05 secs, i need huge arrays for this.
this way it is like
- read whole file
- create the flystraight animators
- render and visualize
But tats not gonna be memory efficient for my application.
My wish to optimize the memory is to develop it according to this algorithm:
- Read 'Create' part of file
-> create the objects at the point
- for the first time frame, read the values, store.
-> then create animator for that part and render.
- then read the next part of the file
-> create animator and render.
.... in a loop.
-
rogerborg
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
If you're running on a desktop, memory is cheap, while filesystem access is still (relatively) slow. On a mobile device, memory is more expensive, but filesystem access is even slower.
I'd go for storing everything in memory, rather than doing incremental file reads. 200 objects * 20 movement per second * 20 bytes per move (position, id, time) = 78kB of memory per second's worth of movement positions.
You'll notice that despite what m'lurned colleague said about 0.05 seconds being a small granularity that the objects do jump noticeably between positions. Still, that's apparently your requirement, so that's what I've implemented. If it turns out that you want smooth interpolation, then we can revisit your requirements.
The sample commands that you supplied have RUN commands with time 0. This seems non-sensical, since they'll move from their initial positions immediately. I've added 0.05f to the time for each RUN command as a workaround, but again, I think you should check your requirements.
I'd go for storing everything in memory, rather than doing incremental file reads. 200 objects * 20 movement per second * 20 bytes per move (position, id, time) = 78kB of memory per second's worth of movement positions.
You'll notice that despite what m'lurned colleague said about 0.05 seconds being a small granularity that the objects do jump noticeably between positions. Still, that's apparently your requirement, so that's what I've implemented. If it turns out that you want smooth interpolation, then we can revisit your requirements.
The sample commands that you supplied have RUN commands with time 0. This seems non-sensical, since they'll move from their initial positions immediately. I've added 0.05f to the time for each RUN command as a workaround, but again, I think you should check your requirements.
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
int main()
{
FILE * commandFile = fopen("commands.txt", "r");
if(!commandFile)
return 1;
IrrlichtDevice *device =
createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 32,
false, false, false, 0);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
typedef struct SCommand
{
s32 objectId;
vector3df newPosition;
f32 atTime;
SCommand() { }
SCommand(s32 id, vector3df& position, f32 time)
: objectId(id), newPosition(position), atTime(time) { }
} SCommand;
list<SCommand> commands;
array<ITextSceneNode*> objects;
char line[256];
while(!feof(commandFile))
{
(void)fgets(line, sizeof(line), commandFile);
s32 id;
vector3df position;
f32 time;
if(5 == sscanf(line, "CREATE,%d,%f,%f,%f,%f",
&id, &position.X, &position.Y, &position.Z, &time))
{
// To prevent multiple re-allocaitons, create your highest ID object first!
objects.set_used(id);
stringw text(id);
ITextSceneNode * newNode = smgr->addTextSceneNode(smgr->getGUIEnvironment()->getBuiltInFont(), text.c_str());
if(!newNode)
return 2;
newNode->setPosition(position);
objects[id - 1] = newNode;
}
else if(5 == sscanf(line, "RUN,%d,%f,%f,%f,%f",
&id, &position.X, &position.Y, &position.Z, &time))
{
SCommand newCommand(id, position, time + 0.05f);
commands.push_back(newCommand);
}
else
{
(void)printf("\nBad line: %s\n\n", line);
return 3;
}
}
(void)fclose(commandFile);
ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(vector3df(1000, -500, -4000));
while(device->run())
{
static u32 startTime = device->getTimer()->getTime();
u32 now = device->getTimer()->getTime();
f32 elapsedTime = (now - startTime) / 1000.f;
if(!commands.empty())
{
list<SCommand>::Iterator it = commands.begin();
SCommand command;
while(it != commands.end())
{
command = *it;
list<SCommand>::Iterator eraseMe = it;
it++;
if(elapsedTime >= command.atTime)
{
objects[command.objectId - 1]->setPosition(command.newPosition);
commands.erase(eraseMe);
}
}
}
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
}
objects.clear();
commands.clear();
device->drop();
return 0;
}
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
the purpose is for PC based not mobile. so its fine. yes,, sorry tat was a mistake. the RUN command starts at 0.05 sec.rogerborg wrote:If you're running on a desktop, memory is cheap, while filesystem access is still (relatively) slow. On a mobile device, memory is more expensive, but filesystem access is even slower.
I'd go for storing everything in memory, rather than doing incremental file reads. 200 objects * 20 movement per second * 20 bytes per move (position, id, time) = 78kB of memory per second's worth of movement positions.
You'll notice that despite what m'lurned colleague said about 0.05 seconds being a small granularity that the objects do jump noticeably between positions. Still, that's apparently your requirement, so that's what I've implemented. If it turns out that you want smooth interpolation, then we can revisit your requirements.
The sample commands that you supplied have RUN commands with time 0. This seems non-sensical, since they'll move from their initial positions immediately. I've added 0.05f to the time for each RUN command as a workaround, but again, I think you should check your requirements.
Code: Select all
#include <irrlicht.h> using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; #pragma comment(lib, "Irrlicht.lib") int main() { FILE * commandFile = fopen("commands.txt", "r"); if(!commandFile) return 1; IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 32, false, false, false, 0); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); typedef struct SCommand { s32 objectId; vector3df newPosition; f32 atTime; SCommand() { } SCommand(s32 id, vector3df& position, f32 time) : objectId(id), newPosition(position), atTime(time) { } } SCommand; list<SCommand> commands; array<ITextSceneNode*> objects; char line[256]; while(!feof(commandFile)) { (void)fgets(line, sizeof(line), commandFile); s32 id; vector3df position; f32 time; if(5 == sscanf(line, "CREATE,%d,%f,%f,%f,%f", &id, &position.X, &position.Y, &position.Z, &time)) { // To prevent multiple re-allocaitons, create your highest ID object first! objects.set_used(id); stringw text(id); ITextSceneNode * newNode = smgr->addTextSceneNode(smgr->getGUIEnvironment()->getBuiltInFont(), text.c_str()); if(!newNode) return 2; newNode->setPosition(position); objects[id - 1] = newNode; } else if(5 == sscanf(line, "RUN,%d,%f,%f,%f,%f", &id, &position.X, &position.Y, &position.Z, &time)) { SCommand newCommand(id, position, time + 0.05f); commands.push_back(newCommand); } else { (void)printf("\nBad line: %s\n\n", line); return 3; } } (void)fclose(commandFile); ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(); camera->setPosition(vector3df(1000, -500, -4000)); while(device->run()) { static u32 startTime = device->getTimer()->getTime(); u32 now = device->getTimer()->getTime(); f32 elapsedTime = (now - startTime) / 1000.f; if(!commands.empty()) { list<SCommand>::Iterator it = commands.begin(); SCommand command; while(it != commands.end()) { command = *it; list<SCommand>::Iterator eraseMe = it; it++; if(elapsedTime >= command.atTime) { objects[command.objectId - 1]->setPosition(command.newPosition); commands.erase(eraseMe); } } } driver->beginScene(true, true, SColor(255,100,101,140)); smgr->drawAll(); driver->endScene(); } objects.clear(); commands.clear(); device->drop(); return 0; }
i will check out the code and have a try on it and see how it is. Wat i also want is the animation betweeen the 2 points. walk animation.
Re: reading file data and making models move accordingly
i tried running the code u sent me using text objects itself. reading the file for 32 objets was fine. but when reading for 200 it crashed. and here's the call stack:rogerborg wrote:Spline animators don't have any concept of 'time' though; they just move at a fixed speed through all of their points.delinkx wrote:RUN,ID,x,y,z,time
Can you explain a little more about what all the parameters mean? In fact, if you can provide specific requirements and a sample resource file, I'll likely just write some sample code for it, since it looks like fun.
> cosmos1.exe!irr::core::array<irr::scene::ITextSceneNode *,irr::core::irrAllocator<irr::scene::ITextSceneNode *> >::operator[](unsigned int index=4294967295) Line 264 + 0xb bytes C++
