(Resolved)TickCount to GetElapsedTime Issue

Started by
7 comments, last by Steve5050 15 years, 9 months ago
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]
Advertisement
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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.

What unit do these functions return? I know GetTickCount returns elapsed time in milliseconds, what does this DXUtil function return?
DXUtil.Timer????
Is it Happy Hour?
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?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.






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 TickTick = 0;...Tick += DXUtil.Timer(DirectXTimer.GetElapsedTime)/16.0FMat1 = 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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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]



This topic is closed to new replies.

Advertisement