read listener position from ASCII file
#1
Posted 04 September 2007 - 04:27 PM
i'm studying the tutorial http://www.devmaster...rticles/openal/ and i'm trying to modify it a bit,in order to fit it to my purpouses.
I've already got a 3D environment made with OGRE; it outputs the position of the listener as an ASCII file.
How can i make the code for the sound read that position?
any kind of tips and suggestions would be extremely precious...i'm groping in the dark! :)
#2
Posted 04 September 2007 - 04:31 PM
#3
Posted 05 September 2007 - 09:29 AM
I have only the final product made with OGRE and not the code.
I'll mention it to them,to see if we can avoid this bottle neck.
I'm a newbie in programming,so can you give few more tips?
what's the command to read the coordinates from the file?
#4
Posted 05 September 2007 - 09:29 AM
#5
Posted 05 September 2007 - 12:57 PM
That actually depends on how your file is formatted.
Say you have got a simple whitespace terminated ASCII file with three standard format IEEE floating point numbers in it, such as
0.73 0.1112 10.45
Then, you can read in your three coordinates like this
#include <fstream> // Header with std::[i,o]fstream classes
/* .... */
std::ifstream myfile; // Create a new input file stream
myfile.open("FILEDIR\\Filename.txt"); // Connect file stream to file
double x, y, z; // Coordinates
myfile >> x; // Read them out, one by one, whitespace automatically is ignored
myfile >> y;
myfile >> z;
Reading a different format (CSV or similar) might take a bit more time for implementation.
Cheers,
- Wernaeh
#7
Posted 06 September 2007 - 10:40 AM
this is the format:
x315346.304077 z233442.343323 a25.650650
the user has can't change the height (it's fixed by default at 4m) but only the 2 dimensions of an horizontal plane x,z and the angle a
#8
Posted 06 September 2007 - 12:40 PM
If its just for a small project (i.e. no code reuse, no need for robustness), I'd suggest the following:
std::ifstream infile;
infile.open("filename");
float coordinates[3];
for (int i = 0;
i < 3;
++i)
{
infile.get();
infile >> coordinates[i];
}
Note this assumes that there are no errors within the source file (i.e. leading char always present). For a more robust version, invent some sort of error checking on your own :)
Cheers,
- Wernaeh
#9
Posted 06 September 2007 - 12:49 PM
it might be a stupid question,but i don't get how the code you gave me "understands" the difference between the coordinate of a plan (x,z) and the orientation a.
thanks and sorry for bothering you again
#10
Posted 06 September 2007 - 04:25 PM
#11
Posted 06 September 2007 - 04:41 PM
i understand.
how should i tell the computer that a is the angle between the user's view and the axis north-south? it was meant for the partition of the sound between the left and right earphone.
do you think it is useless or i don't need it?
#13
Posted 07 September 2007 - 10:12 AM
#14
Posted 07 September 2007 - 03:36 PM
EDIT: Alternatively, you could transform your x and z coordinates by rotating them about the origin by a if you only have a single source.
#15
Posted 07 September 2007 - 03:45 PM
anyway i have more than one source but i'll try to understand the facing thing by studying a piece of code i found! :)
so do you think it will work reading the ASCII file that way and then defining the angle as you said?
ps:thank you very much for the explanation in plain english...at the present time it's the only language i can understand...C is still too obscure!!! :)
#17
Posted 10 September 2007 - 10:57 AM
i'm gonna try that engine right now.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












