So I made a dll that allows threaded lua.
[vid]https://dl.dropboxusercontent.com/u/55492240/2015-05-28-2135-27.webm[/vid]
[code]
if CLIENT then
pi = 0
hook.Add("HUDPaint","pi",function()
draw.RoundedBox( 5, ScrW()/2-256, ScrH()/2-32, 512, 64, Color( 0, 0, 0, 128 ) )
draw.SimpleText(tostring(pi),"CloseCaption_Bold",ScrW()/2-251,ScrH()/2,Color(255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_CENTER)
end)
net.Receive( "pi", function( length, client )
pi = net.ReadFloat()
end)
else
util.AddNetworkString( "pi" )
require("threads")
hook.Add("ThreadMessage", "test", function(id,msg)
if tonumber(msg) then
net.Start("pi")
net.WriteFloat(tonumber(msg))
net.Broadcast()
end
end)
CreateThread([[
pival = 1
isNegative = 1
k = 0
calc = 3
while true do -- Rerun the calculation, adding accuracy each time, for precision # of steps.
pival = pival - (1/calc) * isNegative -- This is the 1 - 1/3 + 1/5 - 1/7...part.
calc = calc + 2 -- This is the 3, 5, 7 part.
isNegative = -isNegative -- This is the + - alternation part.
k = k + 1 -- How many steps it's run
print(pival * 4)
end
]])
end
[/code]
[QUOTE=Mossman1223;47825382][video=youtube;nAqKcoi5-GI]https://www.youtube.com/watch?v=nAqKcoi5-GI[/video]
Barrel with simulated fluid.
It sloshes around in response to acceleration and conserves volume with a reasonable degree of accuracy.
I wasted like 2 days fucking around with matlab code just to get the math right.[/QUOTE]
That looks pretty interesting! Mind if I ask how the simulation works? You can go as maths-heavy as you like, I don't mind if you have to bust out the greek alphabet to explain.
[QUOTE=Elec;47826525]So I made a dll that allows threaded lua.[/QUOTE]
Is the Lua environment for your threads a lua only environment or is it a copy of the gmod environment?
[QUOTE=mcd1992;47826592]Is the Lua environment for your threads a lua only environment or is it a copy of the gmod environment?[/QUOTE]
Currently it's default lua only. Theoretically I could access the engine factory and add everything manually.
Though I'm making this dll for a Computer addon. The speed of the thread can be regulated and the current memory consumption can be calculated by some hacky means, allowing me to add different CPUs and RAMs.
[QUOTE=!cake;47826583]That looks pretty interesting! Mind if I ask how the simulation works? You can go as maths-heavy as you like, I don't mind if you have to bust out the greek alphabet to explain.[/QUOTE]
Basically it calculates the distance (depth) between the lowest level of the container and the level of the liquid, with respect to the "down" direction which is [0,0,-600] + acceleration, normalized.
So getting it to slosh around is pretty easy, I just rotate the plane of the fluid surface to be normal to "down".
Depth is a function of liquid volume, the geometry of the container, and its orientation. For cylindrical vessels (which is all I've written, might do rectangular prisms) the orientation is simply the absolute angle (θ) between the local "up" direction of the cylinder and the global "down" direction.
When θ is 0 or π, calculating depth is of course quite simple as it's V/(π*R^2). When the cylinder isn't vertical, which is most of the time, it turns out that you can't get an exact expression for depth from the volume of a cylindrical wedge or truncated cylinder. The volume of a cylindrical wedge as a function of depth is quite complicated, and finding the inverse of it analytically is actually pretty much impossible. Since I have a function of Volume wrt depth but not its inverse, I can basically just guess at a value of the depth, compute the volume that particular guess would give me, compare that to the volume I actually have and then keep going until it's close enough. I use a bisection algorithm which is incredibly simple but probably kind of slow, it gets to a tolerance of +- 1% in 4-7 iterations. So the fluid level shown is actually incorrect by a margin less than 1%; in the example shown when the barrel is half full the error is about 40 volume units out of some 14,000. If I develop this further and clean up the code some I'll try to improve it.
I should note that the white and purple lines in the video representing the liquid levels are just visual aids, all you need to fully define the level of the liquid is the "down" direction and the depth.
Also, I used information from [URL="http://science.up.ac.za/muti/tank.pdf"]this paper[/URL] as a base for most of the maths. Generalized formulas for volume are given as double integrals, but even for a simple cylinder with flat caps numerical integration techniques are needed since you can't solve them and get an exact expression.
[QUOTE=Elec;47826729]Currently it's default lua only. Theoretically I could access the engine factory and add everything manually.
Though I'm making this dll for a Computer addon. The speed of the thread can be regulated and the current memory consumption can be calculated by some hacky means, allowing me to add different CPUs and RAMs.[/QUOTE]
That's really cool.
[QUOTE=Mossman1223;47825585]thank you, exactly what I needed
[editline]28th May 2015[/editline]
first steps towards a moonbase alpha gamemode
[video=youtube;YbVHSKGvDbY]https://www.youtube.com/watch?v=YbVHSKGvDbY[/video][/QUOTE]
Sadly you're a WAYWO late.
[QUOTE=Mossman1223;47827121]Basically it calculates the distance (depth) between the lowest level of the container and the level of the liquid, with respect to the "down" direction which is [0,0,-600] + acceleration, normalized.
So getting it to slosh around is pretty easy, I just rotate the plane of the fluid surface to be normal to "down".
Depth is a function of liquid volume, the geometry of the container, and its orientation. For cylindrical vessels (which is all I've written, might do rectangular prisms) the orientation is simply the absolute angle (θ) between the local "up" direction of the cylinder and the global "down" direction.
When θ is 0 or π, calculating depth is of course quite simple as it's V/(π*R^2). When the cylinder isn't vertical, which is most of the time, it turns out that you can't get an exact expression for depth from the volume of a cylindrical wedge or truncated cylinder. The volume of a cylindrical wedge as a function of depth is quite complicated, and finding the inverse of it analytically is actually pretty much impossible. Since I have a function of Volume wrt depth but not its inverse, I can basically just guess at a value of the depth, compute the volume that particular guess would give me, compare that to the volume I actually have and then keep going until it's close enough. I use a bisection algorithm which is incredibly simple but probably kind of slow, it gets to a tolerance of +- 1% in 4-7 iterations. So the fluid level shown is actually incorrect by a margin less than 1%; in the example shown when the barrel is half full the error is about 40 volume units out of some 14,000. If I develop this further and clean up the code some I'll try to improve it.
I should note that the white and purple lines in the video representing the liquid levels are just visual aids, all you need to fully define the level of the liquid is the "down" direction and the depth.[/QUOTE]
This is fantastic insight. I also wasn't aware it was so difficult to calculate the other aspects of volume needed for something like this.
[QUOTE=gonzalolog;47826265]Please i need this...Any release date?[/QUOTE]
Feel free to add me if you wanna beta test it. But do post a comment on my profile saying you want to try it.
[QUOTE=Mossman1223;47827121]Basically it calculates the distance (depth) between the lowest level of the container and the level of the liquid, with respect to the "down" direction which is [0,0,-600] + acceleration, normalized.
So getting it to slosh around is pretty easy, I just rotate the plane of the fluid surface to be normal to "down".
Depth is a function of liquid volume, the geometry of the container, and its orientation. For cylindrical vessels (which is all I've written, might do rectangular prisms) the orientation is simply the absolute angle (θ) between the local "up" direction of the cylinder and the global "down" direction.
When θ is 0 or π, calculating depth is of course quite simple as it's V/(π*R^2). When the cylinder isn't vertical, which is most of the time, it turns out that you can't get an exact expression for depth from the volume of a cylindrical wedge or truncated cylinder. The volume of a cylindrical wedge as a function of depth is quite complicated, and finding the inverse of it analytically is actually pretty much impossible. Since I have a function of Volume wrt depth but not its inverse, I can basically just guess at a value of the depth, compute the volume that particular guess would give me, compare that to the volume I actually have and then keep going until it's close enough. I use a bisection algorithm which is incredibly simple but probably kind of slow, it gets to a tolerance of +- 1% in 4-7 iterations. So the fluid level shown is actually incorrect by a margin less than 1%; in the example shown when the barrel is half full the error is about 40 volume units out of some 14,000. If I develop this further and clean up the code some I'll try to improve it.
I should note that the white and purple lines in the video representing the liquid levels are just visual aids, all you need to fully define the level of the liquid is the "down" direction and the depth.
Also, I used information from [URL="http://science.up.ac.za/muti/tank.pdf"]this paper[/URL] as a base for most of the maths. Generalized formulas for volume are given as double integrals, but even for a simple cylinder with flat caps numerical integration techniques are needed since you can't solve them and get an exact expression.
That's really cool.[/QUOTE]
I don't think it's impossible to generate a closed formula for the volume of water in a perfect cylinder knowing trivial information. I will write up a POC tomorrow when I wake up.
[QUOTE=dingusnin;47828237]I don't think it's impossible to generate a closed formula for the volume of water in a perfect cylinder knowing trivial information. I will write up a POC tomorrow when I wake up.[/QUOTE]
Good luck. Based off of [URL="http://science.up.ac.za/muti/tank.pdf"]this paper[/URL] and my own formulations of the problem in Maple/MATLAB, you'd have to use numerical integration just to find the volume. Finding the inverse is worse.
I did try computing the double integral (5) from the paper for a simple cylinder and I got something not very usable.
[QUOTE=Mossman1223;47825532]yeah but I don't really care to spend another week messing around trying to simulate gas physics, compromises are needed
[/QUOTE]
But they aren't separate things, they are both fluid physics (Fluid Dynamics), one's just more viscous than the other.
[editline]e[/editline]
Though you obviously know what you're talking about when it comes to this, not to trivialize the difficulty that would come with adding that feature, just felt I should point out that you may be able to re-use a lot of code.
[QUOTE=man with hat;47821083][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/sound/PlayURL]sound.PlayURL[/url]
Use a text to speech API that allows you to specify text in the URL.[/QUOTE]
Ok. Thank you!
[QUOTE=Mossman1223;47828277]Good luck. Based off of [URL="http://science.up.ac.za/muti/tank.pdf"]this paper[/URL] and my own formulations of the problem in Maple/MATLAB, you'd have to use numerical integration just to find the volume. Finding the inverse is worse.
I did try computing the double integral (5) from the paper for a simple cylinder and I got something not very usable.[/QUOTE]
I don't know if this is 100% applicable, but Wolfram MathWorld has a closed form expression for the volume of a cylindrical wedge: [url]http://mathworld.wolfram.com/CylindricalWedge.html[/url]
(images borrowed from that site)
[img]http://mathworld.wolfram.com/images/eps-gif/CylindricalWedgeSchem_702.gif[/img]
[img]http://mathworld.wolfram.com/images/equations/CylindricalWedge/NumberedEquation2.gif[/img]
or
[img]http://mathworld.wolfram.com/images/equations/CylindricalWedge/Inline31.gif[/img][img]http://mathworld.wolfram.com/images/equations/CylindricalWedge/Inline31.gif[/img][img]http://mathworld.wolfram.com/images/equations/CylindricalWedge/Inline33.gif[/img]
h and φ are both functions of depth (d) and θ, so finding depth given the volume is still no fun.
d = h cos θ
tan θ = h / b
and [img]http://mathworld.wolfram.com/images/equations/CylindricalWedge/Inline10.gif[/img][img]http://mathworld.wolfram.com/images/equations/CylindricalWedge/Inline14.gif[/img][img]http://mathworld.wolfram.com/images/equations/CylindricalWedge/Inline15.gif[/img]
Expressions (7), (8) and (10) let you find φ given a and b.
Volume as a function of depth will still(?) end up being a piecewise monotonic increasing function (number of pieces ranges varies with θ from 1 (perfectly upright or on its side(?)) to 2 (plane of surface is exactly parallel to diagonal) to 3 (deviation from upright or on its side) with no closed form inverse in general. For the 3 piece case with the barrel nearly upright, I think the inverse for the middle piece is closed form.
[QUOTE=!cake;47828994]I don't know if this is 100% applicable, but Wolfram MathWorld has a closed form expression for the volume of a cylindrical wedge: [url]http://mathworld.wolfram.com/CylindricalWedge.html[/url]
<snipped>
[/QUOTE]
Yes, I'm quite aware and did in fact use that very page as a reference. I was specifically referencing the generalized problem of the tilted tank, where that double integral is the volume between the curved surface of the tank (defined as a function of y, where y is the cylindrical axis of the tank) rotated about the y-axis, and the plane of the water's surface, which is inclined at an angle from the y-axis.
This was developed in the context of finding the volume of tanks with more complicated geometries, such as spherical end caps, and even toroidal connecting sections between the spherical and cylindrical sections. I of course have little intention of trying to simulate any of that.
It's probably true that a simpler form exists. In any case I'd still have to approximate the inverse so it wouldn't change much, just maybe make things run a tad faster.
[editline]28th May 2015[/editline]
[QUOTE=TGiFallen;47828671]But they aren't separate things, they are both fluid physics (Fluid Dynamics), one's just more viscous than the other.
[editline]e[/editline]
Though you obviously know what you're talking about when it comes to this, not to trivialize the difficulty that would come with adding that feature, just felt I should point out that you may be able to re-use a lot of code.[/QUOTE]
The only real simulation being done is finding the distance between a flat plane (the fluid surface) and the lowest point of the tank, with respect to an angle, while conserving volume.
What I don't want to start doing is trying to simulate gas pressure and the effect that has on how the fluid enters and exits the tank, air having to bubble in and whatnot.
[QUOTE]one's just more viscous than the other[/QUOTE]
and gases are compressible, while liquids generally aren't.
that adds quite a bit of difference.
It may interest you to know that quite a while ago I tried to simulate stuff like gas pressure and phase changes and mixtures of substances and whatnot, all in little canisters, with lua in gmod. Then I tried getting into stuff like fluid flow physics and heat transfer and chemical reactions, the code got too messy, and I abandoned the project. That's pretty much been the story of all my programming projects. Pretty sure the code is still rattling around somewhere on one of my many harddrives.
[QUOTE=Elec;47826729]Currently it's default lua only. Theoretically I could access the engine factory and add everything manually.
[/QUOTE]
You could do what I did with my JS vm and make it so you can access shit from the main environment via proxy objects. I think wiox was messing around with a similar thing to hide stuff from anticheats.
[QUOTE=Elec;47826729]
Though I'm making this dll for a Computer addon. The speed of the thread can be regulated and the current memory consumption can be calculated by some hacky means, allowing me to add different CPUs and RAMs.[/QUOTE]
I have a similar goal, but I used a much more hacky method (writing my own lua VM in lua). A module would be ideal, but I wanted this thing to work on the client for some reason. Tracking memory usage was one thing I never figured out how to do with my approach, I could have tried to by watching garbage collection but I doubt it would have worked.
Anyhow, I'm interested to see how this turns out.
And now for content! I've been trying to work on Voxelate but I keep getting distracted by the fact that I can destroy the entire map.
[video=youtube;zR7wEwoegVQ]http://www.youtube.com/watch?v=zR7wEwoegVQ[/video]
In all seriousness though, [URL="https://trello.com/b/zrWAQgqX/gm-voxelate"]I've gotten a lot done on it this week[/URL]. Almost ready for the actual release. For real this time.
[img]http://rp.braxnet.org/scr/Gradient_Editor_2015-05-29_09-33-19.png[/img]
dat gradient tho
[QUOTE=Giraffen93;47830202][img]http://rp.braxnet.org/scr/Gradient_Editor_2015-05-29_09-33-19.png[/img]
dat gradient tho[/QUOTE]
yep that's exactly what I used to make it :v: Functionality > Form
While we're all talking about fluid simulation:
[video=youtube;W5g6n9KNM8A]http://www.youtube.com/watch?v=W5g6n9KNM8A[/video]
Back in 2012 I started a gamemode called Zambee Wars, I thought it'd be fun to have another crack at it. The humans have a pretty comprehensive power distribution system for all of their attributes, the zambeez didn't have anything of the sort, I was just doing regular class mechanics. I had an idea that the zambeez could build their own corpse's circulatory system.
This is a day's work on the gui, the red thing in the center is a heart, the blocks around it are veins, and the green thing is a lung. The yellow stuff is toxins, a type of 'hormone', the lung removes toxins at the cost of a loss in 'pressure' within the system.
[IMG]http://images.akamai.steamusercontent.com/ugc/46506032896890585/B058F173FE2E1EA5009EEFDD00605F641FB1BEAC/[/IMG]
Added another particle effect for mortar launch
[video]https://youtu.be/_ckRtm4-aq4[/video]
Anyone have any suggestions as to making the particle effects look better?
[QUOTE=Mossman1223;47833745][video]https://youtu.be/_ckRtm4-aq4[/video]
Anyone have any suggestions as to making the particle effects look better?[/QUOTE]
Increase the amount of particles being emitted while decreasing each particle radius, randomize particle texture from one texture to another same goes for colour and radius, add a bit of refraction and it should look good.
[QUOTE=baldursgate3;47833802]Increase the amount of particles being emitted while decreasing each particle radius, randomize particle texture from one texture to another same goes for colour and radius, add a bit of refraction and it should look good.[/QUOTE]
The problem is, when I use any of the particle/water/watersplash sprites, I get something like this
[IMG]http://puu.sh/i5ax4/13c8ccb61d.jpg[/IMG]
The only one that works is effects/splash1.
[QUOTE=Mossman1223;47833745][video]https://youtu.be/_ckRtm4-aq4[/video]
Anyone have any suggestions as to making the particle effects look better?[/QUOTE]
Are you just getting the hitpos of the barrel and then emitting a particle using the hitnormal?
[QUOTE=Llamalord;47834282]Are you just getting the hitpos of the barrel and then emitting a particle using the hitnormal?[/QUOTE]
Yes, but there isn't an obvious way to actually get the hitnormal from CTakeDamageInfo in an OnTakeDamage hook so I'm actually using the normalized 'GetDamageForce'.
The result is that the particles shoot out at the angle the bullet struck, instead of normal to the prop's surface. I could run a trace from the entity that shot the bullet to get the actual HitNormal, but would that work for non-player entities?
[QUOTE=Mossman1223;47834326]Yes, but there isn't an obvious way to actually get the hitnormal from CTakeDamageInfo in an OnTakeDamage hook so I'm actually using the normalized 'GetDamageForce'.
The result is that the particles shoot out at the angle the bullet struck, instead of normal to the prop's surface. I could run a trace from the entity that shot the bullet to get the actual HitNormal, but would that work for non-player entities?[/QUOTE]
A trace definitely works for non player entities.
[QUOTE=Mossman1223;47833745]https://youtu.be/_ckRtm4-aq4[/video]
Anyone have any suggestions as to making the particle effects look better?[/QUOTE]
Add some length to the particles, mix and match the "long" and square particles, randomize the texture.
[QUOTE=Mossman1223;47834092]The problem is, when I use any of the particle/water/watersplash sprites, I get something like this
[IMG]http://puu.sh/i5ax4/13c8ccb61d.jpg[/IMG]
The only one that works is effects/splash1.[/QUOTE]
Are you rendering it as a trail or a sprite?
Cause it looks like its a trail
[QUOTE=Llamalord;47834636]A trace definitely works for non player entities.[/QUOTE]
I realize that it doesn't really matter where the trace even starts, as long as it hits the right spot on the prop the correct HitNormal will be returned. Do I really need to run a trace just to find the normal on the surface of a prop at a given position? Seems indirect.
[QUOTE=baldursgate3;47834808]Are you rendering it as a trail or a sprite?
Cause it looks like its a trail[/QUOTE]
Sprites. I'm creating a CLuaEmitter and adding particles with Emitter:Add.
[QUOTE=baldursgate3;47833802]Increase the amount of particles being emitted while decreasing each particle radius, randomize particle texture from one texture to another same goes for colour and radius, add a bit of refraction and it should look good.[/QUOTE]
Tried that and it is much nicer.
[IMG]http://puu.sh/i5iYT/fca35b0758.jpg[/IMG]
Sorry, you need to Log In to post a reply to this thread.