Sign in to follow this  

(Resolved)TickCount to GetElapsedTime Issue

This topic is 3463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Using vb.net2003 with dx9.0c I'm switching over from environment.tickcount over to using the dxutil timer and I am not getting the same results. The before code:
Tick = Environment.TickCount
 Mat1 = Matrix.Multiply(Matrix.RotationX(DXUtil.DegreeToRadian(20) * CSng(Math.Cos((CDbl(Tick) / 500.0F)))), Mat2)



This is the after code(Been playing with it for awhile so it looks bad)
Private elapsed As Single
Private elapsedtime As Single
elapsed = DXUtil.Timer(DirectXTimer.GetElapsedTime)
        elapsedtime = 4
        elapsedtime *= 1.2F + elapsed
 Mat1 = Matrix.Multiply(Matrix.RotationX(DXUtil.DegreeToRadian(20) * elapsedtime), Mat2)



Using the Before code I have a human model and the code moves a leg as though it was walking normally.(Moves Back and Forth) Using the After code the leg goes to a waist high front kick and just stays there,it seemed to move slightly but I don't know if that was just a frame rate effect. I've tried for long time to get it right and not getting it done. Thanks Steve [Edited by - Steve5050 on June 25, 2008 4:01:14 PM]

Share this post


Link to post
Share on other sites
In your first method, you used a periodic function (cosine), so the position would cycle back and forth.

In your second method, elapsed will be very close to being a constant. It's just the time since the last call to the timer. So your rotation will be just about the same every frame.

You might try something like substituting elapsed for Tick in your first method and then adjusting the ratio 500.0F to something suitable.

Share this post


Link to post
Share on other sites
Hi,
I tried what you said and the leg moves
to the normal walk position then stops.

CSng(Math.Cos((CDbl(Tick) / 500.0F)))),

I've tried multiplied,lowering,and eliminating
the 500.0f value also.

I don't know what's up.

Share this post


Link to post
Share on other sites
Are you now using:
Tick = DXUtil.Timer(DirectXTimer.GetElapsedTime)
Mat1 = Matrix.Multiply(Matrix.RotationX(DXUtil.DegreeToRadian(20) * CSng(Math.Cos((CDbl(Tick) / 500.0F)))), Mat2)
or something similar?

Share this post


Link to post
Share on other sites
Yes I did use it that way.
Plus a few more,but they all did about the same thing.
One that I tried and can't recall off hand made the leg Quiver
as though someone was being electrocuted.

Thanks for taking the time to help by the way.

You know your stuff, I know because you helped
me before.

One way or another it will pan out,I been all over the map
on it and didn't keep track of what I did and didn't do.






Share this post


Link to post
Share on other sites
I'm so stupid. Tick = DXUtil.Timer(DirectXTimer.GetElapsedTime) is going to be a constant, like I said. You need an increasing value.

Try:

// initialize Tick
Tick = 0;
...

Tick += DXUtil.Timer(DirectXTimer.GetElapsedTime)/16.0F
Mat1 = Matrix.Multiply(Matrix.RotationX(DXUtil.DegreeToRadian(20) * CSng(Math.Cos((CDbl(Tick)/60.0F))), Mat2)

or something similar.

I'm assuming the DXUtil.Timer(DirectXTimer.GetElapsedTime) returns the number of millseconds since DXUtil.Timer(DirectXTimer.GetElapsedTime) was last called. If so, 16.0F corresponds to about 60 FPS and Tick will increase by 1 each frame.

In one second, Tick should go from 0 to 60, Tick/60 will go from 0 to 1 and cos() will go from 1 to 0.5. You should see a periodic change. Then you can adjust the 60.0f to suit you - increase it to slow the rotation down; decrease it to speed the rotation up.

Share this post


Link to post
Share on other sites
Ok,actually I just had to do:

Tick += DXUtil.Timer(DirectXTimer.GetElapsedTime) * 25.0F
Mat1 = Matrix.Multiply(Matrix.RotationX(DXUtil.DegreeToRadian(20) * CSng(Math.Cos((CDbl(Tick)))), Mat2)


The only thing was is that the movement was
inconsistant, it would go slow and then faster
and then slow down again,it was doing that because
I was using the code in that classes render procedure.
So I actually started to use my head a little
and I made a sub to get the elapsed time from my
d3dapp and I made a time property to use.
And it is now running smoothly.
So my actual end result is like:

moveDamIt = Time * 12.0F
Mat1 = Matrix.Multiply(Matrix.RotationX(DXUtil.DegreeToRadian(20) * CSng (Math.Cos((CDbl(moveDamIt))))), Mat2)


Thanks Again Buckeye[wow]



Share this post


Link to post
Share on other sites

This topic is 3463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this