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 / problem animating a model and moving at same time

Author
Message
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 19th Mar 2008 22:17
hey

i have a model loded (borrowing it from the samples to practice with) but i am having trouble moving and animating it at the same time!

i either get an animation then it moves while not animating.
or it moves and when i finish it moving it then animates while its still!

any help is apriciated

jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 19th Mar 2008 23:25
Yes, that is a problem. Here are a few things I think you should consider:

1. loop object will restart the animation every time you have the key pressed. You are better off managing the frame number yourself, using time as the input. (That way, its the same on all machines.)

2. Key presses are reported as long as the key is held down. You will get alot of them. You need to handle that. Its called debouncing.

3. Animations represent object states. e.g. walking. There are three stages....transition from an animation, the animation, and transistion out of the animation. (Usually into another animation.)

4. 9000 frames? No, that is too much. DBPro interpolates, 9000 frames is simply ridiculous. The model needs to be exported with keyframes only. That is why your speed needs to be so high...7000? So, its a little over 1 second, and it wants to play at 7000fps? I must be missing something, because in DBPro, speed seems to me to be in frames per second.

Its somewhat more complex than the view your code currently shows, I'm afraid. Now, you know why there are plug-ins dedicated to this programming issue.
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 20th Mar 2008 00:09 Edited at: 20th Mar 2008 00:13
Quote: "1. loop object will restart the animation every time you have the key pressed. You are better off managing the frame number yourself, using time as the input. (That way, its the same on all machines.)

2. Key presses are reported as long as the key is held down. You will get alot of them. You need to handle that. Its called debouncing.
"


Is there any chance you could provide some more detail on these points ? using time as the input...

and with debouncing im presuming you mean somthign along the lines of a boolean where it performs the action only on the first loop
eg


i am using the Miko Model from the samples to play about and get this right , and also i prety much copied those lines from the camera example. (including the 9000 frames bit)

