Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Strange type-definition problems.

Author
Message
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 11th Oct 2008 19:00
I've been working on a simple 3D physics engine, and have run into a bit of a problem. Variables defined outside of my main loop don't retain their values once the loop starts. However, if defined in the loop, they do.

I'll give the full source if necessary, but here are the relevant parts:

Types:


Code:


And finally, should it be relevant (though I don't believe it is) the gravityEffect() function:


The values should be set correctly, because they're assigned right before the start of the loop. However, all values for weapon_shotgun and player equal zero. If enter is pressed during the loop, the values are properly assigned, and the program can run as expected. Why would it matter if the values are assigned before or during the loop?


My site, for various stuff that I make.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 13th Oct 2008 02:42
omgclassesrgud
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 13th Oct 2008 15:44
I know classes would be better for this, but I hate to abandon something because I couldn't get it to work. I'll switch to classes when I figure out why GDK thinks my floats shouldn't have the values I give them.


My site, for various stuff that I make.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 13th Oct 2008 17:50
Two things:

1) Have you tried disabling optimizations?

2) Why "typedef struct" instead of just "struct"? I thought that was for anonymous structs only?

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 13th Oct 2008 20:43 Edited at: 13th Oct 2008 20:45
The idea with using typedef is that the struct can be called without using struct. It's treated like a regular variable.

In any case, I decided it'd be best to just use a class. What I have so far works pretty much the same as it did before, except that this works correctly.


The major advantage with this is that all the math is done within the class, with one call to the updateStats() function, deprecating the old 'gravityEffect()' function. Looks more neat, too.


My site, for various stuff that I make.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Oct 2008 00:10
Quote: "The idea with using typedef is that the struct can be called without using struct"

That's for C - C++ doesn't need it for that reason. With the way you've formatted your code however, you do need it to create your other types.

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 14th Oct 2008 05:54
If I were you, I'd just forget that stuff and use velocity. And if the displaced object collides with something, bounce back.
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 15th Oct 2008 04:52
All that extra stuff is to make sure the objects move consistently, regardless of framerate, as well as realistically as possible. Right now I'm working on friction against the ground, since it's odd for an object to stop moving the instant it touches the ground. I have it in theory, just need to scale the deceleration of vel.x and vel.z so that the vel.r(x,z) is consistent. I'll post it if I can get it good.


My site, for various stuff that I make.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 15th Oct 2008 05:50
What if it hits a slope?
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 16th Oct 2008 02:49
I'm not dealing with slopes just yet, but I'll have to consider that eventually.


My site, for various stuff that I make.

Login to post a reply

Server time is: 2024-09-30 09:27:33
Your offset time is: 2024-09-30 09:27:33