WORKING WITH MODELS in Microsoft Word Draw Data Matrix 2d barcode in Microsoft Word WORKING WITH MODELS

CHAPTER 4 WORKING WITH MODELS
Data Matrix 2d Barcode Generation In None
Using Barcode creator for Microsoft Word Control to generate, create Data Matrix 2d barcode image in Office Word applications.
www.OnBarcode.com
Barcode Drawer In None
Using Barcode encoder for Word Control to generate, create Barcode image in Word applications.
www.OnBarcode.com
Figure 4-24. Finding the inclination angle
Encoding UCC - 12 In None
Using Barcode printer for Office Word Control to generate, create UPC-A image in Microsoft Word applications.
www.OnBarcode.com
UCC - 12 Creation In None
Using Barcode maker for Word Control to generate, create EAN128 image in Office Word applications.
www.OnBarcode.com
Calculating the Rotation Angles
Data Matrix 2d Barcode Printer In None
Using Barcode generator for Word Control to generate, create Data Matrix image in Microsoft Word applications.
www.OnBarcode.com
Barcode Generator In None
Using Barcode maker for Microsoft Word Control to generate, create Barcode image in Microsoft Word applications.
www.OnBarcode.com
Now that you know the height difference on your terrain, using some trigon math you can find the inclination angle. In a triangle with one corner of 90 degrees, you can find the angle of one of the other corners if you know the length of the opposite side (A in Figure 4-24) and of the neighboring side (B in Figure 4-24). The angle is found by taking the arc tangent (atan) of their lengths. The first length equals the height difference you just calculated, while the second length equals the length of your frontToBack vector! This is how you find the angle and construct the corresponding rotation around the (1,0,0) Side vector. The resulting rotation is stored in a quaternion (an object useful for storing and combining rotations without Gimbal lock, as explained in recipe 2-4): float fbAngle = (float)Math.Atan2(fbTerHeightDiff, backToFront.Length()); Quaternion bfRot = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), -fbAngle); If you rotate your Model using this rotation, the front and back points of your Model will follow the slope of your terrain! Obviously, this is only 50 percent of the work, because you ll also want to rotate your model around its Forward vector so its left and right points follow the terrain. Luckily, you can use the same approach and code to find the lrAngle. You simply want to make sure the leftToFront dotted line in Figure 4-23 is aligned to the terrain underneath: Vector3 left = (frontLeft + backLeft) / 2.0f; Vector3 right = (frontRight + backRight) / 2.0f; Vector3 rightToLeft = left - right; float leftTerHeight = terrain.GetExactHeightAt(left.X, -left.Z); float rightTerHeight = terrain.GetExactHeightAt(right.X, -right.Z); float lrTerHeightDiff = leftTerHeight - rightTerHeight; float lrAngle = (float)Math.Atan2(lrTerHeightDiff, rightToLeft.Length()); Quaternion lrRot = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1), -lrAngle);
Painting PDF 417 In None
Using Barcode printer for Office Word Control to generate, create PDF 417 image in Word applications.
www.OnBarcode.com
Leitcode Maker In None
Using Barcode creation for Microsoft Word Control to generate, create Leitcode image in Office Word applications.
www.OnBarcode.com
C HA PTER 4 WO RK ING WI T H M OD ELS
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Draw Data Matrix ECC200 In .NET Framework
Using Barcode creator for VS .NET Control to generate, create Data Matrix 2d barcode image in VS .NET applications.
www.OnBarcode.com
Now that you have both rotations, it s easy to combine them by multiplying them. Combine the resulting transformation with the World transformation: Quaternion combRot = fbRot * lrRot; Matrix rotatedModelWorld = Matrix.CreateFromQuaternion(combRot) * modelWorld; If you use this rotatedModelWorld matrix as the World matrix for rendering your Model, it will be perfectly rotated to fit on your terrain! However, you still need to position it at the correct height.
Make GS1 DataBar Stacked In Java
Using Barcode maker for Java Control to generate, create GS1 DataBar Truncated image in Java applications.
www.OnBarcode.com
Generating Barcode In None
Using Barcode maker for Microsoft Excel Control to generate, create Barcode image in Microsoft Excel applications.
www.OnBarcode.com
Positioning the Model at the Correct Height
Recognize Code128 In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Linear Printer In Visual Basic .NET
Using Barcode encoder for VS .NET Control to generate, create Linear Barcode image in .NET framework applications.
www.OnBarcode.com
Because you re rotating your Model, some wheels will be lower than others. Now that you have calculated your rotations, you can easily find the rotated positions of your wheels: Vector3 rotFrontLeft = Vector3.Transform(frontLeftOrig, frontLeftMatrix * rotatedModelWorld); Vector3 rotFrontRight = Vector3.Transform(frontRightOrig, frontRightMatrix * rotatedModelWorld); Vector3 rotBackLeft = Vector3.Transform(backLeftOrig, backLeftMatrix * rotatedModelWorld); Vector3 rotBackRight = Vector3.Transform(backRightOrig, backRightMatrix * rotatedModelWorld); Next, you can use the X and Y components of these positions to find out exactly where they should be positioned: float float float float flTerHeight frTerHeight blTerHeight brTerHeight = = = = terrain.GetExactHeightAt(rotFrontLeft.X, -rotFrontLeft.Z); terrain.GetExactHeightAt(rotFrontRight.X, -rotFrontRight.Z); terrain.GetExactHeightAt(rotBackLeft.X, -rotBackLeft.Z); terrain.GetExactHeightAt(rotBackRight.X, -rotBackRight.Z);
Print PDF-417 2d Barcode In .NET Framework
Using Barcode drawer for Visual Studio .NET Control to generate, create PDF 417 image in .NET applications.
www.OnBarcode.com
Read ANSI/AIM Code 128 In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
You know the Y height coordinate of your wheels and you know the Y coordinate of where they should be, so it s easy to calculate how much they re off: float float float float flHeightDiff frHeightDiff blHeightDiff brHeightDiff = = = = rotFrontLeft.Y - flTerHeight; rotFrontRight.Y - frTerHeight; rotBackLeft.Y - blTerHeight; rotBackRight.Y - brTerHeight;
Generating UPCA In Java
Using Barcode drawer for Java Control to generate, create UPC-A Supplement 2 image in Java applications.
www.OnBarcode.com
Data Matrix Encoder In .NET Framework
Using Barcode creator for ASP.NET Control to generate, create DataMatrix image in ASP.NET applications.
www.OnBarcode.com
However, you ve obtained four different values that could be useful for shifting your Model to its correct height. Because you ll be shifting your whole model, there s only one value you can actually use. The value you actually want depends on your liking. If you want to make sure not a single wheel ever sticks even a millimeter in the ground, take the largest difference. If you don t like having spaces between your Model and the terrain, take the smallest one. Hey, this is my recipe, so I m taking their average as the final shifting value: float finalHeightDiff = (blHeightDiff + brHeightDiff + flHeightDiff + frHeightDiff) / 4.0f; modelWorld = rotatedModelWorld * Matrix.CreateTranslation(new Vector3(0, -finalHeightDiff, 0));
Recognizing Barcode In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Generating GS1-128 In None
Using Barcode generation for Online Control to generate, create EAN128 image in Online applications.
www.OnBarcode.com