#9760 posted by metlslime on 2010/04/27 19:40:32
what is the formula to calculate the maximum distance a sound can be heard?
I never figured this out, in the end i just experimented with different distances until i found one that seemed right.
#9761 posted by necros on 2010/04/27 19:51:30
i asked on inside3d, so we'll see. :)
i just experimented with different distances
i would do that if it was only one sound, but i will have multiple sounds at multiple attenuations, and it would be unlikely that i could guesstimate all differences accurately.
Sound Thinking
#9762 posted by Preach on 2010/04/27 22:01:53
We can pick atten to lie between 0 and 4. The engine now defines:
nom_atten = atten / 1000
dist = nom_atten * length(sound.origin - player.origin);
So the crucial thing here is to notice how the attenuation affects the distance.
Attenuation 2 samples are effectively twice as far away as attenuation 1 sounds.
Attenuation 0 sounds are always treated as distance 0 away.
The next thing you need to know is that the volume is multiplied by
( 1 - dist) * rscale in the right ear and (1 - dist) * lscale in the left ear.
rscale is equal to 1 + v_right*normalise(sound.origin - player.origin)
lscale is equal to 1 - v_right*normalise(sound.origin - player.origin)
Don't worry too much about what rscale and lscale mean, just be aware that they are never negative and sum to 2.
We need to compute when both the left and right ear go to zero volume, as in that case the sound is not played.
We know that lscale and rscale are never both equal to 0. So the only case we need to think about is
1 - dist <= 0
this implies that
dist >= 1
so
nom_atten * length(sound.origin - player.origin) >= 1
atten * length(sound.origin - player.origin) >= 1000
It is best to keep the inequality in this form, so that you don't have to worry about dividing by 0 if either the attenuation or the length go to zero.
In real terms, this means a sound with attenuation 1 is audible 1000 units away, attenuation 2 is 500 units away, etc.
You Are A Quake Hero
#9763 posted by necros on 2010/04/27 22:09:55
#9764 posted by Trinca on 2010/04/27 22:38:52
Quake God as Sub-Nigurath
Sounds Like
#9765 posted by Preach on 2010/04/27 23:27:22
If you are going to run this function very frequently, then you might consider it a candidate for optimisation. As it happens, this inequality is ripe for one of my favourite optimisation tricks. It hinges on the idea that calculating the square root of a number is expensive compared to regular operations such as addition and multiplication.
The length of a 3d vector is calculated as
sqrt(x*x + y*y + z*z)
What we notice is that if a and b are > 0 then
a*a >= b*b is equivalent to a >= b
so we can rewrite our inequality from earlier as:
atten * atten * length * length >= 1000*1000
But we have multiplied length by itself, which reverses the sqrt involved in the calculation of length, and takes us back to the value before that step.
So we can replace that with
atten * atten * (x*x + y*y + z*z) >= 1000000
If we were writing this straight in C, there would be no doubt that this method is faster, it replaces one call to sqrt with a single multiplication. In QC, it's a bit harder to decide if it's beneficial, because vlen would have done the multiplication in the brackets for us, which is a little cheaper than doing it ourselves in QC.
In effect, we have replaced the function call to the builtin vlen with four multiplcations and two additions. It's worth noting that a function call has quite a bit of overhead too, so it's likely that we're a way ahead in doing this. If I'm really honest, this is more of an "inner loop in critical c++ rendering code" optimisation, but it's cute to look at.
Thanks Again
#9766 posted by necros on 2010/04/27 23:48:24
very simple when it's all laid out like that, and a nice trick for optimizing vlen calculations. ^_^
(as it turns out, i have other parts in my mod that require frequent vlen calls as well)
Just Replied On I3D But Hey! Here Too...
#9767 posted by mh on 2010/04/28 01:19:28
That value of 1000 *may* have been 1500 in an earlier version of Quake. This is based on a comment I saw in somebody's source maybe 6 years ago; can't remember where or who now.
I've no reason to either doubt or believe it, but I've switched to 1500 myself (in fact I've turned it into a cvar) as I like the extra ambience that it generates in a map.
#9768 posted by necros on 2010/04/28 04:16:00
now that i know a little more about it, i found this line in snd_dma.c for fq085:
vec_t sound_nominal_clip_dist=1000.0;
so it looks like id brought it back down to 1000 unless metl did that, but there's no comment there about it. :)
So
#9769 posted by ijed on 2010/04/28 04:36:57
Iris doors involve maths. Hypotenuese etc.
I got lazy and used a prefab - the lip is difficult to work out.
Your Prefab Madfox, Thanks.
#9770 posted by ijed on 2010/04/28 05:07:49
Ijed:
#9771 posted by metlslime on 2010/04/28 08:45:16
that's the problem, yes.
the alternative is to set the movedir directly in the map file, but that requires a quakec change (since as written, a func_door always calls SetMovedir() which clobbers any movedir you set in the map file.)
They
#9772 posted by ijed on 2010/04/28 13:24:42
Can't be vertical either. I did consider adding a flag to doors, but it seems a bit overkill.
I already have a func_door_model, so maybe that's the cleaner solution.
Iikka's Ikspq3 Iris Doors
#9773 posted by roblot on 2010/04/28 14:27:12
He uses a lip of 49 and -49 equally on the
8 doors. Maybe the bounding box of each of
his doors are the same size to get that lip.
Otherwise its movement seems perfect, without
gaps.
Madfox'
#9774 posted by ijed on 2010/04/28 15:07:39
Example has a total of four different lip values with the opposite pieces moving on the same axis being the same.
None of the values are negative either.
A .mdl solution is a maybe, but not ideal since I'll have to fake the collision. An external bsp could either prove impossible or the solution to everything...
#9775 posted by roblot on 2010/04/28 17:21:20
Yea, it's just those 4 doors that move at 45 degree angles that have a lip thats hard to get right. Maybe Iikka's brush model at the corners (45 degree) have multiple brushes to change its bounding box, thus making it easier to figuring out the lip.
Ijed:
#9776 posted by metlslime on 2010/04/28 21:02:40
if you modify the qc to set the movedir yourself, you can make vertical iris doors too.
Good Point
#9777 posted by ijed on 2010/04/28 22:42:15
And I do have a place for a vertical one that would be very cool since the player is thrown through it as it opens by a trigger_push into a large section of pipe beyond.
Will have to think about this.
Like A Diafragma...
#9778 posted by madfox on 2010/04/29 01:07:04
The prefab of the irisdoor was a rather strange collector item as I couldn't find it in the Qoole prefab directory.
I saw it once in 2004, when the Qoole side still excisted. I couldn't find it as it was in qml format. When I finally found it I realized all the lip sizes were in it, and I even understood less from what I saw.
Glad I could find it in my dusty archive.
I tried a vertical irisdoor with func_trains,
but it really gave me the creep.
Hm
#9779 posted by ijed on 2010/04/29 02:41:58
func_train works in theory. Would be a lot of pissing about on a very small grid though.
Path_Corners
#9780 posted by Mike Woodham on 2010/05/03 18:33:28
I am having trouble with my Ogres.
Going upstairs he is OK but when he returns, he seems to get stuck and twizzles around on one or two of the steps. He looks like he is searching for the way down but never finds it. Other monsters, such as knights and hell knights, are fine and follow the same path_corners without any trouble.
Is this a bounding box issue and do I need to allow more room on one side going in one direction?
For instance, I seem to remember that in the xy view, the lower left hand corner of the path_corner is significant. But could there be relevance to the direction of travel so that I should allow more room on one side in one direction but more room on the other side in the opposite direction?
There is only one monster on this path and no other monsters can cross the path, or otherwise get in the way of the ogre.
#9781 posted by JneeraZ on 2010/05/03 18:42:40
Well, Hell Knights have the same bounding box as the Ogre so I'm not sure what could be going on...
Well
#9782 posted by ijed on 2010/05/03 18:43:19
id1 Ogres as the same size as a Shambler, so if there's a bottleneck smaller than 64 units they can get stuck.
#9783 posted by gb on 2010/05/03 21:29:19
If you use your own progs, you can simply give ogres the smaller bounding box.
Willem
#9784 posted by Lardarse on 2010/05/03 22:45:09
No they don't. Hell knights use the smaller box, ogres use the larger box.
If the ogre is going up fine, but not down, then you need to raise the ceiling by the height of the step. If it still doesn't work, then keep increasing the ceiling height. But 1 or 1.5 x height of step should be enough.
For gb's suggestion to work, you would need to make them use the smaller box. And yes, they do completely fit inside it.
|