• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=James xX;38316173]In this case it will be, But I could also load a similar thing from a text file, of an unknown length. I wouldn't be asking otherwise.[/QUOTE] To do dynamic arrays (In C): [CPP] typedef list struct { size_t length; size_t capacity; void* data; }; list* create(size_t element_size, size_t length) { list* tmp = malloc(sizeof(list)); tmp->length = length; tmp->capacity = length + 255; tmp->data = malloc(element*length+255); return tmp; } void resize(list* lst, size_t newsize) { tmp->data = realloc(tmp->data,newsize); } void destroy(list* lst) { free(lst->data); } #define store(dest,source) (dest->data = (void*)(source)) #define nth(lst,n,type) (((type*)lst->data)[n]) [/CPP] You'd use them like this: [CPP] list* content = create(sizeof(/*Type of the elements*/),/*Number of elements*/); store(content,/*content from my file*/); nth(content,/*position*/,/*Type of the elements*/); [/CPP]
[QUOTE=AlienCat;38318555]I am not sure how you mean with making an array to a 2D array. You could just do something like this maybe. [cpp] int array2D[columnsize][rowsize]; for(int i = 0; i < columnsize; i++) { for(int j = 0; j < rowsize; j++) { array2D[i][j] = array1d[(i * columnsize) + j]; } } [/cpp] You can also cast the array to an 2D array, but I have no idea how to do that. No, I think you have to do something like this: [cpp] noicedatatype* array; array = noisearray(value, seed1, seed2); dowhateveryouwant(noicedatatype[n]); [/cpp][/QUOTE] This is what I want to do: [quote]Use perlin noise to generate a 2D array of height data (2D array = image). If you looked at this image, it'd be a top-down map of terrain height. Lower values mean low terrain. Higher values mean high terrain. (of course, you could flip this).[/quote] [editline]4th November 2012[/editline] I've figured out how to generate noise, but not the 2d array.
[QUOTE=robmaister12;38316880]IIRC this is an issue that comes up when you reference both OpenTK.dll and OpenTK.Compatibility.dll. Compatibility keeps OpenTK's really old API, where GL was in OpenTK.Graphics (that changed when they added GL|ES bindings and had to split them off to their own namespaces). If you need some specific functionality out of the Compatibility library, just grab it's source from SVN and include it in your project. It's MIT licensed, so it's totally fine to do.[/QUOTE] Im currently using non deprecated OGL2, will removing the compatiblity reference break anything? also what is the 3rd dll about? is it just something the compatibility dll needs?
[QUOTE=Richy19;38320341]Im currently using non deprecated OGL2, will removing the compatiblity reference break anything? also what is the 3rd dll about? is it just something the compatibility dll needs?[/QUOTE] Nope, OpenTK.Compatibility does contain some higher-level functionality like text rendering, but it's limited and restriced to fixed-function OpenGL, so you're probably not using it. All my projects thus far have had no need for the compatibility dll. OpenTK.dll has no dependency on the compatibility dll and vice versa. And which third dll? If you're talking about OpenTK.GLControl, that's to get an OpenGL panel in winforms. IIRC it only depends on OpenTK.dll.
I have to make a program that reads a 5x5 matrix of numbers and outputs the highest number. I figured out most of it, but there are parts i just adapted from lecture slides and i don't quite understand them. [code] segment .data matrix dword 10,10,30,40,30, \ 60,50,40,40,30, \ 40,30,70,70,60, \ 10,10,10,90,10, \ 30,80,20,10,20 segment .bss holder resb 4 count resb 4 segment .text global _start _start: mov eax, matrix call FindGreatest FindGreatest: mov esi, [holder] ; why am i doing these 2 steps? mov edi, [count] ; waaaat mov edi, 0 jmp Switch Comparison: inc edi ; move forward 1 slot in the matrix cmp esi, [eax + edi * 4] ; compare stored number with new number jg Switch ; it's bigger so replace it cmp edi, 25 ; check if we are out of bounds jle Comparison ; start over again if we're good to go mov eax, esi sub eax, '0' ; apparently i'm supposed to do this? idk why jmp Print ; print the value now that we have traversed the matrix Switch: mov esi, [eax + edi * 4] ; we found a higher number, store that shiz jmp Comparison Print: mov edx, 4 mov ecx, esi ; we are outputting the stored digit in esi mov ebx, 1 mov eax, 4 ; output with stdio int 0x80 exit: mov eax, 1 xor ebx, ebx int 0x80[/code]
[QUOTE=AlienCat;38318555]I am not sure how you mean with making an array to a 2D array. You could just do something like this maybe. [cpp] int array2D[columnsize][rowsize]; for(int i = 0; i < columnsize; i++) { for(int j = 0; j < rowsize; j++) { array2D[i][j] = array1d[(i * columnsize) + j]; } } [/cpp] You can also cast the array to an 2D array, but I have no idea how to do that. No, I think you have to do something like this: [cpp] noicedatatype* array; array = noisearray(value, seed1, seed2); dowhateveryouwant(noicedatatype[n]); [/cpp][/QUOTE] What do you mean by noisedatatype*? Because this: [cpp] double* array; int x = 0, y = 0; //start rendering if (d3ddev->BeginScene()) { spriteobj->Begin(D3DXSPRITE_ALPHABLEND); for(int n=0; n<75; n++) { array = noisearray(4, rand() % 100 +1, rand() % 100 + 1); //y = 10*sin(x*3.14159/180) + 715; D3DXVECTOR3 pos(array[n], array[n], 0); spriteobj->Draw(square, NULL, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); //x += 16; } spriteobj->End(); //stop rendering d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); }[/cpp] doesn't work.
[QUOTE=Meatpuppet;38320774]What do you mean by noisedatatype*? Because this: [cpp] double* array; int x = 0, y = 0; //start rendering if (d3ddev->BeginScene()) { spriteobj->Begin(D3DXSPRITE_ALPHABLEND); for(int n=0; n<75; n++) { array = noisearray(4, rand() % 100 +1, rand() % 100 + 1); //y = 10*sin(x*3.14159/180) + 715; D3DXVECTOR3 pos(array[n], array[n], 0); spriteobj->Draw(square, NULL, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); //x += 16; } spriteobj->End(); //stop rendering d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); }[/cpp] doesn't work.[/QUOTE] What he means by noisedatatype* is the type of your array. In your case, this is double*. In order for this to work, your noisearray function must return a double* as well.
[QUOTE=Natrox;38321052]What he means by noisedatatype* is the type of your array. In your case, this is double*. In order for this to work, your noisearray function must return a double* as well.[/QUOTE] It does, though
[QUOTE=Meatpuppet;38321108]It does, though[/QUOTE] You also do this; [cpp]D3DXVECTOR3 pos(array[n], array[n], 0);[/cpp] This will cause incorrect behaviour. You will need to convert array[n] into x and y values. It would be easier if you use a 2D array (double**). Can you show me your noisearray function?
[QUOTE=Natrox;38321141]You also do this; [cpp]D3DXVECTOR3 pos(array[n], array[n], 0);[/cpp] This will cause incorrect behaviour. [B]You will need to convert array[n] into x and y values.[/B] It would be easier if you use a 2D array (double**). Can you show me your noisearray function?[/QUOTE] YES THIS IS EXACTLY WHAT I WANT TO DO. Here is the noise function: [cpp]double* noisearray(int w, double seed1, double seed2) { double* output = (double*)malloc(sizeof(double)*w); for(int i = 0; i<w; i++) { output[i] = noise(seed1 + i, seed2 + i); } return output; } [/cpp] I swear if you show me how to do that I will fucking love you so goddamn much.
[QUOTE=Meatpuppet;38321203]YES THIS IS EXACTLY WHAT I WANT TO DO. Here is the noise function: [cpp]double* noisearray(int w, double seed1, double seed2) { double* output = (double*)malloc(sizeof(double)*w); for(int i = 0; i<w; i++) { output[i] = noise(seed1 + i, seed2 + i); } return output; } [/cpp] I swear if you show me how to do that I will fucking love you so goddamn much.[/QUOTE] Try this; [cpp] double** noisearray(int w, int h, double seed1, double seed2) { double** output = (double**) malloc(w * sizeof(double*)); for (int i = 0; i < w; i++) { output [i] = (double*) malloc(h*sizeof(double)); } for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) { output[x][y] = noise(seed1 + i, seed2 + i); } } return output; } [/cpp] and then maybe; [cpp] double** array; //start rendering if (d3ddev->BeginScene()) { spriteobj->Begin(D3DXSPRITE_ALPHABLEND); array = noisearray(w, h, rand() % 100 +1, rand() % 100 + 1); for(int x=0; x<w; x++) { for(int y=0; y<h; y++) { D3DXVECTOR3 pos(x, y, 0); // Please change D3DCOLOR_XRGB yourself with the value of array[x][y]. spriteobj->Draw(square, NULL, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); } } spriteobj->End(); //stop rendering d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); } [/cpp]
[QUOTE=Natrox;38321373]Try this; [cpp] double** noisearray(int w, int h, double seed1, double seed2) { double** output = (double**) malloc(w * sizeof(double*)); for (int i = 0; i < w; i++) { output [i] = (double*) malloc(h*sizeof(double)); } for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) { output[x][y] = noise(seed1 + i, seed2 + i); } } return output; } [/cpp] and then maybe; [cpp] double** array; //start rendering if (d3ddev->BeginScene()) { spriteobj->Begin(D3DXSPRITE_ALPHABLEND); array = noisearray(w, h, rand() % 100 +1, rand() % 100 + 1); for(int x=0; x<w; x++) { for(int y=0; y<h; y++) { D3DXVECTOR3 pos(x, y, 0); // Please change D3DCOLOR_XRGB yourself with the value of array[x][y]. spriteobj->Draw(square, NULL, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); } } spriteobj->End(); //stop rendering d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); } [/cpp][/QUOTE] How do I put the values of the array as x and y values for drawing?
[QUOTE=Meatpuppet;38321496]How do I put the values of the array as x and y values for drawing?[/QUOTE] Well, assuming they are values ranging from 0-1.0 you could do; [cpp] D3DCOLOR_XRGB(array[x][y]*255, array[x][y]*255, array[x][y]*255) [/cpp]
[QUOTE=Natrox;38321593]Well, assuming they are values ranging from 0-1.0 you could do; D3DCOLOR_XRGB(array[x][y]*255, array[x][y]*255, array[x][y]*255) [/QUOTE] No I mean in the vector position.
[QUOTE=Meatpuppet;38321662]No I mean in the vector position.[/QUOTE] I'm confused now myself. Are you calculating noise values for each x and y? If so, D3DXVECTOR3 pos(x, y, 0); should work. I have to go now.
[QUOTE=Natrox;38321690]I'm confused now myself. Are you calculating noise values for each x and y? If so, D3DXVECTOR3 pos(x, y, 0); should work. I have to go now.[/QUOTE] God damn it. I'll never get this fucking thing to work. This is my code [cpp] double** array; //start rendering if (d3ddev->BeginScene()) { spriteobj->Begin(D3DXSPRITE_ALPHABLEND); array = noisearray(64, 64, rand() % 100 + 1, rand() % 100 + 1); for(int x=0; x<64; x++) { for(int y=0; y<64; y++) { D3DXVECTOR3 pos((array[x][0]), (array[0][y]), 0); // Please change D3DCOLOR_XRGB yourself with the value of array[x][y]. spriteobj->Draw(square, NULL, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); } }[/cpp] And it's just drawing a fidgeting square at the origin. If I provide a scalar to the x and y values, then it diffuses more across the screen, but it flashes. I just want something to fucking work for once.
Use x and y instead of array[x][0] and array[0][y]. Array is filled with random noise values (0 to 1), x and y are positions (0 to size).
[QUOTE=robmaister12;38321857]Use x and y instead of array[x][0] and array[0][y]. Array is filled with random noise values (0 to 1), x and y are positions (0 to size).[/QUOTE] X and Y will just go from 0 to 64...
I'm running my shit through a debugger but it's very cryptic. I fixed a handful of bugs but it still is giving strange results and isn't printing anything at the end. Am i traversing my array properly? I'm doing exactly as my professor said we should... [code] segment .data matrix dd 10,10,10,10,10, \ 20,20,20,20,20, \ 30,30,30,30,30, \ 40,90,40,40,40, \ 50,50,50,50,50 segment .bss holder resb 4 count resb 4 segment .text global _start _start: mov eax, matrix call FindGreatest FindGreatest: mov esi, [holder] ; why am i doing these 2 steps? mov edi, [count] ; waaaat mov edi, 0 jmp Switch Comparison: inc edi ; move forward 1 slot in the matrix cmp esi, [eax + edi * 4] ; compare stored number with new number jg Switch ; it's bigger so replace it cmp edi, 25 ; check if we are out of bounds jle Comparison ; start over again if we're good to go mov eax, esi add eax, '0' ; apparently i'm supposed to do this to make the output correct? jmp Print ; print the value now that we have traversed the matrix Switch: mov esi, [eax + edi * 4] ; we found a higher number jmp Comparison Print: mov edx, 4 mov ecx, esi ; we are outputting the stored digit in esi mov ebx, 1 mov eax, 4 ; output with stdio int 0x80 jmp exit exit: mov eax, 1 xor ebx, ebx int 0x80[/code]
You should be able to access the individual values with [I]x[index][/I] (e.g. [I]x[4][/I] would return [I]0x02[/I]). If you want to preserve the column/row setup you have going on, you can use a multidimensional array: [cpp] const unsigned char x[4][3] = { { 0x00, 0x01, 0x00 }, { 0x01, 0x02, 0x00 }, { 0x03, 0x00, 0x00 }, { 0x0D, 0x00, 0x00 } }; [/cpp] [editline]5th November 2012[/editline] Shit, just realized I answered a 15-hour-old question. Need to refresh this page more often, lol.
[QUOTE=Meatpuppet;38321913]X and Y will just go from 0 to 64...[/QUOTE] They know more about the subject than you and your implementation isn't working. Trust them. [QUOTE=Meatpuppet;38321774]If I provide a scalar to the x and y values, then it diffuses more across the screen, but it flashes.[/QUOTE] Why wouldn't it? You're regenerating it every frame.
[QUOTE=laylay;38316074]Need some math help because I suck at math. I'm working on a rollercoaster simulation, I have a path of points so that means I have the tangents for each point. I'm calculating the binormals and normals as explained here: [url]http://www.cs.cmu.edu/afs/andrew/scs/cs/15-462/web/old/asst2camera.html[/url] The problem with that is the normals start to roll when going up and turning, so when the path comes back down, the normals aren't facing directly up like you'd expect. What I want to do is lock the rolling of the track so for example, if you tried to create a loop, the path would start to twist when getting near to the top so there's never any roll in the track. So I've found a paper that I think solves this but I'm having trouble understanding what they mean at the "roll snap" section. [url]https://dip.felk.cvut.cz/browse/pdfcache/hykovter_2010bach.pdf[/url] It first off starts by saying "Using a dot product, we calculate the angle between the vector pointing straight up ((0, 1, 0)?) and a vector being the up vector that we want to straighten." That itself confuses me because if i dot a normal of (0,1,0) and (0,1,0), that's going to give me a value of 1. That is not an angle i should be applying to the normal because in that situation the normal is correct and doesn't need to be corrected. Tried to explain as best I could. If not, here's an image that explains what I want to happen. [IMG]https://dl.dropbox.com/u/99765/fortblox/r34324.png[/IMG] If I have a track like this that has roll, I want to remove all roll by rotating the normal around the tangent. The reason why I need to do this is so the user can define the roll of each node instead of the track rolling on its own when creating the track.[/QUOTE] You mean you get wrong normals if there's a slope/the track flips over backwards? You have to tilt the up vector by the angle of the tangent against the horizontal plane. This gives you very slight roll in a loop, but only to adjust for the movement into the direction of the binormal of the original track. I don't think it's possible to have a non-intersecting loop without any roll. No idea how to do this with axis-angles, but with quaternions you can apparently use tangent * (inverse of tangent clamped to horizontal plane (normalized)) and apply that to the up vector before doing any other calculations.
[QUOTE=Tamschi;38326900]You mean you get wrong normals if there's a slope/the track flips over backwards? You have to tilt the up vector by the angle of the tangent against the horizontal plane. This gives you very slight roll in a loop, but only to adjust for the movement into the direction of the binormal of the original track. I don't think it's possible to have a non-intersecting loop without any roll. No idea how to do this with axis-angles, but with quaternions you can apparently use tangent * (inverse of tangent clamped to horizontal plane (normalized)) and apply that to the up vector before doing any other calculations.[/QUOTE] I managed to get it to work by rotating the normal around the tangent using the angle of the normal dotted with the tangent crossed with an up vector pointing (0,1,0). It was actually a lucky guess, I'm still not 100% sure why it does what I want it to do. I'll have to come back to it sometime. I've saved your post though to help me understand it.
[QUOTE=laylay;38328219]I managed to get it to work by rotating the normal around the tangent using the angle of the [B]normal dotted with the tangent crossed with an up vector pointing (0,1,0)[/B]. It was actually a lucky guess, I'm still not 100% sure why it does what I want it to do. I'll have to come back to it sometime. I've saved your post though to help me understand it.[/QUOTE] That's the cosine of the angle of the tangent with the up vector. The cross product gives you a vector with the length of the cosine of the angle between two unit vectors, and the normal should point in the same direction as this product in this case, so it measures the length of the vector. You should get the same angle with -arccos(up component of the tangent) or arccos(up component of the tangent) depending on your normal direction and coordinate system.
[QUOTE=Jookia;38324534]They know more about the subject than you and your implementation isn't working. Trust them. Why wouldn't it? You're regenerating it every frame.[/QUOTE] I put 'x' and 'y' in, and it just makes a bigger and bigger square for bigger values. This is what they mean, right? [cpp] double** array; //start rendering if (d3ddev->BeginScene()) { spriteobj->Begin(D3DXSPRITE_ALPHABLEND); array = noisearray(64, 64, rand() % 100 + 1, rand() % 100 + 1); for(int x=0; x<64; x++) { for(int y=0; y<64; y++) { D3DXVECTOR3 pos(x, y, 0); // Please change D3DCOLOR_XRGB yourself with the value of array[x][y]. spriteobj->Draw(square, NULL, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255)); } }[/cpp] [editline]5th November 2012[/editline] And how do I not regen it every frame?
Move the noisearray out of the drawing loop.
[QUOTE=Jookia;38331574]Move the noisearray out of the drawing loop.[/QUOTE] I'm not using anything dealing with the noise array right now. Look at the code, it's just drawing 64 squares. Nevertheless, I did that, and it didn't change anything.
Hey guys, I've been struggling with SQL for a while and cant seem to figure it out, I've got this query to select all orders and their customer information, but I also want to select all orders where the customerid is -1 and let the name and surname be empty strings, can anyone help me how to do this? [code]SELECT orders.id, orders.comments, orders.date, orders.status, orders.customerid, customers.firstname, customers.surname FROM orders INNER JOIN customers ON orders.customerid=customers.id[/code]
[QUOTE=Kialtia;38334649]Hey guys, I've been struggling with SQL for a while and cant seem to figure it out, I've got this query to select all orders and their customer information, but I also want to select all orders where the customerid is -1 [b]and let the name and surname be empty strings[/b], can anyone help me how to do this? [/code][/QUOTE] I'm not sure what you mean by this. Do you mean you want empty values for name and subname, or that you don't want to retrieve these? My first guess on the first part is: [code]SELECT o.id, o.comments, o.date, o.status, o.customerid, c.firstname, c.surname FROM orders AS o INNER JOIN customers AS c ON o.customerid=c.id WHERE o.customerid='-1' [/code] Although this is just basic SQL, which you probably already understood, since you know how to JOIN.
[QUOTE=Kialtia;38334649]Hey guys, I've been struggling with SQL for a while and cant seem to figure it out, I've got this query to select all orders and their customer information, but I also want to select all orders where the customerid is -1 and let the name and surname be empty strings, can anyone help me how to do this? [code]SELECT orders.id, orders.comments, orders.date, orders.status, orders.customerid, customers.firstname, customers.surname FROM orders INNER JOIN customers ON orders.customerid=customers.id[/code][/QUOTE] [code]SELECT orders.id, orders.comments, orders.date, orders.status, orders.customerid, customers.firstname, customers.surname FROM orders INNER JOIN customers ON orders.customerid=customers.id [b]OR orders.customerid = -1[/b][/code] ...?
Sorry, you need to Log In to post a reply to this thread.