Please help me get started

Started by
15 comments, last by GDR 10 years, 8 months ago

Hi GDR.

Can i straighten out one point first, WPF can create smooth and continuous motion, no worries. And if all you are creating is a desktop application with not too complex graphics then WPF is perfect for you needs. I can provide you with a small WPF application that generates circles and allows you to drag and throw them around and does collision detection between the objects, although I didn't bother doing wall detection at the time but that's easy, and there are a couple of buttons in the app that don't work. It will certainly show you how to use a continuous time 'heartbeat' to create smooth motion/animation.

It sounds to me as though WPF would be more suitable to your needs.

Write an email to gavin_w3@yahoo.com.au with GDR in the subject line and I'll fix you up with the solution. Unfortunately when I checked it, it was updated to VS11 so you'll probably need to manually build it again.

I am personally using SharpDX at the moment with DirectX 11.1, I have also used SlimDX and XNA in the past. I would not recommend XNA, nor DirectX 9. Those technologies are in support mode and the newer DirectX versions have more features and are more future proof. There is very little reason to use those older technologies when DX 11 is widely available. You have to ask yourself why you need Direct X 9 support and why you would want to use that rather than a more fully featured and more modern library. Why are you considering XP support ? No one has XP anymore. Even if one or two people can pipe up and say 'I use XP' ... it's irrelevant. Just my 2c.

Advertisement

Hi GDR.

Can i straighten out one point first, WPF can create smooth and continuous motion, no worries. And if all you are creating is a desktop application with not too complex graphics then WPF is perfect for you needs. I can provide you with a small WPF application that generates circles and allows you to drag and throw them around and does collision detection between the objects, although I didn't bother doing wall detection at the time but that's easy, and there are a couple of buttons in the app that don't work. It will certainly show you how to use a continuous time 'heartbeat' to create smooth motion/animation.

It sounds to me as though WPF would be more suitable to your needs.

Write an email to gavin_w3@yahoo.com.au with GDR in the subject line and I'll fix you up with the solution. Unfortunately when I checked it, it was updated to VS11 so you'll probably need to manually build it again.

I am personally using SharpDX at the moment with DirectX 11.1, I have also used SlimDX and XNA in the past. I would not recommend XNA, nor DirectX 9. Those technologies are in support mode and the newer DirectX versions have more features and are more future proof. There is very little reason to use those older technologies when DX 11 is widely available. You have to ask yourself why you need Direct X 9 support and why you would want to use that rather than a more fully featured and more modern library. Why are you considering XP support ? No one has XP anymore. Even if one or two people can pipe up and say 'I use XP' ... it's irrelevant. Just my 2c.

Hi Gavin thanks for your input. I'll have to look at the XP requirement again, but if I do need to program this for XP and it would be great to do that, then I would need directx9

and therefore, the question is, do I just use directx9 and use that for Vista, ... Windows 8.

But, with regards to WPF this would be very ideal. I've tried and tried and I've had trouble creating a smooth animation that I would get from DirectX. With CPU spikes, to slight frame rate changes, it just didn't work for me. I'll email you. Thanks.

Hi GDR,

I've sent through the solution, I've included a few details in the email, and removed a couple of things from the project that would cause a crash. If you have any question, just put them up here, as I don't check my email that often.

In regards to smooth animation and smooth frame-rate. It's almost impossible to get a consistent frame-rate, so the best strategy is to accept that every frame is going to last a different amount of time and write your physics to accommodate different frame times. As you'll see in my solution I use inter-op in the Clock class to access the performance counter. This gives me the highest accuracy reading of elapsed time over the frame. This is not the only way to measure frame-time but it's the way i do it. I then use that time to scale the velocity. So a short frame will result in a shorter movement over the frame while a longer frame will result in greater movement. So over many frames, you're objects do move smoothly.

Gavin

Thanks GRD. I'll try it out tonight and let you know.

Hi Gavin, thanks very much for the code you provided. Its really helpful when I can compile something and see it first hand and then go through the code to start getting a better understanding. Thanks for taking the time to provide this for me and tweak it to compile right off the bat without any mods on my end.

I can tell you are a really talented programmer. I can see from your profile you are taking software Engineering. I had done that as well. I kind of drifted out

of the practice after graduation, so thanks again for helping me to get a jump start with your help as I'm rusty.

Just from a quick glance of the code (I'll spend more time later this week going through it) if I'm correct (forgive my inaccuracies or lack of experience), just to re-iterate what you had said, and what I see in your code, you used CompositionTarget.Rendering to create the loop and then within "CompostionTarget_Rendering" you call your function

"HeartBeat" to add the logic to provide the smoother motion. As well I did see the use of QueryPerformanceCounter which you mention in your post above.

I tried it out on 2 windows 7 systems (a laptop that was previously a Windows XP system, upgraded to a Windows 7) and a native Windows 7 PC. It look good when I tried various speeds when dragging the circle.

We had discussed Windows XP and the question regarding why I'm using it. The reason is I've been asked to support it and I want to try my best to follow through with this.

When I ran it on a Windows XP laptop and a desktop I noticed tearing (I believe that's the term for it) with the circle, more predominant at greater speeds. I know from some experience with DirectX (sad to say my level of knowledge was with directx 7 so that shows my age) I could use the Vsync option in full screen . Do you know the back end details (under the hood) for why I see tearing in Windows XP. Have your tried your program on XP or are you able to do a quick test. As well, do you think this is something that can be minimized or solved or something that is the way it is?

Thanks again.

I'm sorry, I haven't used XP for maybe 10 years, I would have thrown it away probably by now. But I would guess that XP is just too old and there maybe subtle compatibility issues. I am not an expert on using .net on old windows though. Make sure you have the most recent service pack on XP. And check what graphics card the computer has, it will need a decent graphics card to render wpf smoothly. I say this because well, if it's XP, maybe there are other things that haven't been updated as well such as graphics. Which could account for the tearing if it's a really old card. Apparently WPF uses direct x for rendering, though it might not perform as you'd expect because wpf is quite a beefy engine, and it does a lot of other stuff.

So..

1. Check graphics card - and try a better card if you can, perhaps updating the card will give you the performance you need.

2. Install latest service pack for XP

Thanks Gavin. I'll check things out. Thanks for your help.

This topic is closed to new replies.

Advertisement