The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## C/C++ Coding for my Math homework lol

This is a discussion on C/C++ Coding for my Math homework lol within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Originally Posted by Psilocybeing I've been researching working with physics in the last week or so, in the hopes of ...

 Tweet
1. Originally Posted by Psilocybeing
I've been researching working with physics in the last week or so, in the hopes of making Traveller smoother, aswell as the prospect of creating a multi-player scorched earth game. So many ideas, I just wish I had the time to see them all through.

Once I'm done cutting down server/client code for another project, I'll be sure to write up a quick scorched-earth style engine. One of these days one of my projects will be complete ;)
lol, i know, thats what i keep telling myself. Im bound to finish something eventually right? For simple gravity physics:

Code:
```int y = 272;
int acc = -10;
int gravity = 1;

while( y>272 ) {
acc += gravity;
y += acc;
}```

2. not to mention im in 8th grade doing freshmen math, i think tis pre calc, or something like that, im getting As and stuff, thats how i got my laptop in the first place, and on weekends i code when im bored, still pretty fun tho,
but i dont like people thinking i know certain math, like fanjita over there, frickien genius finding those sys calls! i got a head ache looking at em from a far, im only in 8th grade doing freshmen math

3. lol, is coding the ti-83 that much work.haha. i code all my formula's in b4 every test

4. Originally Posted by xigency
lol, i know, thats what i keep telling myself. Im bound to finish something eventually right? For simple gravity physics:

Code:
```int y = 272;
int acc = -10;
int gravity = 1;

while( y>272 ) {
acc += gravity;
y += acc;
}```
hey thanks, i will see what i cna do with that for my game, i need a gravity function, i also had one i made by my own, it involves counting heres an example:

Code:
```#define var -=

int count = 0;
while(1) {
count++;
if(count > 20) {
objecty var 0.1
}
if(objecty <= 40) {
var = +=;
}
}```
the - and + are switched because the y axis is going down when positive so itll siwtch the gravity from going up, to down if the objecty is greater than or equal to 40. i dunno if itll work, just a tought it would, tell me what you think, will it work or not

5. Originally Posted by SG57
hey thanks, i will see what i cna do with that for my game, i need a gravity function, i also had one i made by my own, it involves counting heres an example:

Code:
```#define var -=

int count = 0;
while(1) {
count++;
if(count > 20) {
objecty var 0.1
}
if(objecty <= 40) {
var = +=;
}
}```
the - and + are switched because the y axis is going down when positive so itll siwtch the gravity from going up, to down if the objecty is greater than or equal to 40. i dunno if itll work, just a tought it would, tell me what you think, will it work or not
Yea thats not gravity as much as something moving downwards. Gravity involves acceleration. And whats the define for? Oh, you think you can assign to a define, i see. That wouldnt work. But how about:
Code:
```int var = 1;
int count = 0;
while(1) {
count++;
if(count > 20) {
objecty += 0.1*var;
}
if(objecty <= 40) {
var = -1;
}
}```
But then again, the gravity code is more realistic and simpler.

6. i can see whrer your going with teh accelaeration having to be there, but i cant find too much, i think i have one, it relates to what you said, its pretty close to what you said heres what i was thinking:
Code:
```
int count = 0;
float accel = 2.0;
float slower = 0.5;
while(1) {
count++;
if(count >= 20) {
blittedobjecty -= accel;
} else if(count  >= 1000) {
blittedobjecty += accel - slower;
}
}```
what do you think?
i dunno if itll work, can you tell me what you think? its a basic gravity thatll eventually go up then slow down then go down, i tink, is that gonna awokr? dont seem like it because i cant seem to get the slowe variable to decrease by 0.5 i think, i dunno i need an example of some usable gravity

7. does any1 know if sin cos tan operations r suppored??

8. Yeah I write codes for my TI-83 before tests. I don't know C otherwise I would have taken the time to type up my own calc program a long time ago.

9. In Math.h they're most certainly support chingwyn, check here if you need more reference -
http://www-ccs.ucsd.edu/c/math.html

10. oo aight thx but i was wondering if they had it in the psp library??

11. chignwyn, hows it coming? with the gravity? i got sound to complie but not play, so im looking into SDL andSDL_Mixer for sound, anyone wanna point me in a diretion to load and play any kind of sound with SDL, SDL_Mixer?

12. yeah its comin aight only difficult part is gettin a stable increase its so im tryin to c if psp has a math class or somethin cuz usin sin is so simple for the bounce u want

