Saving position coordinates in real-time
by Zachary Seldess · in Torque Game Engine · 10/04/2006 (12:34 pm) · 20 replies
Hi everyone,
I'm thinking about buying the Torque 3D Game Engine - it seems to be perfect for what I want to do - but before I do buy it I'm hoping to get a little feedback from those of you that have experience with the engine.
Here's what I'm doing:
I'm building interactive virtual sound environments/works inside 3D maps that, via LAN, can be experienced and altered in real-time simultaneously by several users. To achieve this I have to combine 3D gaming software with real-time audio processing software (Cycling 74's Max/MSP).
So... all I really need to know before I jump in and buy TGE is this:
Can I access the positional coordinates of specific players inside the game environment (x,y,z,pitch,yaw, etc.) in REAL-TIME and constantly save that information to a file (txt or xml) on the hard drive of the computer being used? If I can do this then it will be easy for me to use that information to create a very subtle, and complex spatialized sound environment.
Any help would be greatly appreciated!
Zachary
I'm thinking about buying the Torque 3D Game Engine - it seems to be perfect for what I want to do - but before I do buy it I'm hoping to get a little feedback from those of you that have experience with the engine.
Here's what I'm doing:
I'm building interactive virtual sound environments/works inside 3D maps that, via LAN, can be experienced and altered in real-time simultaneously by several users. To achieve this I have to combine 3D gaming software with real-time audio processing software (Cycling 74's Max/MSP).
So... all I really need to know before I jump in and buy TGE is this:
Can I access the positional coordinates of specific players inside the game environment (x,y,z,pitch,yaw, etc.) in REAL-TIME and constantly save that information to a file (txt or xml) on the hard drive of the computer being used? If I can do this then it will be easy for me to use that information to create a very subtle, and complex spatialized sound environment.
Any help would be greatly appreciated!
Zachary
About the author
#2
10/04/2006 (1:08 pm)
I think because he wants to use it to modify the sound data. I assume you are talking about modifying some kind of sound setup that exists in the real world? Or I guess some kind of complex audio software. Anyways, writing out the data of objects like that is a piece of cake, but I'm not sure how fast it would run in a "realtime" setup. It should be pretty easy to at least get a prototype running by doing that though. But eventually you might want to look at some other method of interfacing your audio software directly with the server in TGE, so it can read the data you need straight from the simulation.
#3
So I will build a 3D sound environment that maps onto the 3D map. And you're right Paul - this solution to the problem is not the best one - really more of faking the two world's coexistence. But it's where I'll start because it's easy ( = there are preexisting objects in Max/MSP) to perpetually read info from a txt file. Eventually, I will want to design new Max/MSP objects that really interface with the server in TGE (not just coordinate info, but actions as well). The objects are written in C, though, so I'll need help with that when the time comes.
Another question: Can the coordinate information of the players in the game be stored in a static location in the RAM of the server? If so, that would be the first Max object that I would need to make. And Paul, is this what you had in mind when you wrote "some other method of interfacing your audio software directly with the server in TGE, so it can read the data you need straight from the simulation"?
10/04/2006 (4:49 pm)
Thanks Paul and Sean for the quick response. The audio software that I use (Max/MSP) is really more of a graphic object-oriented programming environment for real-time "whatever" (i.e. realtime use of data to manipulate/generate sound, video, lighting, etc.). In this project I will be using the software to design the 3D sonic counterpart to the 3D map running on the Torque engine. Why use this software? It's extremely powerful and versatile, and just as the game engine allows for much creativity, expression, and interactivity in terms of the design and use of 3D visual worlds, Max/MSP allows for a similar amount of subtlety and flexibility in the design of the sonic world.So I will build a 3D sound environment that maps onto the 3D map. And you're right Paul - this solution to the problem is not the best one - really more of faking the two world's coexistence. But it's where I'll start because it's easy ( = there are preexisting objects in Max/MSP) to perpetually read info from a txt file. Eventually, I will want to design new Max/MSP objects that really interface with the server in TGE (not just coordinate info, but actions as well). The objects are written in C, though, so I'll need help with that when the time comes.
Another question: Can the coordinate information of the players in the game be stored in a static location in the RAM of the server? If so, that would be the first Max object that I would need to make. And Paul, is this what you had in mind when you wrote "some other method of interfacing your audio software directly with the server in TGE, so it can read the data you need straight from the simulation"?
#4
In short, yes, but it depends on what you're able to do in your outside program. I wrote a shared .dll in the past to pass position info from Torque to an outside program. The data was saved as shared data in the .dll and then could be accessed via accessors in the other program. And if you go that route don't forget to use the Dynamic Library resource, it makes loading the .dll in Torque a lot easier.
10/05/2006 (6:15 am)
@ZacharyIn short, yes, but it depends on what you're able to do in your outside program. I wrote a shared .dll in the past to pass position info from Torque to an outside program. The data was saved as shared data in the .dll and then could be accessed via accessors in the other program. And if you go that route don't forget to use the Dynamic Library resource, it makes loading the .dll in Torque a lot easier.
#5
So the big question is, will I (with some hard work of course) be able to create, in a short time, a simple networked "game environment" - and I mean very simple, no weapons, no killing, just entering the space and moving around it? I'm not as worried about the terrain/map building as I am about the creation of the rules and game interface. I don't want to buy the engine and then realize it's capable of doing exactly what I want, but I won't actually be able to make it do what I want until one year of refining my skills.
Zachary
10/10/2006 (9:10 am)
This brings me to the hard-to-answer question. TGE seems like a highly complex engine - highly configurable if you have programming experience. I don't have much. So the big question is, will I (with some hard work of course) be able to create, in a short time, a simple networked "game environment" - and I mean very simple, no weapons, no killing, just entering the space and moving around it? I'm not as worried about the terrain/map building as I am about the creation of the rules and game interface. I don't want to buy the engine and then realize it's capable of doing exactly what I want, but I won't actually be able to make it do what I want until one year of refining my skills.
Zachary
#6
download the free demo.
it does basic networked gaming / shared experience right out of the box,
and a lot more.
when you buy the engine you're basically getting the source code to the demo.
regarding saving the position of players in realtime to a file,
you could even do that with just the demo.
- altho as scott mentioned, there are more sophisticated (and complicated) ways to go about getting data out of torque into another app.
10/10/2006 (9:32 am)
Hi Zachary -download the free demo.
it does basic networked gaming / shared experience right out of the box,
and a lot more.
when you buy the engine you're basically getting the source code to the demo.
regarding saving the position of players in realtime to a file,
you could even do that with just the demo.
- altho as scott mentioned, there are more sophisticated (and complicated) ways to go about getting data out of torque into another app.
#7
Zachary
10/15/2006 (6:41 pm)
Thanks for the advice everyone. I've purchased TGE, tried some stuff out, and it looks like it's perfect for my project. Orion, you mentioned that I could save the position of the players in realtime to a file - even in the demo. Can you explain how, or point me to a tutorial that has that information in it? I'm going to be reading a lot of documentation from now on, but it would save me time if I got right down to working on the most imporant issue. Thanks.Zachary
#8
http://www.garagegames.com/mg/forums/result.thread.php?qt=7575
You'll want to write some scripts in your server directory that write out the data you want. I'm not sure what data it is you want, but tracking objects is easy in Torque Script. If you need any help figuring out more, just ask.
10/16/2006 (5:04 pm)
Here's a thread pretty well covers the basics of file i/o from script.http://www.garagegames.com/mg/forums/result.thread.php?qt=7575
You'll want to write some scripts in your server directory that write out the data you want. I'm not sure what data it is you want, but tracking objects is easy in Torque Script. If you need any help figuring out more, just ask.
#9
i meant to get back w/ more info but got buried under other stuff.
10/16/2006 (5:15 pm)
Thanks Paul,i meant to get back w/ more info but got buried under other stuff.
#10
Thanks for the links. I've looked through them a bit and it seems like some of what I want is there, I'm just not good enough at TorqueScript to fully understand it. This looks like something I could use, but I don't want a save dialog to pop up, I want to perpetually resave the player's position information in a specific text file that can be simulataneously read by another program.
function SaveFile()
{
getSaveFilename("*.txt",saveTextFile,"default.txt");
}
function saveTextFile(%fileName)
{
%file = new FileObject();
%file.openforWrite(%filename);
%file.writeLine( "This is an output file);
%file.writeLine( "I can contain any plain text that the user wishes to output." );
%file.close();
%file.delete();
}
What is this doing? Is this like the above but without a save dialog? And do I specify the file path in the the filename? As you can see, I'm new to this.
function write(%filename)
{
%file = new FileObject();
%file.openforWrite(%filename);
%file.writeLine( "This is an output file);
%file.writeLine( "I can contain any plain text that the user wishes to output." );
%file.close();
%file.delete();
}
And then how can can someone tell me how to get the position of the player into this file?
If one of you very generous souls could offer some script that could do this, it would be REALLY helpful. I'm a total beginner, trying to learn the script, but I think it could take a long while to learn enough to do even this simple thing. I've got everything but this scripting issue worked out for the intitial stage of my project, and I'd like to get this script done so I can start to work with the information in terms of sound in the other program.
10/25/2006 (1:02 pm)
Hi Paul, Orion, and everyone,Thanks for the links. I've looked through them a bit and it seems like some of what I want is there, I'm just not good enough at TorqueScript to fully understand it. This looks like something I could use, but I don't want a save dialog to pop up, I want to perpetually resave the player's position information in a specific text file that can be simulataneously read by another program.
function SaveFile()
{
getSaveFilename("*.txt",saveTextFile,"default.txt");
}
function saveTextFile(%fileName)
{
%file = new FileObject();
%file.openforWrite(%filename);
%file.writeLine( "This is an output file);
%file.writeLine( "I can contain any plain text that the user wishes to output." );
%file.close();
%file.delete();
}
What is this doing? Is this like the above but without a save dialog? And do I specify the file path in the the filename? As you can see, I'm new to this.
function write(%filename)
{
%file = new FileObject();
%file.openforWrite(%filename);
%file.writeLine( "This is an output file);
%file.writeLine( "I can contain any plain text that the user wishes to output." );
%file.close();
%file.delete();
}
And then how can can someone tell me how to get the position of the player into this file?
If one of you very generous souls could offer some script that could do this, it would be REALLY helpful. I'm a total beginner, trying to learn the script, but I think it could take a long while to learn enough to do even this simple thing. I've got everything but this scripting issue worked out for the intitial stage of my project, and I'd like to get this script done so I can start to work with the information in terms of sound in the other program.
#11
here's some basic functionality.
put it in a .cs file somewhere (say in client.cs, but it should really get a file all its own),
and then call "PPosStart();" to start recording and "PPosStop();" to stop.
Note i added a timestamp at the front of each line, because that seemed good.
This will record the player's position every half second. To make it more frequent, decrease "gPPosPeriod".
I'm not 100% sure that "$player" is defined in stock TGE tho. If it's not, let me know.
I actually tested this, so except for the possible $player thing, it should work.
10/25/2006 (1:54 pm)
Hey Zach - this sounds like a fun project, and i can't resist writing a little code -here's some basic functionality.
put it in a .cs file somewhere (say in client.cs, but it should really get a file all its own),
and then call "PPosStart();" to start recording and "PPosStop();" to stop.
Note i added a timestamp at the front of each line, because that seemed good.
This will record the player's position every half second. To make it more frequent, decrease "gPPosPeriod".
I'm not 100% sure that "$player" is defined in stock TGE tho. If it's not, let me know.
I actually tested this, so except for the possible $player thing, it should work.
$gPPosFileName = "./playerPos.txt"; // output filename. will be a sibling of console.log
$gPPosPeriod = "500"; // store position every 500 MS aka half a second
$gPPosTimer = 0; // utility variable
function PPosTick()
{
cancel($gPPosTimer);
PPosDoPosWrite();
$gPPosTimer = schedule($gPPosPeriod, 0, "PPosTick");
}
function PPosDoPosWrite()
{
%line = (getSimTime() / 1000) @ ": " @ $Player.getPosition();
%file = new FileObject();
%file.openForAppend($gPPosFileName);
%file.writeLine(%line);
%file.close();
%file.delete();
}
// to kick it all off, call this:
function PPosStart()
{
PPosTick();
}
// to stop it, call this:
function PPosStop()
{
cancel($gPPosTimer);
$gPPosTimer = 0;
}
#12
It looks like $player is not defined. Here's what I get in the console:
EGTGE1/server/position.cs (21): Unable to find object: ' ' attempting to call function 'getPosition'
This occurs every 500 ms. The text file is written but contains only the time stamp.
Can you show me how to define $player? Is it something like this that I need to include?
$player = localclientconnection.player;
And one more thing. The time stamp is great, and I may end up using it. But for now, it would be easier to have an index number followed by a comma. So something like this maybe? I'm just guessing, as you can see.
$index=0;
function PPosDoPosWrite()
{
%line = ($index++ @ "," SPC $Player.getPosition();
10/26/2006 (9:39 am)
Wow! Thanks Orion! This community is really supportive. I hope I'll be able to reciprocate eventually. I named the file position.cs, put it in the server directory, and added the necessary line of script in main.csIt looks like $player is not defined. Here's what I get in the console:
EGTGE1/server/position.cs (21): Unable to find object: ' ' attempting to call function 'getPosition'
This occurs every 500 ms. The text file is written but contains only the time stamp.
Can you show me how to define $player? Is it something like this that I need to include?
$player = localclientconnection.player;
And one more thing. The time stamp is great, and I may end up using it. But for now, it would be easier to have an index number followed by a comma. So something like this maybe? I'm just guessing, as you can see.
$index=0;
function PPosDoPosWrite()
{
%line = ($index++ @ "," SPC $Player.getPosition();
#13
hmm, i'm not sure about localclientconnection.
try using this instead of $player: $GameConnection.getPlayerObject().
w/r/t $index, you're spot-on.
10/26/2006 (12:22 pm)
Hiya -hmm, i'm not sure about localclientconnection.
try using this instead of $player: $GameConnection.getPlayerObject().
w/r/t $index, you're spot-on.
#14
$index=0;
function PPosDoPosWrite()
{
%line = ($index++ @ "," SPC $Player.getPosition();
best,
Zachary
10/26/2006 (12:31 pm)
This seems to work fine, but I forgot to ask one more question: How can I overwrite the information everytime I call the function PposStart(); ?$index=0;
function PPosDoPosWrite()
{
%line = ($index++ @ "," SPC $Player.getPosition();
best,
Zachary
#15
how about something like this:
10/26/2006 (12:53 pm)
You mean re-start the file ?how about something like this:
function PPosReset()
{
$index = 0;
%file = new FileObject();
%file.openForWrite($gPPosFileName);
%file.close();
%file.delete();
}
#16
I added that last bit and it works fine. To report the positions, this is what I'm doing:
function PPosDoPosWrite()
{
%line = ($index++) @ "," SPC localclientconnection.player.getTransform();
Thanks again! This is so helpful.
Zach
10/26/2006 (1:30 pm)
You Rock! Thank you so much!I added that last bit and it works fine. To report the positions, this is what I'm doing:
function PPosDoPosWrite()
{
%line = ($index++) @ "," SPC localclientconnection.player.getTransform();
Thanks again! This is so helpful.
Zach
#17
i think localclientconnection may only be valid in standalone mode, so if $GameConnection works it might be a bit better if you ever want to do this multiplayer-style, but that's pretty minor.
yeah, the community here is great.
i definitely got a lot of help when i was getting started so i enjoy helping out when i can.
plus your project sounds cool. ;)
ooo
10/26/2006 (1:35 pm)
Hey Zach - my pleasure !i think localclientconnection may only be valid in standalone mode, so if $GameConnection works it might be a bit better if you ever want to do this multiplayer-style, but that's pretty minor.
yeah, the community here is great.
i definitely got a lot of help when i was getting started so i enjoy helping out when i can.
plus your project sounds cool. ;)
ooo
#18
So everything is working great with localclientconnection.player.getTransform();
I can't get $GameConnection to work though, but that's ok for now.
I've been trying to decipher the last two numbers in the vector from getTransform, and I've got it now, but I don't really understand why it's done this way. Here's the data:
from 0 to 239.99999 degrees (just under 2/3rds of 360 degrees) the last two numbers read:
6th number : 1 throughout
7th number: 0. - 4.28879 (just under 2/3rds of 2(pi))
That's perfectly sensible. But then from 240 - 360 degrees:
6th number : -1 throughout
7th number : 2.09439 - 0.
I can definitely work with this as the relationships never change, but WHY not just continue increasing up to 2(pi) from 240 - 360 degrees. That seems the easiest conceptually. Maybe I'm missing something here. Any ideas?
10/26/2006 (7:59 pm)
Orion,So everything is working great with localclientconnection.player.getTransform();
I can't get $GameConnection to work though, but that's ok for now.
I've been trying to decipher the last two numbers in the vector from getTransform, and I've got it now, but I don't really understand why it's done this way. Here's the data:
from 0 to 239.99999 degrees (just under 2/3rds of 360 degrees) the last two numbers read:
6th number : 1 throughout
7th number: 0. - 4.28879 (just under 2/3rds of 2(pi))
That's perfectly sensible. But then from 240 - 360 degrees:
6th number : -1 throughout
7th number : 2.09439 - 0.
I can definitely work with this as the relationships never change, but WHY not just continue increasing up to 2(pi) from 240 - 360 degrees. That seems the easiest conceptually. Maybe I'm missing something here. Any ideas?
#19
the last four digits from GetTransform() represent the orientation like this: "AxisX AxisY AxisZ Theta",
where Axis is a unit-length vector, and Theta is the radians to rotate around that axis.
converting from a real rotation matrix to a "quaternion" like that sometimes gives you numbers like that.
10/27/2006 (1:46 pm)
Heh, that's sorta just the way it goes.the last four digits from GetTransform() represent the orientation like this: "AxisX AxisY AxisZ Theta",
where Axis is a unit-length vector, and Theta is the radians to rotate around that axis.
converting from a real rotation matrix to a "quaternion" like that sometimes gives you numbers like that.
#20
So everything's working great so far - I'm reporting the movement of my player to my other software that then uses the info to process and spatialize audio. Thanks again Orion and everyone else for the help. Moving on though...
Here's what I want to do next:
I want dynamic, moving lights to float around in a space. I've been working with the lighting kit and seem not to have any problems using what's there (static and dynamic), although I never feel like I fully understand what I'm working with (can't find extensive docs on lighting - TDN doesn't seem to have much). But I can't figure out how to get the dynamic lights to move around in space. I'm thinking of perhaps several different colored FlameLights (don't now how to do this - with lighting editor?) floating around a room, crossing paths from time to time.
Can someone give me a few tips? I'm asking here after quite a bit of searching on my own, to no avail.
And then... the second part! : (Orion, any more advice you can offer on this would be amazing)
Once I've got the lights moving around, I want to save this information to a txt file just as mentioned in the above posts. Here's how I'm formatting the player info in the text file, for reference (thanks again Orion). I'd like to do a similar thing with the lights:
Any help would be greatly appriciated. This engine (and community) has really been inspiring me.
Zachary
11/13/2006 (9:24 am)
Hey there,So everything's working great so far - I'm reporting the movement of my player to my other software that then uses the info to process and spatialize audio. Thanks again Orion and everyone else for the help. Moving on though...
Here's what I want to do next:
I want dynamic, moving lights to float around in a space. I've been working with the lighting kit and seem not to have any problems using what's there (static and dynamic), although I never feel like I fully understand what I'm working with (can't find extensive docs on lighting - TDN doesn't seem to have much). But I can't figure out how to get the dynamic lights to move around in space. I'm thinking of perhaps several different colored FlameLights (don't now how to do this - with lighting editor?) floating around a room, crossing paths from time to time.
Can someone give me a few tips? I'm asking here after quite a bit of searching on my own, to no avail.
And then... the second part! : (Orion, any more advice you can offer on this would be amazing)
Once I've got the lights moving around, I want to save this information to a txt file just as mentioned in the above posts. Here's how I'm formatting the player info in the text file, for reference (thanks again Orion). I'd like to do a similar thing with the lights:
$gPPosFileName = "./playerPos.txt"; // output filename. will be a sibling of console.log
$gPPosPeriod = "100"; // store position every 100 msec
$gPPosTimer = 0; // utility variable
$index = 1; // index variable for coll object
function PPosTick()
{
cancel($gPPosTimer);
PPosDoPosWrite();
$gPPosTimer = schedule($gPPosPeriod, 0, "PPosTick");
}
function PPosDoPosWrite()
{
PPosReset();
%line = "1" @ "," SPC localclientconnection.player.getTransform() @ ";";
%file = new FileObject();
%file.openForAppend($gPPosFileName);
%file.writeLine(%line);
%file.close();
%file.delete();
}
// to kick it all off, call this:
function PPosStart()
{
PPosTick();
}
// to stop it, call this:
function PPosStop()
{
cancel($gPPosTimer);
$gPPosTimer = 0;
}
// to reset it, call this:
function PPosReset()
{
$index = 0;
%file = new FileObject();
%file.openForWrite($gPPosFileName);
%file.close();
%file.delete();
}Any help would be greatly appriciated. This engine (and community) has really been inspiring me.
Zachary
Torque 3D Owner Sean H.