method One: Refer to the book "Mastering C # Game Programming". according to the learning WorldWind source, the method used in WorldWind is basically consistent with this method.
UsingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Runtime.InteropServices;namespaceGameloop//modify namespaces as needed{ Public classPrecisetimer {[System.Security.SuppressUnmanagedCodeSecurity] [DllImport ("kernel32")] Private Static extern BOOLQueryPerformanceFrequency (ref Longperformancefrequency); [System.Security.SuppressUnmanagedCodeSecurity] [DllImport ("kernel32")] Private Static extern BOOLQueryPerformanceCounter (ref Longperformancecount); Long_tickspersecond =0; Long_previouselapsedtime =0; PublicPrecisetimer () {QueryPerformanceFrequency (ref_tickspersecond); GetElapsedTime (); //Get rid of first rubbish result } Public DoubleGetElapsedTime () {LongTime =0; QueryPerformanceCounter (refTime ); DoubleElapsedTime = (Double) (Time-_previouselapsedtime)/(Double) _tickspersecond; _previouselapsedtime=Time ; returnElapsedTime; } }}
Precise time leveling in C # game development