- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
direction.Y in Microsoft Word
direction.Y Make Data Matrix ECC200 In None Using Barcode maker for Word Control to generate, create ECC200 image in Microsoft Word applications. www.OnBarcode.comCreate Barcode In None Using Barcode drawer for Office Word Control to generate, create Barcode image in Office Word applications. www.OnBarcode.compoint A.Y
Code128 Creation In None Using Barcode creation for Microsoft Word Control to generate, create Code 128C image in Microsoft Word applications. www.OnBarcode.comPDF417 Drawer In None Using Barcode encoder for Office Word Control to generate, create PDF417 image in Microsoft Word applications. www.OnBarcode.com1 3 5 4 2 Create GS1 - 13 In None Using Barcode creation for Microsoft Word Control to generate, create EAN-13 image in Microsoft Word applications. www.OnBarcode.comDrawing EAN128 In None Using Barcode generator for Microsoft Word Control to generate, create USS-128 image in Word applications. www.OnBarcode.comCHAPTER 5 GETTING THE MOST OUT OF VERTICES
Draw Code 39 Extended In None Using Barcode creation for Microsoft Word Control to generate, create Code-39 image in Microsoft Word applications. www.OnBarcode.comInternational Standard Serial Number Printer In None Using Barcode encoder for Office Word Control to generate, create ISSN - 10 image in Word applications. www.OnBarcode.comAs long as the difference in height between the current point and the terrain below is too large, do the following: 1. Divide the direction of the Ray in half. 2. Add the resulting direction to the current point to obtain the next point. 3. If the next point is also above the terrain, save the next point as the current point. Imagine this as walking over the Ray each step, and before placing your foot, you check whether your foot is not below the terrain. As long as this isn t the case, you continue while halving your step size after each step. Once you ve placed your foot under the terrain, you retract your foot and try putting it half as far, until you end your foot exactly on the position of the terrain that collides with the terrain. In code, this is as follows: private Vector3 BinarySearch(Ray ray) { float accuracy = 0.01f; float heightAtStartingPoint = terrain.GetExactHeightAt(ray.Position.X, -ray.Position.Z); float currentError = ray.Position.Y - heightAtStartingPoint; while (currentError > accuracy) { ray.Direction /= 2.0f; Vector3 nextPoint = ray.Position + ray.Direction; float heightAtNextPoint = terrain.GetExactHeightAt(nextPoint.X, -nextPoint.Z); if (nextPoint.Y > heightAtNextPoint) { ray.Position = nextPoint; currentError = ray.Position.Y - heightAtNextPoint; } } return ray.Position; } You start by calculating the difference in height between the starting point on your Ray and the terrain beneath (or above) that point. The while will loop until this difference is less than your predefined accuracy of 0.01f. If the difference is still larger, you halve the step size and calculate the next point on the Ray. If this next point is above the terrain, you step to that point and calculate the height difference at that point. If it isn t, do nothing so that the next time the step size is halved again. After quitting the while loop, ray.Position will contain a position on the Ray where the height difference with the terrain is less than 0.01f. Reading ECC200 In C# Using Barcode reader for .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comData Matrix Printer In None Using Barcode creator for Word Control to generate, create Data Matrix 2d barcode image in Office Word applications. www.OnBarcode.comCHAPTER 5 GETTING THE MOST OUT OF VE RTICES
QR Code ISO/IEC18004 Creator In VS .NET Using Barcode encoder for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications. www.OnBarcode.comCreate USS Code 128 In None Using Barcode generation for Online Control to generate, create Code 128 Code Set A image in Online applications. www.OnBarcode.comThis is how you can use your method, starting from the rayAB created with the GetPointerRay: pointerPos = BinarySearch(pointerRay); Draw Matrix Barcode In Visual C# Using Barcode generation for Visual Studio .NET Control to generate, create Matrix Barcode image in Visual Studio .NET applications. www.OnBarcode.comEncoding UPC Symbol In VB.NET Using Barcode encoder for Visual Studio .NET Control to generate, create UCC - 12 image in Visual Studio .NET applications. www.OnBarcode.com Note If your pointer is not over the terrain, this method will stay forever in its while loop. Therefore, it can be useful to break out of the while loop if a counter value is greater than some threshold, as shown in the code later in this recipe. Read ANSI/AIM Code 39 In Java Using Barcode scanner for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comData Matrix ECC200 Generator In Visual Studio .NET Using Barcode drawer for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications. www.OnBarcode.comProblems with the Binary Search
ECC200 Scanner In Visual C#.NET Using Barcode recognizer for .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comRecognize QR Code JIS X 0510 In Visual Basic .NET Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comIn most cases, the binary search will do a fine job, but in some case it will just fail miserably, as shown in Figure 5-20. GS1 DataBar Expanded Encoder In Java Using Barcode generator for Java Control to generate, create GS1 DataBar Truncated image in Java applications. www.OnBarcode.comMaking Code 3 Of 9 In C# Using Barcode encoder for .NET Control to generate, create Code39 image in VS .NET applications. www.OnBarcode.com1 3 5 4 2 Figure 5-20. Problematic case for the binary search Since the binary check does not check terrain height between point 0 and point 1, the collision between the first hill and the Ray is not detected at all, and the same result (point 5) is returned as a collision between the Ray and the terrain. To solve this, the binary search should be preceded by a linear search, which is simple in comparison to the binary search. Linear Search
In a linear search, you re going to divide your Ray into a few equidistant steps, for example, eight steps, as shown in Figure 5-21. Figure 5-21. Linear search
CHAPTER 5 GETTING THE MOST OUT OF VERTICES
You simply walk over your Ray in steps of the same size, until you encounter a point below the terrain. This will not give you an exact result, but at least you will detect that the Ray has collided with the first hill. Because neither point 1 nor point 2 in Figure 5-21 is really close to the terrain, you will want to use the binary search on the Ray between points 1 and 2 to accurately find the exact collision point. The LinearSearch method accepts the whole Ray between A and B, divides it into equal steps, and returns the part of the Ray that corresponds to the step during which the collision occurred: private Ray LinearSearch(Ray ray) { ray.Direction /= 300.0f; Vector3 nextPoint = ray.Position + ray.Direction; float heightAtNextPoint = terrain.GetExactHeightAt(nextPoint.X, -nextPoint.Z); while (heightAtNextPoint < nextPoint.Y) { ray.Position = nextPoint; nextPoint = ray.Position + ray.Direction; heightAtNextPoint = terrain.GetExactHeightAt(nextPoint.X, -nextPoint.Z); } return ray; } In this example, the Ray is divided into no less than 300 steps. Increasing this value will increase the probability of detecting peaks but will require more processing power. For each point, you calculate the next point and check whether that next point is above or below the terrain. As long as it is above the terrain, continue. If the next point is below the terrain, return the current Ray containing the point before the collision and the step in which the collision occurred. This Ray can immediately be used to start the BinarySearch method: Ray shorterRay = LinearSearch(pointerRay); pointerPos = BinarySearch(shorterRay);
|
|