[QUOTE=Juice_Layer;38684594]Okay, back again with another request. I have a text file, "input2.txt".
It looks like this:
[code]
10 20 30 40 50
50 40 30 20 10
[/code]
I have two arrays, I've declared them as "arrA" and "arrB". I need "arrA" to read the first line of values in this text file.
I haven't had any luck using statements such as && != '\n' in the "while" loop. I thought that would solve my issue. However, it just scrambles up the numbers it seems.
I need the program to:
1) Print arrA (which I have done successfully)
2) Print arrB (which I hope to accomplish)
3) Tell the user whether they are in perfect order (10::10, 20::20), reversed order (10::50)(20::40), or out of order.
Here is what I have so far.
[code]#include <stdio.h>
#define MAX_SIZE 100
int main (void)
{
FILE* spInput = fopen("input2.txt","r");
int in = 0;
int arrA[MAX_SIZE];
int arrB[MAX_SIZE];
int count = 0;
while(fscanf(spInput, "%d", &in) != EOF)
{
arrA[count] = in;
count++;
}
int index;
printf("Original set:\n");
for(index = 0; index < count; index++)
printf("%d\t",arrA[index]);
return 0;
}
[/code][/QUOTE]
Please, god. I have to turn this in tomorrow and I need help. I need arrA to read line 1, and arrB to read line 2. I think I can handle the rest once that's done.
[QUOTE=Staneh;38700826]What would be the best way to make a "particle" game? The only way I can think of is to make every particle an entity and then run collision for every pixel, but I don't think that'll be efficient. If you don't know what I'm talking about, an example pic:
[img]http://www.best1000games.com/wp-content/uploads/2012/10/powder-game-1.jpg[/img][/QUOTE]
Make a bitmap where each pixel is assigned to one of the elements in your game. To do the physics, loop over the pixels of the bitmap and swap them around based on whatever rules you want for that element. For example, a VERY simple 'sand' particle might check if the space below it is 'empty', and if it is then swap it (so it moves down).
It's by no means the fastest way of doing it, but it is definitely the easiest.
Alright, thanks for the information guys, I'll start working on it now then!
[QUOTE=Staneh;38702585]Alright, thanks for the information guys, I'll start working on it now then![/QUOTE]
Feel free to add me on steam if you need anything, I really enjoy making those things!
Need help with opengl drawing faces (quads)!
Here is a pic:
[IMG]http://i.imgur.com/hYqze.png[/IMG]
You can see 4 seperate quads.
They all have the same Color values for the vertices ( 3 dark, and the vertex towards the center of the 4 quads is white)
Now my problem is that the top-right and bottom-left vertex have a wrong color blending.
I want them to have the same color blending like the topleft and bottomright quad.
I know that this problem is caused by the way openGL (or the driver, Idk) triangulates the quads.
The only way I'd know to solve this, is to manually rotate the quads 90°, if they have 3 consecutive dark values as vertex-color...
But thats definitly NOT an option for my program.
Is there some other way to solve this?
Some draw-setting? Something like "alternate quad-triangulation order" or something like that ??
[QUOTE=Juice_Layer;38702351]Please, god. I have to turn this in tomorrow and I need help. I need arrA to read line 1, and arrB to read line 2. I think I can handle the rest once that's done.[/QUOTE]
Your code, as it stands, reads every number (on both lines) into arrA. As there is always an even amount of numbers, you can just divide 'count' by two to get the start point for the second array.
So then you can test whether the numbers match up by comparing arrA[i] vs arrA[count/2 + i] where i goes from 0 to count/2-1
You can do pretty much the same thing in reverse to check for the reversed ordering - except you compare arrA[i] vs arrA[count - 1 - i] where i from 0 to count/2-1
If you are [b]required to use both arrays[/b], then you can keep loading everything into arrA like you do. After that, you'll need a second counter variable for arrB. Loop through arrA from [countA/2] to [countA - 1] and copy that value into arrB[countB]. You'll need to change the value of countA, though - otherwise when you go to print out all the elements in the original set you'll print out garbage values which shouldn't be there any more (your set is now smaller)
[QUOTE=mechanarchy;38706187]Your code, as it stands, reads every number (on both lines) into arrA. As there is always an even amount of numbers, you can just divide 'count' by two to get the start point for the second array.
So then you can test whether the numbers match up by comparing arrA[i] vs arrA[count/2 + i] where i goes from 0 to count/2-1
You can do pretty much the same thing in reverse to check for the reversed ordering - except you compare arrA[i] vs arrA[count - 1 - i] where i from 0 to count/2-1
If you are [b]required to use both arrays[/b], then you can keep loading everything into arrA like you do. After that, you'll need a second counter variable for arrB. Loop through arrA from [countA/2] to [countA - 1] and copy that value into arrB[countB]. You'll need to change the value of countA, though - otherwise when you go to print out all the elements in the original set you'll print out garbage values which shouldn't be there any more (your set is now smaller)[/QUOTE]
Could you actually write that in code for me? I'd greatly appreciate it. Is "i" supposed to be my index value? I already have an int named "index". I'm just a visual learner, I need to see what's going on to be honest because I understand about nothing when it comes to syntax.
[QUOTE=Juice_Layer;38706804]Could you actually write that in code for me? I'd greatly appreciate it. Is "i" supposed to be my index value? I already have an int named "index". I'm just a visual learner, I need to see what's going on to be honest because I understand about nothing when it comes to syntax.[/QUOTE]
Just because you waited until the last moment to do your homework doesn't mean people should take pity on you and do it for you.
[QUOTE=Juice_Layer;38706804]Could you actually write that in code for me? I'd greatly appreciate it. Is "i" supposed to be my index value? I already have an int named "index". I'm just a visual learner, I need to see what's going on to be honest because I understand about nothing when it comes to syntax.[/QUOTE]
[img]https://dl.dropbox.com/u/6929441/screenshots/fp-juice_layer-01.png[/img]
[QUOTE=Topgamer7;38707254]Just because you waited until the last moment to do your homework doesn't mean people should take pity on you and do it for you.[/QUOTE]
I didn't wait until the last day, it was a lab that was assigned two days ago. This is one of two questions. I managed to solve the other one, but this week is finals week so there are no tutors available on campus. I don't want your pity, I just want some help. I'm terrible at programming and I can't find anything in the book about what I'm trying to do.
[editline]4th December 2012[/editline]
I also appreciate the help, and I see exactly what you're doing, but I don't know how to write that in code. I'll just turn in what I have. Thank you anyhow, and also for going through the trouble of writing it out and making a diagram.
[url=http://pastebin.com/p2iLy8i6]Here is the full solution.[/url]
[h2]Learn from this. Do not submit it verbatim.[/h2]
[QUOTE=mechanarchy;38707463][url=http://pastebin.com/p2iLy8i6]Here is the full solution.[/url]
[h2]Learn from this. Do not submit it verbatim.[/h2][/QUOTE]
Thank you for this. I will look through it, the notes definitely help a lot to see exactly what is going on. I would have never thought to divide the array like that, I also wasn't sure on how to store info from one array into another as you did with A and B. Thank you for your help.
Sloved.
-disregard, chrome extensions suck major wang-
snip
So i'm trying to choose a graphics library, and I just want some suggestions.
I was thinking that a OpenGL library would work, but I don't know which is better; SharpGL or OpenTK?
Or, instead, you could recommend me something completely different.
[QUOTE=Killowatt;38722205]So i'm trying to choose a graphics library, and I just want some suggestions.
I was thinking that a OpenGL library would work, but I don't know which is better; SharpGL or OpenTK?
Or, instead, you could recommend me something completely different.[/QUOTE]
I assume this is C#? OpenTK is pretty neat, although I can't compare it to SharpGL as I've never used that.
[QUOTE=Killowatt;38722205]So i'm trying to choose a graphics library, and I just want some suggestions.
I was thinking that a OpenGL library would work, but I don't know which is better; SharpGL or OpenTK?
Or, instead, you could recommend me something completely different.[/QUOTE]
The XNA graphics library is pretty neat if you ask me. It's just a pain in the ass to get all your sprites etc loaded in.
How would I represent -256 in 9-Bit sign and magnitude?
So, I have run into a problem when trying to set up an interface for more easily registering functions to a script engine. Most likely because I'm using heavily templated code.
Here's a snippet that should (not) work:
[cpp]
template<typename O>
struct Object
{
std::string objectName;
Object(std::string name): objectName(name);
template<typename F>
void RegisterFunction(F f, const std::string& name);
};
// Called later on like this:
Object<Vector2<float> > Vec2 = Engine.RegisterObject(Vector2<float>, "Vec2");
Vec2.RegisterFunction(Math::Distance<float>, "Distance"); // error C2914: 'Object<O>::RegisterFunction' : cannot deduce template argument as function argument is ambiguous
[/cpp]
How would I go about solving this that doesn't involve rewriting all of the templated functions?
If you define the first bit as 0 = positive and 1 = negative it would be:
1100000000
So you can see it's not possible to represent it with just 9 bits.
With 8-bit numbers (the (unsigned)byte datatype) you can define numbers from 0-255 including.
256 would be 255 + 1 => which would be 0 again since there is not enough space.
You could also use the "normal" byte (which is of course also 8bit) which uses the first bit as part of the number and not as the sign.
Then you can represent numbers from -128 to 127.
tldr: you need 10bits to represent -256.
[editline]6th December 2012[/editline]
[QUOTE=jaooe;38725926]How would I represent -256 in 9-Bit sign and magnitude?[/QUOTE]
Two's complement is the normal way to express signed numbers. Even though the first bit can be taken to be the "sign bit", i.e. it's 1 for every negative number and 0 for every positive number, the notation can't express a negative zero so the range extends one number lower.
With 9 bits, the two's complement value for -256 would be 100000000
[QUOTE=ThePuska;38728294]Two's complement is the normal way to express signed numbers. Even though the first bit can be taken to be the "sign bit", i.e. it's 1 for every negative number and 0 for every positive number, the notation can't express a negative zero so the range extends one number lower.
With 9 bits, the two's complement value for -256 would be 100000000[/QUOTE]
Just for the record, thats correct too. And usually the proper way to do it.
I was refering to the "naive" method of just using signbit + magnitude, since he wanted to do it like this. Even though you loose one number since you now have negative and positive zero.
[editline]6th December 2012[/editline]
By the way I have a question:
In OpenGL I have the functions VertexPointer, ColorPointer, TexCoordPointer and so on.
Assume I have a VBO that contains only vertex-positions. Now I just want to provide [U]one additional byte per vertex[/U] and [U]access them in the vertexshader[/U]. How would I do that? I cannot use texcoord since the smallest texcoord size is 2bytes and I also might want to use texcoords later on.
I need a function like VertexPointer but not for vertex-positions but for bytes. Something like MyArbitraryPointer(...);
Ahh, yeah, cheers.
I'm not trying to do anything with it mind, our lecturer has set us an assessment and the first questions were to convert a couple decimals to binary in the forms of sign and magnitude, twos comp and excess 256. Had a feeling the last one would be a trick.
Cheers for the input though anyway!
Just tried converting 4 3/8 (four and three eighths) to IEEE754 where:
[code]
Numbers are held in 16 bits split from left to right as follows:
1 bit sign flag that should be set for negative numbers and otherwise clear.
7 bit exponent held in Excess 63
8 bit significand, normalised to 1.x with only the fractional part stored – as in IEEE 754
[/code]
and I have 0100000101000110 binary and 4146 HEX.
The last bits should be [url=http://www.wolframalpha.com/input/?i=%284%2B3%2F8%29%2F4+in+binary].00011000[/url]
[QUOTE=ThePuska;38729650]The last bits should be [url=http://www.wolframalpha.com/input/?i=%284%2B3%2F8%29%2F4+in+binary].00011000[/url]
[code]
(4+3/8)/4 in binary
[/code]
[/QUOTE]
Why the /4 ?
Because the significand is normalized between 1 and 2. Divide the (absolute value) number by the greatest power of two smaller or equal to the number to do that.
Can anyone help me real quick? I'm trying to get each digit of an integer, but just can't seem to figure out how.
Example; Consider number 256. I would like to take 2, 5, 6, and add them up.
I'm using Java.
Thanks :)
Look up Integer.toString.
Sorry, you need to Log In to post a reply to this thread.