13. imlearn about sin and con 3rd quarter, maybe i should touch up on it now on internet, and yes theres a sin tagnet thing in c, its in the math lib, just search thro ur libs directory for math.c/math.h, or just use the windows serch funcion via start search

hope u can get it done soon so i can start getting it ready for sound

14. yup there is and it works good good progress now

15. If you want a standard increase over time, you could grab the time (say, 01:12:10) and then minus that.

So, if gravity is + 9.8 per second, then you go

time = start (1:12:10) - now (1:12:14)
acceleration = 4 * 9.8

Of course, that can get a lot more accurate considering the PSP has an internal clock counting microseconds (I think it's microseconds...)

Doing it that way means that it doesn't rely on the execution time of the functions above it and the CPU speed.

Just a thought...

16. ## completing the square

Get the code to pump out answers for "completing the square" problems and I'd be happy. Ugh College Algebra stinks :)

17. yeah i got it now, everyone thx alot, i got the sin workin now so all i have to do is change certain varibles to change the altitude and period of the function

dbeyer3069---
lol completing the square is acutally extremely ez

18. ok once you get it complied send me what u got chingwyn, ill start getting my scrolling images and backround done, then add collision detection somehow, i cant think of a way to do it with images, i cna do it with the ground easy

Code:
```if(caty >= 272- 36) {
caty = 272 - 36;
}```
that makes a ground barrier 4 pixels up for my cat image which has ate dimensions of 32 x 32 so 4 + 32 = 36, and 272 is the bottom of the screen y axis wise and so 272 - 36 = ground barrier that the cat bounce off of thanks to chingwyns gravity engine ad bounceing mechnism

thanks chingwyns ill add u tpo te credits for major engine coding

19. If you want some simple collision detection SG57, you can set up bounding boxes and bounding circles very easily.

Ie, if you want to get the cat so that it couldn't go out of a box.

if ( (catx-boxX)*(catx-boxX) < r*r && (caty-boxY)*(caty-boxY) < r*r )
cat_in_box = TRUE;
else cat_in_box = FALSE;

And then for a bounding circle -

if ( (catx-sphX)*(catx-sphX) + (caty-sphY)*(caty-sphY) < r*r )
cat_in_circle = TRUE;
else cat_in_circle = FALSE;

You change the boxX/Y or sphX/Y to your image's x and y locations and thus it acts as a bounding object.

Just my 2c

20. Originally Posted by SG57
i can see whrer your going with teh accelaeration having to be there, but i cant find too much, i think i have one, it relates to what you said, its pretty close to what you said heres what i was thinking:
Code:
```
int count = 0;
float accel = 2.0;
float slower = 0.5;
while(1) {
count++;
if(count >= 20) {
blittedobjecty -= accel;
} else if(count  >= 1000) {
blittedobjecty += accel - slower;
}
}```
what do you think?
i dunno if itll work, can you tell me what you think? its a basic gravity thatll eventually go up then slow down then go down, i tink, is that gonna awokr? dont seem like it because i cant seem to get the slowe variable to decrease by 0.5 i think, i dunno i need an example of some usable gravity
Not quite.

Code:
```int y = 272;
int acc = -10;
int gravity = 1;

while(  y < 272  ) {
acc += gravity;
y += acc;
}```
^^ That exactly. You can change the int's to float's if you want. Try that code.

Code:
```int y = 272;
int acc = -10;
int gravity = 1;

while(  y < 272  ) {
acc += gravity;
y += acc;
// Draw some image at x,y
sceWaitVblankStart();
flipScreen();
clearScreen(0);
}```

21. Oh, and on the topic of this thread, I have on occasion used programming for math homework. I remember I had once in 7th grade, one of those problems like:
HAM
+CHEESE
---------
TURKEY

Or something, where all letters are different numbers, and I made a program that cycled through every possibiliy and checked if it worked. And then I found out we had to show work, so I printed out the source and stapled it to the worksheet. It actually took me less time to write the program, like 5 minutes, than to do the problem myself.

22. lol nice i need one of those key generators how do one? i just need a basic foudnation of it, meaning all i avhe to doif i ever get one is put my numbers in the variables and walla, thats called a key generator if i am not mistaken, so what should i do? i cant even begin where to start... how could u find the answer? maybe something like:

Code:
```
int SDL_main() {
int a =3;
int b = 2;
int c = 1;
int d = -1;
int e = -2;
int f = -3;
int g = 4;
int h = -5;
int x;
while(1) {
x + h - a / b * c + d = e + f + g * h - a * x
return x;
}```
wow, that seems like itll work, hmmm im going to try it and see what happens!, maybe set up a proportion adn get an easy answer for my homework question

23. Originally Posted by Smerity
If you want some simple collision detection SG57, you can set up bounding boxes and bounding circles very easily.

Ie, if you want to get the cat so that it couldn't go out of a box.

if ( (catx-boxX)*(catx-boxX) < r*r && (caty-boxY)*(caty-boxY) < r*r )
cat_in_box = TRUE;
else cat_in_box = FALSE;

And then for a bounding circle -

if ( (catx-sphX)*(catx-sphX) + (caty-sphY)*(caty-sphY) < r*r )
cat_in_circle = TRUE;
else cat_in_circle = FALSE;

You change the boxX/Y or sphX/Y to your image's x and y locations and thus it acts as a bounding object.

Just my 2c
ok, so if i had an object that was moving, meaning scrolling by, then hwo would i amek the images x and y co ordinates collistion deteted? an example, my spikes dimensions are x = 65 y = 44 so by what u are saying the code will go like this....
Code:
```
if ( (catx+spikex)*(catx+spikex) < r*r && (caty+spikey)*(caty+spikey) < r*r )
caty = 30 pixels above the spike
}```
thats for having the spike "box" image as a collison barrier basically meaning if the cat hits it, then itll sop at the top of it, i ahd trouble at the end there, so could u fix it up so the cat stops on top of him? i believe i did my math right... the spike dimensions are 65 x 44, so tell me if my math was right

24. Originally Posted by Hardrive
wow, i now like how to make tic tac toe with java (barely)
Everybody has to start somewhere and Tic Tac Toe is a good beginner program. It actually I think was the 2nd project we did in my old highschools grade 11 Info Tech class.

25. Originally Posted by dbeyer3069
Get the code to pump out answers for "completing the square" problems and I'd be happy. Ugh College Algebra stinks :)
I haven't yet read the rest of the thread, but with the program I released on an earlier page you should be able to find the roots, just make sure that you rearrange the problem into the Ax^2 + Bx + C = 0 format then plug in A,B,and C and it will tell you the roots. Also I think it would be possible to write a program that will show step by step what you should write down on your paper for completing the square problems.

SG57, I was in your shoes last year. At the end of the year you'll be getting into the quadratic formula and factoring equations a bit, and next year, you'll be doing a ton of it. Also this year I think you'll be doing Mean, Median, Mode, Range, and quartiles. You should be able to write a program that will do those when you get to that in your class.

26. considering the equation sin(tPI);
my t which is time goes up by .05 every time but i want to do something everytime it hits a whole number
can some1 help me out with this??

27. Originally Posted by soccerPMN
SG57, I was in your shoes last year. At the end of the year you'll be getting into the quadratic formula and factoring equations a bit, and next year, you'll be doing a ton of it. Also this year I think you'll be doing Mean, Median, Mode, Range, and quartiles. You should be able to write a program that will do those when you get to that in your class.
ok, we have done very little mean median mode stuff and i already told u im doing 9th grade math tho im in 8th grade, and if we ever really get into mean median mdoe hing, then i can make a huge input program to input the numbres into variables and then calcualte the total and divide it by how many there are, and return the answer, very easy math when doing it in programming! specially whne on the calculator u accidnetly add an extra 1 on the ened and have to starat over, but i ahve homework for math tonight and its on ratios, odds, and probability, hope C/C++ can do that

28. Originally Posted by SG57
ok, we have done very little mean median mode stuff and i already told u im doing 9th grade math tho im in 8th grade, and if we ever really get into mean median mdoe hing, then i can make a huge input program to input the numbres into variables and then calcualte the total and divide it by how many there are, and return the answer, very easy math when doing it in programming! specially whne on the calculator u accidnetly add an extra 1 on the ened and have to starat over, but i ahve homework for math tonight and its on ratios, odds, and probability, hope C/C++ can do that
Yea i did that stuff in like 7th grade, but im in the highest classes possible.

29. anyone think this will work for recording something s movement and printing it out later?

Code:
```int recorder;
if(objectx++ || +) {
recorder++;
}
printf("You Sent objectx %i feet!", 480 * 3 / recorder);```
would that record objectx's distance going right then print it in feet wise if thr psp screen is 4 inches long x axis

Page 2 of 2 First 1 2

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 09:11 PM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY