I'm having problems with an n-body simulator. I tried to use the gravitational equation for vectors, however that didn't exactly work, so I split up the forces into their respective X and Y components and used two seperate gravitational equations. The problem is the entire body is exploding rather than coming in. I'm obviously doing something wrong with the gravity, I'm just not sure what it is.
[code]
void forceInit() //Initializes/Updates the forces acting on each particle from the other particles
{
int i, j;
double rx=0, ry=0, r1, r2;
for(i=0;i<N;i++) //N is the number of particles
{
for(j=0;j<N;j++)
{
if(j==i) continue; //so we don't check the particle against itself
rx += pow(part[0][j] - part[0][i], 2);
ry += pow(part[1][j] - part[1][i], 2);
}
r1 = pow(rx, -1); //converts to 1/r since all particle masses are =1
r2 = pow(ry, -1);
part[2][i]=G*r1; //G is gravitational constant
part[3][i]=G*r2;
rx = 0;
ry = 0;
}
}
void forceNext() //Converts the force into the next location for the particle
{
int i;
forceInit();
for(i=0;i<N;i++)
{
part[4][i] += part[2][i] * T; //T is the change in time
part[5][i] += part[3][i] * T;
part[0][i] += part[4][i] * T;
part[1][i] += part[5][i] * T;
}
}
/*part[x][y] is an array listing all the particle's properties
x is the property type and y is the particle number
property types:
0 - X coordinate
1 - Y coordinate
2 - X force
3 - Y force
4 - X Velocity
5 - Y Velocity
6 - Theta (used for initial velocity and position)
*/
[/code]
I can answer any questions about the code or show more parts if needed.
Gah, I'm stuck in dll hell.
Could someone who can actually compile a dll help me with [b][url=http://luaforge.net/projects/pluto/]pluto[/url][/b], a library for persisting lua?
I think I might be able to get around using it with a pure lua library I wrote that uses setfenv and getfenv, but I'm not sure yet.
Trying to make a glow effect in xna but it doesn't show the glow or any change at all :
[code]
GraphicsDevice.Clear(Color.Black);
GraphicsDevice.SetRenderTarget(bulletRenderTarget);
spriteBatch.Begin();
foreach (Bullet bullet in bulletList)
{
Texture2D bulletTexture = textures[bullet.bulletType];
spriteBatch.Draw(
bulletTexture,
new Rectangle(
(int)bullet.position.X,
(int)bullet.position.Y,
bulletTexture.Width,
bulletTexture.Height
),
null,
Color.White,
MathHelper.ToRadians(bullet.angle),
new Vector2(
bulletTexture.Width / 2,
bulletTexture.Height / 2
),
SpriteEffects.None,
0
);
}
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Black);
postProcessEffect.CurrentTechnique = postProcessEffect.Techniques["Blur"];
spriteBatch.Begin();
spriteBatch.Draw(
bulletRenderTarget,
new Vector2(0, 0),
Color.White
);
GraphicsDevice.BlendState = BlendState.Additive;
foreach (EffectPass pass in postProcessEffect.CurrentTechnique.Passes)
{
pass.Apply();
spriteBatch.Draw(
bulletRenderTarget,
new Vector2(0,0),
Color.White
);
}
DrawHud();
foreach (BaseEntity entity in entityList)
{
entity.Draw(gameTime);
}
spriteBatch.End();
[/code]
shader :
[code]
float BlurDistance = 0.002f;
sampler ColorMapSampler : register(s1);
float4 PixelShaderFunction(float2 Tex: TEXCOORD0) : COLOR
{
float4 Color;
// Get the texel from ColorMapSampler using a modified texture coordinate. This
// gets the texels at the neighbour texels and adds it to Color.
Color = tex2D( ColorMapSampler, float2(Tex.x+BlurDistance, Tex.y+BlurDistance));
Color += tex2D( ColorMapSampler, float2(Tex.x-BlurDistance, Tex.y-BlurDistance));
Color += tex2D( ColorMapSampler, float2(Tex.x+BlurDistance, Tex.y-BlurDistance));
Color += tex2D( ColorMapSampler, float2(Tex.x-BlurDistance, Tex.y+BlurDistance));
// We need to devide the color with the amount of times we added
// a color to it, in this case 4, to get the avg. color
Color = Color / 4;
// returned the blurred color
return Color;
}
technique Blur
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
[/code]
[QUOTE=ZenX2;26559046]Gah, I'm stuck in dll hell.
Could someone who can actually compile a dll help me with [b][url=http://luaforge.net/projects/pluto/]pluto[/url][/b], a library for persisting lua?
I think I might be able to get around using it with a pure lua library I wrote that uses setfenv and getfenv, but I'm not sure yet.[/QUOTE]
Pluto 2.4 compiles fine for me on VS08 with lua 5.1.4 libraries. You can't use that makefile on Windows, if you want a dll. Making a blank c project in VS and then adding the required libraries(just lua51.lib) worked fine.
[url]http://nottarga.com/heart/pluto.dll[/url]
[url]http://nottarga.com/heart/pluto.lib[/url]
your meant to link to the .lib version
[QUOTE=Richy19;26565851]your meant to link to the .lib version[/QUOTE]
Yeah, what richy said.
Also, do you need networking in yours? Only link the ones you need. If it's a network-less, audio-less game then:
sfml-graphics-s-d.lib
sfml-window-s-d.lib
sfml-system-s-d.lib
In that order. I read somewhere that the order matters, for some reason.
Posted in WAYWO but this is more appropriate:
[img]http://gyazo.com/969cb55ac8450a7ca26cd915069099b6.png[/img]
[img]http://gyazo.com/ce1f4f4983a514a1ccfafa2d6a0fafa7.png[/img]
Becomes
[img]http://gyazo.com/dcfadb02c52cfbf6bc0f73693a6ea426.png[/img]
Dead cells don't regrow properly.
[url]http://pastebin.com/dYfS74Nv[/url]
Anyone know why?
Oh. And a better way of waiting for each generation would be appreciated too.
"Build: 1 succeeded"
Problem solved then?
Edit: Oh I see, you're talking about the warnings. They are non-fatal, you can pretty much ignore them. I get those too, not entirely sure what causes it.
[QUOTE=bootv2;26566554]didn't fully read my post? the problem is when the program starts it gives me the following error: unable to start program
Tjhis application has failed to start because the application configuration is incorrect, review the manifest file for possible errors. reinstalling the program may fix the problem. for more details, please see application event log.
and what I'm seeing is the following error: 1>Link:
1> LINK : C:\Users\Tim\Documents\Visual Studio 2010\Projects\sfml\sfml\Debug\sfml.exe not found or not built by the last incremental link; performing full link
1>sfml-system-s-d.lib(Platform.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'sfml-system-s-d.lib(Platform.obj)' or at 'C:\Users\Tim\Documents\Visual Studio 2010\Projects\sfml\sfml\Debug\vc90.pdb'; linking object as if no debug info
1>sfml-system-s-d.lib(Clock.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'sfml-system-s-d.lib(Clock.obj)' or at 'C:\Users\Tim\Documents\Visual Studio 2010\Projects\sfml\sfml\Debug\vc90.pdb'; linking object as if no debug info
1>sfml-system-s-d.lib(Sleep.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'sfml-system-s-d.lib(Sleep.obj)' or at 'C:\Users\Tim\Documents\Visual Studio 2010\Projects\sfml\sfml\Debug\vc90.pdb'; linking object as if no debug info
1> sfml.vcxproj -> C:\Users\Tim\Documents\Visual Studio 2010\Projects\sfml\sfml\Debug\sfml.exe[/QUOTE]
1.) No I didn't see that, and I still can't. Where did you say that?
2.) Those aren't errors, those are warnings. As I said, you can ignore those.
As for the application crashing, what type of project did you create? A win32 console project? Because that's what it should be.
They aren't errors, just warnings.
[editline]8th December 2010[/editline]
Ninja'd.
They aren't causing it to crash.
Read my post, I said I also get those warnings. And I can use SFML just fine.
Zip up your entire solution and send it to me, I'll see if the same happens to me. If you don't want to do that... well, I don't know what the problem is.
Are ou using the right version of SFML for your compiler?
example: you cant use the VS2008 sfml on 2010.
In fact my recommendation is to recompile them completely
What version do you want/ are you using? 1.6 or 2.0?
well the source of the 1.6 can be found in the full sdk download, but im not sure as to how to compile it as it doesnt apear to come with the build folder that contains all the project files.
But if you want to use 2.0 (i have used it in all my projects and it works fine) then download this [url]http://sfml.svn.sourceforge.net/viewvc/sfml/trunk/?view=tar[/url] go into the build folder, vs2008, run the SFML.sln and let the visual studio converter do its thing
The only other thing i could think of is if you used codeblocks instead until someone can say how to do it
I am also using SFML 2.0, and I highly recommend it over the older versions. I haven't actually encountered a single issue with it, and it has some awesome features over 1.6!
Also, I have some SFML2 binaries on my dropbox, compiled with VS2010. You can have them if you want:
[url]http://dl.dropbox.com/u/6661951/Programming/SFML2%20for%20VS2010.zip[/url]
[QUOTE=bootv2;26567656]it worked! thanks to all who bothered to help me![/QUOTE]
Glad to hear it. I look forward to seeing some cool content over in WAYWO from you :smile:
[QUOTE=BlkDucky;26566303]Posted in WAYWO but this is more appropriate:
[img_thumb]http://gyazo.com/969cb55ac8450a7ca26cd915069099b6.png[/img_thumb]
[img_thumb]http://gyazo.com/ce1f4f4983a514a1ccfafa2d6a0fafa7.png[/img_thumb]
Becomes
[img_thumb]http://gyazo.com/dcfadb02c52cfbf6bc0f73693a6ea426.png[/img_thumb]
Dead cells don't regrow properly.
[url]http://pastebin.com/dYfS74Nv[/url]
Anyone know why?
Oh. And a better way of waiting for each generation would be appreciated too.[/QUOTE]
Nobody? :frown:
[QUOTE=BlkDucky;26567723]Nobody? :frown:[/QUOTE]
How is this part supposed to work?
[code] neighbours = 0
if map[y-1] and map[y-1][x-1] and map[y-1][x-1] == 1 then neighbours = neighbours + 1 end
if map[y] and map[y][x-1] and map[y][x-1] == 1 then neighbours = neighbours + 1 end
if map[y+1] and map[y+1][x-1] and map[y+1][x-1] == 1 then neighbours = neighbours + 1 end
if map[y-1] and map[y-1][x] and map[y-1][x] == 1 then neighbours = neighbours + 1 end
if map[y+1] and map[y+1][x] and map[y+1][x] == 1 then neighbours = neighbours + 1 end
if map[y-1] and map[y-1][x+1] and map[y-1][x+1] == 1 then neighbours = neighbours + 1 end
if map[y] and map[y][x+1] and map[y][x+1] == 1 then neighbours = neighbours + 1 end
if map[y+1] and map[y+1][x+1] and map[y+1][x+1] == 1 then neighbours = neighbours + 1 end
[/code]
[editline]8th December 2010[/editline]
Why are the and's there?
[QUOTE=sim642;26567783]How is this part supposed to work?
[code] neighbours = 0
if map[y-1] and map[y-1][x-1] and map[y-1][x-1] == 1 then neighbours = neighbours + 1 end
if map[y] and map[y][x-1] and map[y][x-1] == 1 then neighbours = neighbours + 1 end
if map[y+1] and map[y+1][x-1] and map[y+1][x-1] == 1 then neighbours = neighbours + 1 end
if map[y-1] and map[y-1][x] and map[y-1][x] == 1 then neighbours = neighbours + 1 end
if map[y+1] and map[y+1][x] and map[y+1][x] == 1 then neighbours = neighbours + 1 end
if map[y-1] and map[y-1][x+1] and map[y-1][x+1] == 1 then neighbours = neighbours + 1 end
if map[y] and map[y][x+1] and map[y][x+1] == 1 then neighbours = neighbours + 1 end
if map[y+1] and map[y+1][x+1] and map[y+1][x+1] == 1 then neighbours = neighbours + 1 end
[/code]
[editline]8th December 2010[/editline]
Why are the and's there?[/QUOTE]
[QUOTE=ZenX2;26535244]Figured it out: you were checking if the x existed, and assuming the y existed. This does not work in lua, sadly.
[lua]if map[y-1] ~= nil and map[y-1][x-1] ~= nil and map[y-1][x-1] == 1 then[/lua]
[/quote]
Which can be cut down to that, apparently.
[QUOTE=MakeR;26542187]Nil in Lua evaluates to false:
[lua]if map[y-1] and map[y-1][x-1] and map[y-1][x-1] == 1 then[/lua][/QUOTE]
It checks to see if that cell exists, i.e. not off of the map.
[QUOTE=BlkDucky;26567877]Which can be cut down to that, apparently.
It checks to see if that cell exists, i.e. not off of the map.[/QUOTE]
I suggest to make a separate function to check the status of a cell, which would check if the requested position is off the map or not as well. That way you can make simple checks for each cell without worrying about a cell being off the map.
[QUOTE=bootv2;26567725]it'll be there, I just need to do the tutorial on sfml for a while. I can use the 1.6 tutorial right?[/QUOTE]
Should be fine, yes. If something doesn't work, check the SFML2 documentation at [url]http://www.sfml-dev.org/documentation/2.0/[/url] to find the equivalent function
[QUOTE=BlkDucky;26567723]Nobody? :frown:[/QUOTE]
your rules are wrong. two or three neighbors results in a living cell surviving to the next generation. you have it set so only cells with 3 will survive on.
that would cause exactly the behavior screenshotted.
[lua]
if map[y][x] == 0 then
if neighbours == 3 then
bufferMap[y][x] = 1 -- New life
end
else -- Currently alive
if neighbours == 3 || neighbours == 2 then
bufferMap[y][x] = 1 -- Survives
else
bufferMap[y][x] = 0
end
end[/lua]
[QUOTE=Soda;26568649]your rules are wrong. two or three neighbors results in a living cell surviving to the next generation. you have it set so only cells with 3 will survive on.
that would cause exactly the behavior screenshotted.
[lua]
if map[y][x] == 0 then
if neighbours == 3 then
bufferMap[y][x] = 1 -- New life
end
else -- Currently alive
if neighbours == 3 || neighbours == 2 then
bufferMap[y][x] = 1 -- Survives
else
bufferMap[y][x] = 0
end
end[/lua][/QUOTE]
Right you are. Works perfectly now. Not sure how I missed that. Thanks. :3:
With C# how can i keep track of time?
Like how in XNA you can view how many miliseconds have passed since the last second
If you need it for timing frames or high accuracy in general, try using the Stopwatch class. If not, the drag & drop Timer control is probably adequate.
Its a console project, so i guess im using stopwatch.
Btw what i meant was a Non-XNA equivalent to XNA's GameTime class.
On mono if that matters
[editline]8th December 2010[/editline]
ok so Stopwatch has: stopWatch.Elapsed.Milliseconds
but whats the most accurate way to know when a second has gone past?
[editline]8th December 2010[/editline]
so i have this
[code]using System;
using System.Diagnostics;
using System.Threading;
namespace timeManager
{
partial class MainClass
{
static int minutes = 0;
static int hours = 0;
static int days = 0;
public static void Main (string[] args)
{
Stopwatch stopWatch = new Stopwatch();
Stopwatch.StartNew().Start();
while(true)
{
minutes = stopWatch.Elapsed.Seconds;
Console.Clear();
Console.WriteLine(minutes);
}
}
}
}[/code]
Which should output the number of seconds, but all i get is 0
Try Stopwatch.Start() instead of stopWatch.StartNew().Start().
By the way, I've only used the Timer class - I'm just going by example pages like [url]http://dotnetperls.com/stopwatch[/url]
Ahh the problem was, Stopwatch.StartNew().Start(); is meant to be stopWatch.Start(); but .start wasnt showing becouse i was accessing theclass not the object.
BTW the console isnt clearing
I was thinking of buying [url=http://www.amazon.com/exec/obidos/ASIN/8590379825/lua-home-20]this[/url] book, should I? I have skimmed through the first edition on lua.org and I really like the author.
Yes. I found it extremely helpful, both for programming and as a flat surface for my mouse pad.
Sorry, you need to Log In to post a reply to this thread.