• What Do You Need Help With? V6
    7,544 replies, posted
Isn't str store, not load? So, essentially it stores r1 on the stack and then loads in in r0 before calling delay.
I have a problem where when I print a struct in another function in another file, it prints fine, but in my main, it prints out garbage values In my implementation for an ADT (im doing binary search trees by the way) [code] int Minimum (Tree *T, void *I){ if(T->size==0) return 0; T->current=T->root; while(T->current->left) T->current=T->current->left; I=T->current->value; printValue(I); //Prints fine here return 1; } [/code] Main.c [code] void *tempVoid=malloc(sizeof(void *)); Minimum(&tempTree,tempVoid); printValue(tempVoid); //prints garbage [/code] Output: (The Binary Tree) 45 Tom 45 Adam 55 Liz 60 Bob 65 Karen 70 Ann 75 John 80 Pete 85 Mary 90 Dave (Trying to print the minimum) 35 Ashley //print in Minimum function -293750920 //print in main my print function: [code] void printValue(void *value1){ Student *student1 = (Student*)(value1); printf("%d %s\n", GradeOfStudent(*student1), NameOfStudent(*student1)); } [/code] So in the assignment we have to use void pointers etc so that the adt is useable for any data type (in this case it's students with a name and grade)
Hey everyone, I'm working on the C++ project i mentioned before, i and i thought i would ask around and see what you all thought. These are the requirements (I'll put them in a code window so they're separate from the rest): [code] Blood Pressure Category Systolic (mm Hg) Diastolic (mm Hg) Normal less than 120 and less than 80 Prehypertension 120–139 or 80–89 High Stage 1 140–159 or 90–99 Stage 2 160 or higher or 100 or higher [/code] So, i'm going to have 4 potential outcomes it looks like. Either it will be normal, pre-hypertension, or stage 1 or 2 hypertension. So, i'm going to input a patient's data from a .dat file. So, i'll have say "White Aaron 173/80" and i'll go through and pull the last name, the first name, and then the numbers. The only thing that i'm confusing myself over is how to process the numbers. Since i have two different categories of numbers, i'm not sure how i would go about using both categories (systolic, and a diastolic) to process this all. I'm thinking i can have a loop for each (is this possible?) that loops until a number exceeds the minimum for said category (So, for systolic, loop until 120, 140, or 160) then do the same for diastolic. I guess i'm just not sure how i would go about looping the two data types, then saying "Well, they've got 140 for systolic, and 96 for diastolic, so they're clearly in stage 1 hypertension". What do you all think?
[QUOTE=ZeekyHBomb;42959583]Isn't str store, not load? So, essentially it stores r1 on the stack and then loads in in r0 before calling delay.[/QUOTE] You're right; I really do need to get a handle on ASM before I try debugging these things. So it appears r0 has the literal value by the time `delay` gets called in each instance, as it should, but for some reason the delay is different, i.e. the call from start_kernel "works" while the one from the method does not. I'm not sure how else to go about debugging this...
Damnit. That messed up the formatting and i can't seem to edit it. Sorry. [URL=http://s1326.photobucket.com/user/aaronwhite1786/media/class_zpsd8daefd9.jpg.html][IMG]http://i1326.photobucket.com/albums/u654/aaronwhite1786/class_zpsd8daefd9.jpg[/IMG][/URL] There. That's what it should be.
[QUOTE=bull3tmagn3t;42959726]I have a problem where when I print a struct in another function in another file, it prints fine, but in my main, it prints out garbage values In my implementation for an ADT (im doing binary search trees by the way) [code] int Minimum (Tree *T, void *I){ if(T->size==0) return 0; T->current=T->root; while(T->current->left) T->current=T->current->left; I=T->current->value; printValue(I); //Prints fine here return 1; } [/code] Main.c [code] void *tempVoid=malloc(sizeof(void *)); Minimum(&tempTree,tempVoid); printValue(tempVoid); //prints garbage [/code] Output: (The Binary Tree) 45 Tom 45 Adam 55 Liz 60 Bob 65 Karen 70 Ann 75 John 80 Pete 85 Mary 90 Dave (Trying to print the minimum) 35 Ashley //print in Minimum function -293750920 //print in main my print function: [code] void printValue(void *value1){ Student *student1 = (Student*)(value1); printf("%d %s\n", GradeOfStudent(*student1), NameOfStudent(*student1)); } [/code] So in the assignment we have to use void pointers etc so that the adt is useable for any data type (in this case it's students with a name and grade)[/QUOTE] Minimum only modifies I (the pointer itself), but not *I (what the pointer is pointing at). What you want is using an uninitialized (no malloc) void *tempVoid, pass &tempVoid to Minimum, modify Minimum to accept a void** parameter instead just void* and assign value to *I. What happens then is that you pass a pointer to your void* to the Minimum function. Modifying I would again not work right, but instead you dereference the void**, which is the tempVoid pointer, and assign to that. [editline]23rd November 2013[/editline] [QUOTE=Rayjingstorm;42959747]You're right; I really do need to get a handle on ASM before I try debugging these things. So it appears r0 has the literal value by the time `delay` gets called in each instance, as it should, but for some reason the delay is different, i.e. the call from start_kernel "works" while the one from the method does not. I'm not sure how else to go about debugging this...[/QUOTE] Yeah, it [i]seems to[/i] look fine. Fire up gdb on your rPi, step through each instruction and examine the changes made to the register/memory. [editline]23rd November 2013[/editline] [QUOTE=JohnStamosFan;42959742]So, i'm going to have 4 potential outcomes it looks like. Either it will be normal, pre-hypertension, or stage 1 or 2 hypertension. So, i'm going to input a patient's data from a .dat file. So, i'll have say "White Aaron 173/80" and i'll go through and pull the last name, the first name, and then the numbers. The only thing that i'm confusing myself over is how to process the numbers. Since i have two different categories of numbers, i'm not sure how i would go about using both categories (systolic, and a diastolic) to process this all. I'm thinking i can have a loop for each (is this possible?) that loops until a number exceeds the minimum for said category (So, for systolic, loop until 120, 140, or 160) then do the same for diastolic. I guess i'm just not sure how i would go about looping the two data types, then saying "Well, they've got 140 for systolic, and 96 for diastolic, so they're clearly in stage 1 hypertension". What do you all think?[/QUOTE] I'd have a array of some kind storing the blood pressure levels in descending order (high pressure to low). Then go through each level, test if the pressure >= blood pressure of the guy. If yes, he's that category. If no, try the next. When you have no further categories to test just select the lowest pressure (last entry in the array). Strictly speaking, you don't need to test against the last entry. You may decide to omit the level from the array.
[QUOTE=ZeekyHBomb;42959834] I'd have a array of some kind storing the blood pressure levels in descending order (high pressure to low). Then go through each level, test if the pressure >= blood pressure of the guy. If yes, he's that category. If no, try the next. When you have no further categories to test just select the lowest pressure (last entry in the array). Strictly speaking, you don't need to test against the last entry. You may decide to omit the level from the array.[/QUOTE] Hmm, that's a nice idea. We haven't done a ton with arrays yet. I'll have to look into that and see what i can do. I've got until Monday night. So i have some time to figure out how to do this, since it should be pretty straight forward once i just figure out the number mess. With an array, would i need to make one for each type of blood pressure? Like one array to see where he was with systolic, then diastolic, then if he meets both in a category, it says "He's level 2" etc?
You can make separate arrays if you think it's easier for you. I'd recommend having one for the systole, one for the diastole and one for the category-names then. Otherwise you can also have an array of pairs or structs [code]struct BloodPressure { //TODO: cool bunch 'o functions int Systolic, Diastolic; }; //this array contains (min pressure, category name) pairs and is sorted descending by pressure static const std::pair<BloodPressure, std::string> bloodPressureLevels[] = { { BloodPressure(160, 100), "Stage 2" }, { BloodPressure(140, 90), "Stage 1" }, //... };[/code] The example conveniently shows both, struct and pair usage, in one example. [editline]23rd November 2013[/editline] Also note, that the initialization of the pairs for the array are C++11. You might not use a C++11 compiler in your class, so if the compiler complains use [code]std::make_pair(BloodPresure(sys, dia), "name")[/code] instead.
[QUOTE=ZeekyHBomb;42960357]You can make separate arrays if you think it's easier for you. I'd recommend having one for the systole, one for the diastole and one for the category-names then. Otherwise you can also have an array of pairs or structs [code]struct BloodPressure { //TODO: cool bunch 'o functions int Systolic, Diastolic; }; //this array contains (min pressure, category name) pairs and is sorted descending by pressure static const std::pair<BloodPressure, std::string> bloodPressureLevels[] = { { BloodPressure(160, 100), "Stage 2" }, { BloodPressure(140, 90), "Stage 1" }, //... };[/code] The example conveniently shows both, struct and pair usage, in one example. [editline]23rd November 2013[/editline] Also note, that the initialization of the pairs for the array are C++11. You might not use a C++11 compiler in your class, so if the compiler complains use [code]std::make_pair(BloodPresure(sys, dia), "name")[/code] instead.[/QUOTE] Awesome. Thanks for always being super helpful. Some of this stuff doesn't get explained very will in class or the book, so it's a bit of a pain trying to figure out how stuff works. Let setw. This stuff is giving me fits. At first i was thinking setw set the distance from the left, then i thought it set the distance from the right, now after trying it, and reading some, i have no idea how i'm getting stuff to line up. I'll go grab some dinner and come back to see if i can get my head a set width from my anus. Thanks again!
I'm trying to implement the A* path-finding algorithm on an 8 directional grid, but it's not working. My heuristic is the Pythagorean formula for distance. I don't know why it's not working, but here's a section of the code, can anyone see any problems with my implementation? [QUOTE] cell = (clsPoint) toEvaluate.get(0); //current grid cell, represented by a point x = (int) cell.x; y = (int) cell.y; //calcluate a g score double g_score = 0; clsPoint g_cell = cell; for (int s = 0; s < max_eval && g_cell.parent != null;s++) { g_score += Math.abs(g_cell.parent.x - g_cell.x) + Math.abs(g_cell.parent.y - g_cell.y); g_cell = g_cell.parent; //recursively goes through each linked list until the starting node is reached. } //calculate an f score double f_score = g_score + clsMainProgram.program.distanceTo(x, y, goalx, goaly); //distanceTo gives the Pythagorean distance from the first point to the second. double testf = 0; double testg = 0; //check adjacent cells; testg = g_score+Math.sqrt(2); testf = testg + clsMainProgram.program.distanceTo(x-1, y-1, goalx, goaly); //check the up if ( (curlevel.walkable[x-1][y-1] && f_score > testf) ) { filled = false; //unless given otherwise clsPoint newcell = new clsPoint(x-1,y-1,0); newcell.parent = cell; nextEvaluate.add(newcell); }[/QUOTE]
-snip- Just got it all working properly, don't need anymore help
[QUOTE=JohnStamosFan;42961887]Awesome. Thanks for always being super helpful. Some of this stuff doesn't get explained very will in class or the book, so it's a bit of a pain trying to figure out how stuff works. Let setw. This stuff is giving me fits. At first i was thinking setw set the distance from the left, then i thought it set the distance from the right, now after trying it, and reading some, i have no idea how i'm getting stuff to line up. I'll go grab some dinner and come back to see if i can get my head a set width from my anus. Thanks again![/QUOTE] std::setw sets the minimum number of characters to be outputted on one formatted output-operation. So if I do std::setw(3), then write "a", it's going to output " a" (two spaces in front). If I write "ab" it's going to output " ab" (single space in front). If I write "abcdef" it's going to output "abcdef" (no spaces in front). You can control where to fill with std::left and std::right (and std::internal); as you can see it's to the left by default. [url=http://en.cppreference.com/w/cpp/io/manip/left]See cppreference.com[/url]. [QUOTE=Xystus234;42962214]I'm trying to implement the A* path-finding algorithm on an 8 directional grid, but it's not working. My heuristic is the Pythagorean formula for distance. I don't know why it's not working, but here's a section of the code, can anyone see any problems with my implementation?[/QUOTE] You can use [noparse][code]...code...[/code][/noparse]-tags to post code. How much works already and what exactly fails? You only seem to be checking one direction (-1, -1). Did you not post parts of the code? And what's the purpose of calculating g_score? You're adding it to both f_score and testf. And I don't get the purpose of testg, why do you add sqrt(2)? Isn't distanceTo going to do that? When you're done going through a bunch of nodes and checking distances - where do you store the new path? Did you also not post that part?
If I have an object at X1, Y1 and I always want it to look/point in the direction of X2, Y2, What was the formula? Im currently doing: [csharp] Vector3 direction = playerPos - position; direction.Normalize(); amountOfRotation = (float)Math.Acos(Vector3.Dot(Vector3.Backward, direction)); [/csharp] But it doesnt respond to wrapping well. I remember it being cosX - sin X sinY + cosY? But I cant remember the exact thing
If you have situation like this [thumb]http://i.stack.imgur.com/HUKbR.png[/thumb] and want the angle, then you do [code] // delta between the points deltaY = P2_y - P1_y deltaX = P2_x - P1_x // degrees angleInDegrees = arctan(deltaY / deltaX) * 180 / PI // or angleInDegrees = atan2(deltaY, deltaX) * 180 / PI // radians angleInDegrees = arctan(deltaY / deltaX) // or angleInDegrees = atan2(deltaY, deltaX) [/code]
[QUOTE=cartman300;42967055]If you have situation like this [thumb]http://i.stack.imgur.com/HUKbR.png[/thumb] and want the angle, then you do [code] // delta between the points deltaY = P2_y - P1_y deltaX = P2_x - P1_x // degrees angleInDegrees = arctan(deltaY / deltaX) * 180 / PI // or angleInDegrees = atan2(deltaY, deltaX) * 180 / PI // radians angleInDegrees = arctan(deltaY / deltaX) // or angleInDegrees = atan2(deltaY, deltaX) [/code][/QUOTE] At least the arctan with quotient will still give the wrong result half the time, when deltaX is negative probably. IIRC it's offset by 180° or Pi. [editline]24th November 2013[/editline] [QUOTE=Richy19;42966995]If I have an object at X1, Y1 and I always want it to look/point in the direction of X2, Y2, What was the formula? Im currently doing: [csharp] Vector3 direction = playerPos - position; direction.Normalize(); amountOfRotation = (float)Math.Acos(Vector3.Dot(Vector3.Backward, direction)); [/csharp] But it doesnt respond to wrapping well. I remember it being cosX - sin X sinY + cosY? But I cant remember the exact thing[/QUOTE] Do you need the rotation as angle for looking or would a the coefficients (the values in the final transformation matrix) be enough? That's far simpler and faster than using the angle - in fact the normalized direction is already the result, you only need to make a 2x2 matrix from the values (don't remember the exact arrangement) and flip the sign in one cell. [editline]24th November 2013[/editline] I think it's [code]x -y y x[/code]
[QUOTE=Tamschi;42968599] Do you need the rotation as angle for looking or would a the coefficients (the values in the final transformation matrix) be enough? That's far simpler and faster than using the angle - in fact the normalized direction is already the result, you only need to make a 2x2 matrix from the values (don't remember the exact arrangement) and flip the sign in one cell. [editline]24th November 2013[/editline] I think it's [code]x -y y x[/code][/QUOTE] I managed to get it working with: [cpp]amountOfRotation = -(float)(Math.Atan2(target.Z - position.Z, target.X - position.X)); [/cpp]
I need help structuring a proper system to preload game resources in my "res" folder, such as shaders (.glsl files) and textures. I know how to load the files and put them into a string so that they can be compiled into shaders or decoded if they are textures, but how do I store this data? Should I have some sort of list of resources? I want to be able to do something like [CODE] ResourceManager.load("res/shaders/defaultVertex.glsl"); ResourceManager.load("res/shaders/defaultFragment.glsl"); [/CODE] at the start of the program, and then use this to access it: [CODE] ShaderProgram sp = new ShaderProgram(ResourceManager.get("defaultVertex.glsl"), ResourceManager.get("defaultFragment.glsl")); [/CODE] The most performance heavy operation is the loading of the files in general, so I want that to be done at the start of the program.
I have some questions about reading binary data files in C++. Say I want to store map data in a binary file, so I would have 2 shorts that would tell you the width and height, followed by width*height shorts that is the data of the map. Now my issue is that each short in the file would be 16 bits, whereas there is no gurantee that the unsigned shorts will be that wide. They can range between 16 and the size of an int. If I had a vector of shorts, I can't just read straight into it right? How would I solve this problem?
[QUOTE=WTF Nuke;42969883]I have some questions about reading binary data files in C++. Say I want to store map data in a binary file, so I would have 2 shorts that would tell you the width and height, followed by width*height shorts that is the data of the map. Now my issue is that each short in the file would be 16 bits, whereas there is no gurantee that the unsigned shorts will be that wide. They can range between 16 and the size of an int. If I had a vector of shorts, I can't just read straight into it right? How would I solve this problem?[/QUOTE] Have a look at the [url=http://www.cplusplus.com/reference/cstdint/]cstdint[/url] header.
[QUOTE=MakeR;42970148]Have a look at the [url=http://www.cplusplus.com/reference/cstdint/]cstdint[/url] header.[/QUOTE] Thanks, but I have a question. It says "Optional: These typedefs are not defined if no types with such characteristics exist.*" Does that mean if it compiles for me, it will run for anyone?
Hi. I'm doing some Java and would like a little bit of help I have an array of strings and each element is formatted like this String[index] = "blah1, blah2" I'm trying to figure out how I can manipulate the array so I can take strings "String1" and "String2" then make them: String1 = "blah1" String2 = "blah2" I don't want the comma in either of them. I can't figure out how to do this, but I'm sure it's simple
[QUOTE=harryh11;42970609]Hi. I'm doing some Java and would like a little bit of help I have an array of strings and each element is formatted like this String[index] = "blah1, blah2" I'm trying to figure out how I can manipulate the array so I can take strings "String1" and "String2" then make them: String1 = "blah1" String2 = "blah2" I don't want the comma in either of them. I can't figure out how to do this, but I'm sure it's simple[/QUOTE] strings[0] = "blah1"; strings[1] = "blah2";
I might not be explaining myself very well. I have an one-dimensional array of strings called StringArray. String[] = StringArray[10] Every element of StringArray has the format: StringArray[0] = "x0, y0" StringArray[1] = "x1, y1" ... ... StringArray[10] = "x9, y9" StringArray is static and I want to use it in different ways. Sometimes I simply System.out.print(StringArray[a]) But sometimes I want to actually make a new pair of strings, StringA and StringB, so that they are as follows StringA = "xa" StringB = "ya" Where a is whatever index I need it to be at the time. So I've got a load of strings which are 2 words separated by a comma, and I want to pluck the individual words from those strings, and ignore the comma. I hope I am being clear here.
[QUOTE=harryh11;42971176]I might not be explaining myself very well. I have an one-dimensional array of strings called StringArray. String[] = StringArray[10] Every element of StringArray has the format: StringArray[0] = "x0, y0" StringArray[1] = "x1, y1" ... ... StringArray[10] = "x9, y9" StringArray is static and I want to use it in different ways. Sometimes I simply System.out.print(StringArray[a]) But sometimes I want to actually make a new pair of strings, StringA and StringB, so that they are as follows StringA = "xa" StringB = "ya" Where a is whatever index I need it to be at the time. So I've got a load of strings which are 2 words separated by a comma, and I want to pluck the individual words from those strings, and ignore the comma. I hope I am being clear here.[/QUOTE] I would suggest something using substring. [url]http://www.homeandlearn.co.uk/java/substring.html[/url]
I'm trying to create a physics class for a platform game I'm working on. Should I make a physics class or add the physics to my sprite/(player/enemy) class? Also, are there any good tutorials for 2D physics?
What would i need to do to ignore a character in an input line? I've got this: [code] ifstream patient; string firstName, lastName; int systolic; int diastolic; //read file patient >> lastName >> firstName >> systolic >> diastolic; [/code] The problem is, it pulls the last and first names just fine, and the data for systolic, but since the data is written as "White Aaron 140/60" the / stops the read after i pull the systolic data, leaving me without a way to pull the diastolic info out. I'm reading up on the ignore function, but it looks like i'll have to go search the web. Our book seems to devote about 1 paragraph to it.
You can just do a patient.get(char) with some garbage char as the param.
[QUOTE=JohnStamosFan;42973530]What would i need to do to ignore a character in an input line? I've got this: [code] ifstream patient; string firstName, lastName; int systolic; int diastolic; //read file patient >> lastName >> firstName >> systolic >> diastolic; [/code] The problem is, it pulls the last and first names just fine, and the data for systolic, but since the data is written as "White Aaron 140/60" the / stops the read after i pull the systolic data, leaving me without a way to pull the diastolic info out. I'm reading up on the ignore function, but it looks like i'll have to go search the web. Our book seems to devote about 1 paragraph to it.[/QUOTE] In C++11 you could use a regular expression to parse this. Otherwise you could use std::getline with ' ' as separator for the name and with '/' as separator for the pressure. [code]getline(patient, lastName, ' '); getline(patient, firstName, ' '); getline(patient, systolic, '/'); getline(patient, diastolic);[/code]
Awesome. Thanks guys. I emailed my teacher and go "Just do it like the assignment" as the response, so that was a bit less than helpful from his end. I do have an odd error. On the getline command for systolic and diastolic, getline is underlined in red and the error box reads "Error: No instance of overload function "getline" matches the argument list" which seems odd, because the first two for firstname, and lastname don't have an issues. Anyhow, thanks again guys. This class would probably be a bit easier if my teacher wasn't teaching 5 other non-programming classes. He seems a bit overwhelmed. Enjoy the day, everyone.
Oops, yeah, std::getline is defined for std::string (and char*), but it doesn't do integer conversion. You could do that manually, using std::stoi (C++11) or std::istringstream.
Sorry, you need to Log In to post a reply to this thread.