will try and figure out how many frames i need to for the Miko_walk model
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 20th Mar 2008 00:13 Edited at: 20th Mar 2008 00:35
I have a DBPro snippet that I used to figure out DMI animations (Miko is one that I used, too...she's cute.)...just need to sneakerNet it over here...hang on a tic, I put it in this post shortly.

Actually, here is a thread in this forum with the information:
http://forum.thegamecreators.com/?m=forum_view&t=126136&b=22&p=0

wrt debouncing...yes, but with more than a simple boolean. Your snippet is in error, however. You still need to use the '==' operator, and I would !recommend using the not operator, just use 1 for true and 0 for false. In fact, make 1 = true, and everything else is false.

I use what I call a synchronizer (an UDT), which is ran from the QueryPerformanceCounter function in Windows. perftimer() is the DBPro version of that function. I get the period figured out at the top of my code, and multiply the return by the period to get the time elapsed (t_0) since the last frame. That time drives the entire game loop...animations, real-time, all of it.
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 20th Mar 2008 00:49
ok thanks for the info,

(thanks for the info on my code snippet, (i typed it directly in the post just as an example to give you an impression of what i meant))

will give this a try and let you know how i get on,

although i am still confused as to the timer you are referring to. also how do i find out how many frames are in an animation ? (so i know how many to load)
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 20th Mar 2008 01:08 Edited at: 20th Mar 2008 02:17
I know...I thought...its pseudocode, why hassle him about that? Sorry.

You just let append object do it. You can tell which frame to start with by getting total object frames, and adding 1. Look at my DBPro snippet where it calls append object.

The frame extents I had to find out experimentally because I think there are transition frames in there that you would not want to loop in any method. (Using loop, play or set object frame.)

If you load the entire set of animations...there are 135. The list in the other thread is what I use...from experiments like what you are doing now.

The timer is from Windows. Its called a Performance Counter. On most machines (All that I know about, anyway), it runs at 3.58Mhz, an interesting value...the color burst frequency on NTSC televisions, and also the clock speed of my first computer, a Timex-Sinclair 2068!

This timer is provided to you in GDK, I think. Probably named dbPerfTimer(), or something close to that. Otherwise, just use QueryPerformanceCounter. It is in the Windows library, in kernel32.dll, so you should be able to call it from your program with no problems.

EDIT: On second thought, let me be more specific, here.

QueryPerformanceCounter is a function in kernel32.lib, which your program is already linked with. At any rate, it is Windows core code, and there is no need to link to it using dynamic-linkage of any sort, UNLESS you are in DBPro, and that is for entirely different reasons that are on DBPro alone.

So, there are two functions that you should look at using your help system...assuming you are using VC++ Express.
QueryPerformanceCounter and QueryPerformanceFrequency (Not sure about that name, tho.).

Call QueryPerformanceFrequency first...at the beginning of it all, first chance you get, really. Take the reciprocal of that, and store it as a double float named dfPeriod, or whatever strikes you at the moment to name it. Also make a double float called t_0, to store the time elapsed since the last time you checked. While you are creating global variables, take two long integers as well...liCount and liLastCount.

Seed liCount and liLastCount just before you start your game loop using QueryPerformanceCounter.

At the start of your game loop, get liCount using QueryPerformanceCounter.
t_0 = (liCount - liLastCount) * dfPeriod;

Now, all of those calculations that involve delta T work! Also, they work the same on all machines, at all FPS, resolutions, etc.

If you have access to dbPerfTimer, you can just make dfPeriod = 1.0 / 3580000.0

Now, that was off the top of my head, too...so no warranty of any kind is implied.
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 20th Mar 2008 01:31
I attempted to implement the debounce as bellow to no avail, your input is apriciated as to my idiocy



(this is NOT Pseudo so feel free to comment on it )
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 20th Mar 2008 02:11
I do have a few questions, but I think I can help you get this headed to the next issue, at least.



Try that. I'm not sure if I put in the dbObjectPlaying correctly, but I did change some things...I don't actually use GDK right now.
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 20th Mar 2008 02:43
i tried to implement the code provided but it produces the same results. (the model floats forward with no sign of animation )
i also tried adding in the {} on the if statement and it produces the same results
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 20th Mar 2008 02:55 Edited at: 20th Mar 2008 02:56
Did you set key1 to false at the start? Also, it is type boolean, and true and false...they have syntax highlighting?
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 20th Mar 2008 03:28 Edited at: 20th Mar 2008 03:42


so yes


to make things more confusing this code makes the animation play WHILE the button is held down while the second section of code does nothing while the third section moves the object forward but does not play the animation




jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 20th Mar 2008 04:11 Edited at: 20th Mar 2008 04:12
I think that you should go ahead and put the frame numbers and speed in there, the numbers that you are using are not in the range of this animation. Move is frames 32 - 50. The speed is less important, but 7000 fps is just way too high. Try 6.

Firstly, I would call dbScanCode at the top of the loop, and store the result. Then you could use a switch statement for the keys, which is pretty much the standard method. It you have any other if (dbScanCode() == somethings) in there, they will steal the keypress, and you will have no control. Are there any more of those in the game loop?
Core2uu
16
Years of Service
User Offline
Joined: 15th Mar 2008
Location: Saskatoon, SK, Canada
Posted: 20th Mar 2008 06:11
Sorry to butt in in your very interesting conversation but seeing as you linked to my former post I want to say something...

OK, so with the self-invented noob code I used which is quite similar to the one used by Movian I got the animation playing and object moving with NO PROBLEM... I also got GREAT working collision detection and response...

I used a very simple set of code and it ran without issues...
The main problem for me was that all the animations were not packed into one file... As I said before it was in separate which made it all-the-more confusing... using dbAppendObject and such...

That is the part that is still confusing me... how to append multiple files' animations...

Anyways back to the problem at hand... Here is a snippet of the code I used...


~~Core2uu~~
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 20th Mar 2008 06:20 Edited at: 20th Mar 2008 06:22
woot finally got this working
Jinzai i know you know what your talking about however the numbers that i use in this coding example work! and when i try to use the numbers you give me it does not....

the defining factor was your comment about the switch statement, i did as you advised and put the dbscancode into an int called key and then did case statements and put the looped animation into the WalkForward. Also note that the animation now only plays when the model is moving forward and stops when the model stops moving I have provided my code (that compiles and gives the desired effect)

NOTE: i am tempted to switch the dbMouseClick to a similar format for (a: consistancy - & b: my research has revealsed that compilers generate more eficient code from them over if statements! - (i said i was new to this so please don't laugh)) so this has been a great learning experience!








also just to make a note i have included a snipet from the "camera" tutorial that is included with the GDK


this code is direct from the tutorial and un-edited (just wanted to show you why i was using such high values for the frames and speed!)
maybe we can continue this thread to figure out why the values are so high compared to the ones that work for you ?
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 20th Mar 2008 07:10 Edited at: 20th Mar 2008 07:18
Well, that's my bad on the model, maybe it is a different miko.x I will look at the one in GDK.
EDIT: Yes, I was assuming that miko was a DarkMATTER I model, it isn't even close...more like binary X.

Yes, the same thing applies for dbMouseClick(). Both of them mean...right now, and same for dbMouseX(), dbMouseY(). The most straightforward way of using them is to get it once, and use that. Usually, that is the case. You will also want to nest such things at times, but it takes some of the event-driven aspect out of the rest of the game.

I saw your code earlier...the 3rd person camera. That's very nice code. Eventually, you can use it in a camera class and it will be nicer still then.

XLNT, now you can get on to the next issue, which seems to be killing folks, or jumping, or what not.
Cheers.
Movian
16
Years of Service
User Offline
Joined: 5th Mar 2008
Location:
Posted: 20th Mar 2008 07:51
Quote: "That's very nice code. Eventually, you can use it in a camera class and it will be nicer still then."


Thank you very much, (as as previously mentioned i am still fairly new to c++ (didn't even know about the switch case functionality) ) so could you explain a class ? is it similar to a library ?
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 20th Mar 2008 08:07 Edited at: 20th Mar 2008 08:17
Yes, a class is much like a library. It contains data, and the code to manipulate it. Very powerful, and somewhat onerous to learn. In fact, .NET is sort of a library that exposes classes in the way you are thinking. C++ programs gain alot of functionality when using classes; its pretty much the cornerstone of C++, and the reason for buzzwords like 'OOP'.

Okay, I think you have loaded the miko_walk.x model, which is fine, but I would usually load all the animations into the same object. (Otherwise, you are running headlong into an object headache later.)

So, I loaded just the walk animation. The numbers that you want for the frames are 0 to 6720. The thing will loop alright still, but that only has 6720 frames. The speed thing is still tied to your sync rate, and eventually you will have the information to calculate it properly in terms of FPS. I would think she has to be moving at a pretty good clip. In fact, I think that the interpolation and speed are both best set every frame based on that t_0 variable that I went off on you about above. That gibberish is fairly key to decent and consistent animation.


This has only made it more obvious to me that I need to start looking at the DBO data. There is alot in there about what happened when you said to load the object. Look at DBOData.h, all the way at the bottom is the structure definition for sObject, above that are the definitions for the members of that structure.
EDIT:...and there is a function to get the address of the sObject data...sObject* dbGetObject(int objnum)
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th Mar 2008 19:30
Ok - I'm just popping in and don't have trime to study the whole thread - but animation frames are floats, so having frame 1.543 is valid.

Using Time? Just pick a Time Multiplier (for speed) and multiply it times the TimeElapsed you calulate:

Try this example - has what you are looking for - not eloquent - I helped Waco_Opticon with this same issue - see attached.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-20 05:23:14
Your offset time is: 2024-11-20 05:23:14