I have an array of vertices, I'd like to find duplicates remove them and set indices for the vertices. Anyone know of any good resources on this?
[QUOTE=Shadaez;38382391]Does anyone have resources on how to generate perlin noise? I think I get the idea of how it works, but it would be nice to have it more clearly laid out.
[editline]9th November 2012[/editline]
Simplex noise works, too, but I think that Perlin is easier as far as I know.
[editline]9th November 2012[/editline]
Also, I use python but I should be able to understand just about any language as long as it's well commented or clear.[/QUOTE]
[url]http://www.6by9.net/b/2012/02/03/simplex-noise-for-c-and-python[/url]
This is the one I have been playing with.
I have to create a sort method that sorts a queue in my java class. I cannot use peek or use a sort method within the queue class.
I have a queue with something like this:
[10 12] [12 14] [0 6] [3 5]
I need to get it into this:
[0 6] [3 5] [10 12] [12 14]
What would be the best way to do it? I have this:
[QUOTE=QuikKill;38387610]I have to create a sort method that sorts a queue in my java class. I cannot use peek or use a sort method within the queue class.
I have a queue with something like this:
[10 12] [12 14] [0 6] [3 5]
I need to get it into this:
[0 6] [3 5] [10 12] [12 14]
What would be the best way to do it? I have this:[/QUOTE]
[url]http://en.wikipedia.org/wiki/Quicksort[/url]
[QUOTE=Tortex;38358150]This only converts the first value in the array from hex to decimal correctly then it sets the others to the save value as the first, must be missing something obvious but cant figure out what :/
[code]
void ConvertToDecimal(const vector<string> &in, vector<int> &out)
{
stringstream sstrm;
int o;
for(int i = 0; i < in.size(); i++)
{
sstrm << hex << in[i];
sstrm >> o;
out.push_back(o);
}
}
[/code][/QUOTE]
Try sstrm.clear() at the end of every loop.
[QUOTE=farmatyr;38386062]I have an array of vertices, I'd like to find duplicates remove them and set indices for the vertices. Anyone know of any good resources on this?[/QUOTE]
Just create a hashmap, and to assign indices, iterate each unique entry in the hashmap (use some TryAdd method that doesn't create too much useless calculation or throw exceptions when the added entry already exists). The end result should have a complexity close to O(n + k), where n is the amount of vertices and k is the amount of unique vertices. If your hash is good enough. I don't think one can do much better than that.
edit:
Wait that's wrong, what I was thinking of will require iterating the original vertex list twice - so not O(n + k) but rather O(2n) - iterate once to create the hashmap, second time to assign the indices. The indices can be immediately assigned while creating the hashmap.
edit:
Okay it doesn't even require iterating the list twice, you can just assign the index as soon as the vertex is added to the hashmap, or as soon as you've found the existing vertex from the hashmap. That of course requires that when you add a vertex to the hashmap, you assign it an index - and the index will obviously be the current count of unique entries in the hashmap.
I'll stop now. If you're confused, I can explain better later
[QUOTE=quincy18;38339614]I am having a problem with some basic opengl texturing. I am using opentk and winforms.
I will shorten the code a but but basicly this is where my glControl load and draw functions :
[code]
private void glControl_Load(object sender, EventArgs e)
{
m_Loaded = true;
Application.Idle += new EventHandler(Application_Idle);
SetupViewport();
//Init
GL.ClearColor(Color.Black);
GL.Disable(EnableCap.CullFace);
GL.Enable(EnableCap.Texture2D);
//ImageScanner
m_ImageScanner = new ImageScanner(glControl.Width, glControl.Height);
}
void Application_Idle(object sender, EventArgs e)
{
glControl_Paint(null, null);
}
private void glControl_Paint(object sender, PaintEventArgs e)
{
if (!m_Loaded)
return;
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Modelview);
m_ImageScanner.Draw();
glControl.SwapBuffers();
}
[/code]
I set up a basic orthographic viewport for 2d drawing. Image scanner loads and draws a image and is going to do some basic proccessing. To draw the image I made a image class :
[code]
public Image(string a_FilePath)
{
m_PosX = 0;
m_PosY = 0;
LoadImage(a_FilePath);
}
public void LoadImage(string a_Filepath)
{
m_Image = new Bitmap(a_Filepath);
BitmapData bmp_data = m_Image.LockBits(new Rectangle(0, 0, m_Image.Width, m_Image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
m_GLTextureID = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, m_GLTextureID);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);
m_Image.UnlockBits(bmp_data);
}
public void Draw()
{
GL.LoadIdentity();
GL.BindTexture(TextureTarget.Texture2D, m_GLTextureID);
GL.Begin(BeginMode.Quads);
{
GL.TexCoord2(0.0f, 0.0f);
GL.Vertex2(0.0f, 0.0f);
GL.TexCoord2(1.0f, 0.0f);
GL.Vertex2(m_Image.Width, 0.0f);
GL.TexCoord2(1.0f, 1.0f);
GL.Vertex2(m_Image.Width, m_Image.Height);
GL.TexCoord2(0.0f, 1.0f);
GL.Vertex2(0.0, m_Image.Height);
}
GL.End();
}
[/code]
It is drawing but its pure white and not textured with the texture that is loaded. it draws the correct size so I know the image is being loaded.[/QUOTE]
Check if you got any errors by using
[csharp]#if DEBUG
GLError error = glGetError();
if (error != GLError.NO_ERROR)
{
Console.WriteLine("Error {0} occured at {1}", error, "Location");
}
#endif[/csharp]
at the end of the texture creation and at the end of the draw function.
snip
Okay, I am trying to run a program from java. In this case it is the Natural Selection 2 game exe.
Running it normally is fine.
Launching it through the java app makes it crash with errors of not finding files (such as the font and shaders, which do exist).
I have used both Runtime exec and processbuilder to launch it, with the same results.
Is there any way to fix this?
I wanna go about making voxel terrain in XNA but haven't found any satisfactory tutorials as for how to. I've come up with an idea but I dunno if the right way, anyone have input?
1) Create an array with all the blocks in a chunk 32x32x32 or whatever.
2) Loop through each square and decide which sides are facing the air, then add the vertexes on each of those sides for the side.
3) Send it to a vertex buffer.
When a block is broken or placed, go through steps 2 and 3 again.
[QUOTE=chaz13;38388766]I wanna go about making voxel terrain in XNA but haven't found any satisfactory tutorials as for how to. I've come up with an idea but I dunno if the right way, anyone have input?
1) Create an array with all the blocks in a chunk 32x32x32 or whatever.
2) Loop through each square and decide which sides are facing the air, then add the vertexes on each of those sides for the side.
3) Send it to a vertex buffer.
When a block is broken or placed, go through steps 2 and 3 again.[/QUOTE]
When you break a block only loop through neighbouring blocks instead? Would be much faster, right?
[QUOTE=hogofwar;38388762]Okay, I am trying to run a program from java. In this case it is the Natural Selection 2 game exe.
Running it normally is fine.
Launching it through the java app makes it crash with errors of not finding files (such as the font and shaders, which do exist).
I have used both Runtime exec and processbuilder to launch it, with the same results.
Is there any way to fix this?[/QUOTE]
Im guessing when java launches it, it doesnt use the exe's directory and thats why its failing.
for more on the problem check this out [url]http://blog.wolfire.com/2012/05/Game-File-Systems-File-Paths[/url]
As for a solution, I dont know if java allows you to change the current directory or anthing like htat
[editline]10th November 2012[/editline]
try using the processbuilder method and change the working directory to that of natural selection 2 via [URL="http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#directory(java.io.File)"]http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#directory(java.io.File)[/URL]
[QUOTE=hogofwar;38388762]Okay, I am trying to run a program from java. In this case it is the Natural Selection 2 game exe.
Running it normally is fine.
Launching it through the java app makes it crash with errors of not finding files (such as the font and shaders, which do exist).
I have used both Runtime exec and processbuilder to launch it, with the same results.
Is there any way to fix this?[/QUOTE]
What you want to do is to set the working directory for the program to run: [url]http://stackoverflow.com/questions/9954631/executing-exe-file-in-java-in-separate-directory[/url]
Edit: Ninjad
[QUOTE=hogofwar;38388807]When you break a block only loop through neighbouring blocks instead? Would be much faster, right?[/QUOTE]
Yeah good point. Still need to send the whole lot to another vertex buffer though, but that would make it faster.
I just wanna know if this is roughly the correct way to go about doing it.
[QUOTE=Richy19;38388929]Im guessing when java launches it, it doesnt use the exe's directory and thats why its failing.
for more on the problem check this out [url]http://blog.wolfire.com/2012/05/Game-File-Systems-File-Paths[/url]
As for a solution, I dont know if java allows you to change the current directory or anthing like htat
[editline]10th November 2012[/editline]
try using the processbuilder method and change the working directory to that of natural selection 2 via [URL="http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#directory(java.io.File)"]http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#directory(java.io.File)[/URL][/QUOTE]
Thank you both! That works perfectly.
No idea how I didn't see it before.
[editline]10th November 2012[/editline]
[QUOTE=chaz13;38389073]Yeah good point. Still need to send the whole lot to another vertex buffer though, but that would make it faster.
I just wanna know if this is roughly the correct way to go about doing it.[/QUOTE]
Can't think of anything else apart from that.
[QUOTE=ThePuska;38388349]Just create a hashmap, and to assign indices, iterate each unique entry in the hashmap (use some TryAdd method that doesn't create too much useless calculation or throw exceptions when the added entry already exists). The end result should have a complexity close to O(n + k), where n is the amount of vertices and k is the amount of unique vertices. If your hash is good enough. I don't think one can do much better than that.
edit:
Wait that's wrong, what I was thinking of will require iterating the original vertex list twice - so not O(n + k) but rather O(2n) - iterate once to create the hashmap, second time to assign the indices. The indices can be immediately assigned while creating the hashmap.
edit:
Okay it doesn't even require iterating the list twice, you can just assign the index as soon as the vertex is added to the hashmap, or as soon as you've found the existing vertex from the hashmap. That of course requires that when you add a vertex to the hashmap, you assign it an index - and the index will obviously be the current count of unique entries in the hashmap.
I'll stop now. If you're confused, I can explain better later[/QUOTE]
O(n + k) and O(2n) are the same as O(n), and more exactly describing the performance, it would be Θ(n).
-snip-
[QUOTE=ArgvCompany;38392865]O(n + k) and O(2n) are the same as O(n), and more exactly describing the performance, it would be Ω(n).[/QUOTE]
Abusing notation, the intention of O(n+k) is to convey linear dependence on two variables. Though in this case since k is upper-bound by n, O(n) is strictly equivalent to O(n+k). However assuming neither n nor k are constants and are independent, O(n+k) is generally not O(n).
[QUOTE=ThePuska;38393121]Abusing notation, the intention of O(n+k) is to convey linear dependence on two variables. Though in this case since k is upper-bound by n, O(n) is strictly equivalent to O(n+k). However assuming neither n nor k are constants and are independent, O(n+k) is generally not O(n).[/QUOTE]
I'm sorry, I just assumed that k was a constant, my fault.
Hey there.
I'm using C#, and I have this 2 dimensional array:
[CODE]int[,] sAPoints = new int [5,5];[/CODE]
Now, I want to shuffle the array so that if i had:
0 1 1 2 2
3 2 1 0 1
2 1 0 2 3
1 1 1 0 2
2 1 2 0 1
It would have to be shuffled in both directions, x and y.
Possible outcome:
3 0 0 2 1
2 1 1 2 1
0 2 3 1 2
0 1 0 1 2
2 1 1 2 1
How would I do this?
Shuffle each row, then shuffle each column.
[QUOTE=eternalflamez;38393742]Hey there.
I'm using C#, and I have this 2 dimensional array:
[CODE]int[,] sAPoints = new int [5,5];[/CODE]
Now, I want to shuffle the array so that if i had:
0 1 1 2 2
3 2 1 0 1
2 1 0 2 3
1 1 1 0 2
2 1 2 0 1
It would have to be shuffled in both directions, x and y.
Possible outcome:
3 0 0 2 1
2 1 1 2 1
0 2 3 1 2
0 1 0 1 2
2 1 1 2 1
How would I do this?[/QUOTE]
flatten the array, shuffle it with a good shuffle algorithm, unflatten
[editline]11th November 2012[/editline]
dajoh's for some reason doesn't give you all the possible outcomes:
[code]
dajohs_shuffle ---- 16 unique outcomes
[[1, 3], [4, 2]] 6378
[[1, 4], [3, 2]] 6347
[[3, 4], [1, 2]] 6335
[[4, 2], [1, 3]] 6301
[[2, 4], [3, 1]] 6299
[[1, 2], [4, 3]] 6278
[[4, 1], [2, 3]] 6272
[[2, 3], [4, 1]] 6270
[[3, 4], [2, 1]] 6267
[[2, 1], [4, 3]] 6261
[[4, 3], [1, 2]] 6248
[[1, 2], [3, 4]] 6212
[[3, 2], [1, 4]] 6191
[[2, 1], [3, 4]] 6135
[[3, 1], [2, 4]] 6120
[[4, 3], [2, 1]] 6086
my_shuffle ---- 24 unique outcomes
[[4, 1], [2, 3]] 4317
[[1, 2], [3, 4]] 4270
[[2, 3], [4, 1]] 4250
[[3, 4], [1, 2]] 4229
[[4, 3], [1, 2]] 4218
[[3, 1], [4, 2]] 4215
[[3, 1], [2, 4]] 4212
[[3, 4], [2, 1]] 4196
[[1, 3], [4, 2]] 4191
[[1, 4], [2, 3]] 4183
[[2, 4], [1, 3]] 4182
[[3, 2], [1, 4]] 4174
[[1, 3], [2, 4]] 4170
[[2, 4], [3, 1]] 4164
[[2, 1], [3, 4]] 4160
[[4, 2], [1, 3]] 4149
[[2, 1], [4, 3]] 4143
[[4, 2], [3, 1]] 4124
[[1, 4], [3, 2]] 4119
[[4, 3], [2, 1]] 4101
[[3, 2], [4, 1]] 4095
[[2, 3], [1, 4]] 4081
[[1, 2], [4, 3]] 4037
[[4, 1], [3, 2]] 4020
[/code]
[editline]11th November 2012[/editline]
here's how i did that: [url]http://eval.in/2652[/url]
[QUOTE=swift and shift;38394142]stuff[/QUOTE]
I just realized how closely connected this is with Rubik's cube and the fact that you cannot get all permutations of the cube by just rotating faces.
[QUOTE=swift and shift;38394142]flatten the array, shuffle it with a good shuffle algorithm, unflatten
[editline]11th November 2012[/editline]
dajoh's for some reason doesn't give you all the possible outcomes:
[/code] twice
[editline]11th November 2012[/editline]
here's how i did that: [url]http://eval.in/2652[/url][/QUOTE]
I agree on the fact that his option doesn't give all possible outcomes. (For instance if a row contains only 1 1 1 1 1, the row will just move)
I'm already thinking on how to do it your way, halfway there though.
[editline]10th November 2012[/editline]
How about this:
[code]
Random random = new Random();
int[,] sATemp = new int[5, 5];
int[,] usedNumbers = new int[5, 5];
int iTempRowNr = random.Next(0, 5);
int iTempColNr = random.Next(0, 5);
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
{
while(usedNumbers[iTempColNr, iTempRowNr] != 0)
{
iTempRowNr = random.Next(0, 5);
iTempColNr = random.Next(0, 5);
}
usedNumbers[iTempColNr, iTempRowNr] = 1;
sATemp[y, x] = sAPoints[iTempColNr, iTempRowNr];
}
}
sAPoints = sATemp;
[/code]
This seems to work.
Make sure that gives you a good distribution before deciding to use it. Shuffling arrays evenly is a solved problem, you should probably just grab an already proven algorithm: [url]http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle[/url]
[QUOTE=swift and shift;38394142]flatten the array, shuffle it with a good shuffle algorithm, unflatten
[editline]11th November 2012[/editline]
dajoh's for some reason doesn't give you all the possible outcomes:
[code]
dajohs_shuffle ---- 16 unique outcomes
[[1, 3], [4, 2]] 6378
[[1, 4], [3, 2]] 6347
[[3, 4], [1, 2]] 6335
[[4, 2], [1, 3]] 6301
[[2, 4], [3, 1]] 6299
[[1, 2], [4, 3]] 6278
[[4, 1], [2, 3]] 6272
[[2, 3], [4, 1]] 6270
[[3, 4], [2, 1]] 6267
[[2, 1], [4, 3]] 6261
[[4, 3], [1, 2]] 6248
[[1, 2], [3, 4]] 6212
[[3, 2], [1, 4]] 6191
[[2, 1], [3, 4]] 6135
[[3, 1], [2, 4]] 6120
[[4, 3], [2, 1]] 6086[/code]
[editline]11th November 2012[/editline]
here's how i did that: [url]http://eval.in/2652[/url][/QUOTE]
You're right, you can't get all permutations by shuffling just the rows and the columns. But your implementation of it is getting even more results than it should. There are only 4 unique ways to shuffle a 2x2 array with any number of row and column swaps.
[editline]10th November 2012[/editline]
For proof, consider row-swapping as left-multiplication by a matrix P, and column-swapping as right-multiplication by a matrix Q. It just so happens with 2x2 matrices that P=Q=[[0, 1], [1, 0]] and P*P=I, so no matter how you apply them on a matrix M, you can only get 4 different results:
M
P*M
P*M*Q
M*Q
[QUOTE=ThePuska;38394914]You're right, you can't get all permutations by shuffling just the rows and the columns. But your implementation of it is getting even more results than it should. There are only 4 unique ways to shuffle a 2x2 array with any number of row and column swaps.
[editline]10th November 2012[/editline]
For proof, consider row-swapping as left-multiplication by a matrix P, and column-swapping as right-multiplication by a matrix Q. It just so happens with 2x2 matrices that P=Q=[[0, 1], [1, 0]] and P*P=I, so no matter how you apply them on a matrix M, you can only get 4 different results:
M
P*M
P*M*Q
M*Q[/QUOTE]
That might be so, but a 5x5, as shown in my example, does have 25 unique sets. Considering you don't want it to return to the original set, you'll have 24 left.
Using row/column shuffling, a n-by-n array can be shuffled in (n!)^2 ways. Properly shuffling, there should be (n^2)! permutations. The difference is quite big with a 5x5 array
[QUOTE=chaz13;38388766]I wanna go about making voxel terrain in XNA but haven't found any satisfactory tutorials as for how to. I've come up with an idea but I dunno if the right way, anyone have input?
1) Create an array with all the blocks in a chunk 32x32x32 or whatever.
2) Loop through each square and decide which sides are facing the air, then add the vertexes on each of those sides for the side.
3) Send it to a vertex buffer.
When a block is broken or placed, go through steps 2 and 3 again.[/QUOTE]
This is a good starting guide:
[url]https://sites.google.com/site/letsmakeavoxelengine/home[/url]
[QUOTE=ArgvCompany;38393364]I'm sorry, I just assumed that k was a constant, my fault.[/QUOTE]
You're right, k generally is the notation for constant. Should be "n + m" or something if it's two variables.
Sorry, you need to Log In to post a reply to this thread.