• Content count

  • Joined

  • Last visited

Community Reputation

477 Neutral

1 Follower

About Josheir

  • Rank

Personal Information

  • Interests
  1. Speed Division Problem, Help Please.

    Thank you, everyone. Enjoy the holiday season safely! Josheir
  2. Speed Division Problem, Help Please.

    It's been a long time...They're both helpful! Now, I'm understanding that speed is the magnitude of the vector. What I'm not understanding is how dx's and dy's time numerator is working. Thank you, Josheir
  3. void update() { if (thrust) { dx += cos(angle*DEGTORAD)*.02; dy += sin(angle*DEGTORAD)*.02; } else { dx*=0.99; dy*=0.99; } int maxSpeed = 15; float speed = sqrt(dx*dx+dy*dy); if (speed>maxSpeed) { dx *= maxSpeed/speed; dy *= maxSpeed/speed; } x+=dx; y+=dy; . . . } In the above code, why is maxSpeed being divided by the speed variable. I'm stumped. Thank you, Josheir
  4. Code Snippet Help, Please.

    Thank you for the link haegarr, the code is indeed this sort of game. I'm having a fun time with the code being so succinct. I don't know when I'll return to looking at the code, although I will probably have more questions. Sincerely, Josheir
  5. Code Snippet Help, Please.

    This code is from a simple 3D race car game. When the line : if (I == 400)... is altered the value is for changing a single house near the road in the x direction. I was wondering if someone could tell me how this code works. Mostly, what does line do and what on earth is i about? Are these lines of pixels? EDIT : The screen dimensions are : 1024 x 768 and the world is larger, mainly horizontally. std::vector<Line> lines; for(int i=0;i<1600;i++) { Line line; line.z = i*segL; if (i>300 && i<700) line.curve=0.5; if (i>1100) line.curve=-0.7; if (i<300 && i%20==0) {line.spriteX=-2.5; line.sprite=object[5];} if (i%17==0) {line.spriteX=2.0; line.sprite=object[6];} if (i>300 && i%20==0) {line.spriteX=-0.7; line.sprite=object[4];} if (i>800 && i%20==0) {line.spriteX=-1.2; line.sprite=object[1];} if (i==400) {line.spriteX=-1.2; line.sprite=object[7];} if (i>750) line.y = sin(i/30.0)*1500; lines.push_back(line); } Also, if there is anything else interesting I'd like to here it Thanks so much, Josheir P.S. Is this a beginner's question?
  6. C++ 2D Math Problem

    hmm, cmc where did you translate the whole picture so P becomes the origin? Appreciatively, Josheir
  7. C++ 2D Math Problem

    Yes, all that helps; I'm pretty sure I understand it now. I am a bit confused by the diagram though. I'll go over my program again tomorrow but I do understand what you mean. I need to translate this understandable concept into the understandability of the idea for a specific program. Like I said, it's not really a rectangle, it's more complicated. Thanks again, Josheir
  8. C++ 2D Math Problem

    So, is this correct: The first two p's subtract the offset to regard the point not being the origin. Than the computation is done again and p's are added to re translate it back to the origin. The array is four integers held to be a shape of a grid of 8 cells (two columns,) It's not really a rectangle. I was playing around with the values (mirrored or not:) xNew = -y yNew = x and got it working luckily. I find it confusing that the second set of additions uses the first set that subtracts. I think I've got it now but was hoping someone could do a simple explanation if there is anything else to explain! The way that I got it working was I drew a circle with p.y in the center and a.y on the circumference with the difference being what I assumed to be the y. Likewise for the x values. Thank you, Josheir
  9. In the following code: Point p = a[1]; center of rotation for (int i = 0; I<4; i++) { int x = a[i].x - p.x; int y = a[i].y - p.y; a[i].x = y + p.x; a[i].y = - x + p.y; } I am understanding that a 90 degree shift results in a change like: xNew = -y yNew = x Could someone please explain how the two additions and subtractions of the p.x and p.y works? Thank you, Josheir
  10. I just finished studying the tree. I concluded the theory and wrote up all the pseudo-code / charts. I wanted to thank you for your help! As time allows (which it should,) I look forward to a quick study in the sorting/inserting/and deleting of the binary tree and than on to hashes. Once again, thank you : ApochPiQ, and may you all have happy holidays! Happily, Josheir
  11. ApochPiQ, I'm having a lot of trouble with this idea on how to make the whole form elegant. I wrote the code for this problem years ago and it wasn't really graceful. I used a variable to determine the level of the conversation (which conversation was active ) and than a bunch of if-thens with flags to determine what to be printing out. It was longwinded and sometimes waited for a response from keypress for yes/no to determine more flags. There were flags for determining if the space of the character had been left and revisited. A lot of if-thens and flags. For example, do you have the item yet for a different text displayed. Or, if you have visited a certain character before you have visited the current character. The idea was that all the levels were in one huge loop. There was a check for location, and than a lot of if than else to determine the correct text display. There has got to be an easy way is what I was thinking and wanted to rewrite it. So I thought of the tree, but really I don't understand it to well. I'm thinking maybe there is a variable with an if-then for determining if the tree should be traversed compared to a current variable. Thinking about it this would probably be more complicated than what I had. And if I needed to reverse the traverse backwards it could get complicated. I did read a book that had a program of similar complexity (much shorter though) and the book noted the program as being simple. I am looking for a solution that is efficient, really. What do you recommend? Instead of being so long and spread out I want it more functional or something like that. The main problem with the program was the function was very long that contained this. Also, there were so many flags that it got confusing. And It is difficult to debug. And like I said, so many if-thens. Thank you for your time; I am curious about your recommendation, Josheir
  12. That's what I needed, it looked like a tree to me so now I am understanding well. A quick question, is there a method to writing a conversation that is interactive by visiting one of the characters locations as described above but using multi-dimensional arrays? If there is, perhaps another quick explanation / demonstration. Thank You, Josheir
  13. I am writing a text message box tool. The program takes a string and wraps it onto a colored rectangle. I am trying to understand how to program a game later. I need some sort of idea that keeps track of the conversation when there can also be more than two members in the conversation. A member of the conversation is a 2D image of a character at a particular x and y location that displays text depending on if the other interacting characters have been visited. I am running into problems because any member of the conversation can also display a yes or no question. The yes or no question can be answered so it can create two new paths for each character. If there was only one character to use a "yes or no" question than I was thinking a tree would work nicely that would also hold the text for the other character text conversations. However, there are more than one of these and I am trying to keep track of all the interactive conversations. Best Regards; Thank You, Josheir
  14. C++ Recursion Quick Sort

    Thank you ApochPiQ, this is the site I learned from : The second page (when printed) illustrates the stop partition nicely so that it is easy to understand the left value for the right side partition. Have happy holidays; Sincerely, Josheeir
  15. Edit : Maybe this should be in Beginners forum. Sorry if it should be there. Hello everyone, we're getting closer to the holidays. Everyone have a safe happy season. I'm having trouble with a recursion problem for an : Inside the Quick Sort example. At the very least, I am having trouble understanding how the right side of the quick sort is done after doing all the left hand subsections. I understand that the partition function's job is to keep reducing the left-hand subsection. I am not very good at recursion yet and I am also having trouble mostly with the two quicksort calls in the quicksort function. I could really use some help. Thank you, Josheir Here is the code: #include <iostream> void getdata(int[], int); void display(int[], int); void swap(int &, int &); void partition(int[], int&, int&); void quicksort(int[], int, int); //using std; int main() { const int max = 10; int list[max]; getdata(list, max); std::cout << "initial list\n"; display(list, max); quicksort(list, 0, max - 1); std::cout << "sorted list:\n"; display(list, max); while (1); return(0); } void getdata(int a[], int n) { a[0] = 10; a[1] = 9; a[2] = 8; a[3] = 7; a[4] = 6; a[5] = 5; a[6] = 4; a[7] = 3; a[8] = 2; a[9] = 1; } void display(int a[], int n) { for (int i = 0; i < n; i++) std::cout << a[i] << "[" << i << "]\t"; std::cout << std::endl; } void swap(int &a, int &b) { int temp = a; a = b; b = temp; } void quicksort(int a[], int left, int right) { int l = left, r = right; partition(a, l, r); if (left < r) { quicksort(a, left, r); } if (l < right) { quicksort(a, l, right); } } void partition(int a[], int &l, int &r) { int pivot = a[l]; while (r > l) { while (a[l] < pivot)++l; while (pivot < a[r])--r; if (l > r)continue; swap(a[l], a[r]); ++l; --r; } } Thanks again.