WORKING WITH MODELS in Microsoft Word

Generation DataMatrix in Microsoft Word WORKING WITH MODELS

CHAPTER 4 WORKING WITH MODELS
Data Matrix Drawer In None
Using Barcode printer for Microsoft Word Control to generate, create Data Matrix 2d barcode image in Office Word applications.
www.OnBarcode.com
Code 3 Of 9 Generator In None
Using Barcode encoder for Word Control to generate, create Code 3/9 image in Microsoft Word applications.
www.OnBarcode.com
The last line adds a matrix that contains this vertical translation to the World matrix of the Model.
Encoding PDF-417 2d Barcode In None
Using Barcode drawer for Microsoft Word Control to generate, create PDF-417 2d barcode image in Word applications.
www.OnBarcode.com
Code 128 Code Set C Creation In None
Using Barcode generation for Microsoft Word Control to generate, create Code 128 Code Set A image in Word applications.
www.OnBarcode.com
Note Here you re putting your newly calculated matrix at the right of the multiplication to make sure the
QR-Code Creation In None
Using Barcode drawer for Office Word Control to generate, create QR image in Word applications.
www.OnBarcode.com
Data Matrix ECC200 Creation In None
Using Barcode printer for Office Word Control to generate, create Data Matrix image in Microsoft Word applications.
www.OnBarcode.com
model is moved over the absolute Up axis. If you put it at the left part of the multiplication, the Model would be moved along the Up vector of the Model, which is rotated.
GS1 - 12 Drawer In None
Using Barcode creation for Office Word Control to generate, create UPC-A Supplement 5 image in Office Word applications.
www.OnBarcode.com
UPCE Creation In None
Using Barcode printer for Microsoft Word Control to generate, create UCC - 12 image in Microsoft Word applications.
www.OnBarcode.com
That s it. If you render your Model using this World matrix, the Model will follow the slope of the terrain nicely. It s a huge amount of code, but if you put it in a for loop, the amount is already divided by 4. If you re scared it looks a bit heavy on the calculations, keep in mind that these calculations have to be performed only for Models that actually have to be rendered to the screen!
Data Matrix 2d Barcode Generation In VB.NET
Using Barcode maker for .NET Control to generate, create DataMatrix image in VS .NET applications.
www.OnBarcode.com
Making Data Matrix 2d Barcode In None
Using Barcode creator for Online Control to generate, create ECC200 image in Online applications.
www.OnBarcode.com
Preparing for Animation
Drawing EAN 13 In Visual C#
Using Barcode creator for Visual Studio .NET Control to generate, create GS1 - 13 image in Visual Studio .NET applications.
www.OnBarcode.com
Scanning PDF-417 2d Barcode In VB.NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
If you have animated your Model, you can get into some trouble. For example, if you have rotated one of the wheels for 180 degrees, the vector stored in the Tag property of the wheel will contain the highest point of the wheel, instead of the lowest! This will cause your Model s wheel to sink into the ground. To solve for this, you should reset the Bone matrices of the wheels to their original value before performing the calculations. This is no problem, because you need to store these anyway when doing Model animations (see recipe 4-9); 2, 4, 6, and 8 are the indices of the Bones attached to the four wheels. myModel.Bones[2].Transform myModel.Bones[4].Transform myModel.Bones[6].Transform myModel.Bones[8].Transform = = = = originalTransforms[2]; originalTransforms[4]; originalTransforms[6]; originalTransforms[8];
Printing UCC-128 In Objective-C
Using Barcode generator for iPhone Control to generate, create EAN / UCC - 13 image in iPhone applications.
www.OnBarcode.com
UPC - 13 Creation In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create EAN13 image in ASP.NET applications.
www.OnBarcode.com
float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 1000.0f; Matrix worldMatrix = Matrix.CreateTranslation(new Vector3(10, 0, -12)); // starting position worldMatrix = Matrix.CreateRotationY(MathHelper.PiOver4*3)*worldMatrix; worldMatrix = Matrix.CreateTranslation(0, 0, time)*worldMatrix; //move forward worldMatrix = Matrix.CreateScale(0.001f)*worldMatrix; //scale down a bit worldMatrix = TiltModelAccordingToTerrain(myModel, worldMatrix, 5, 1, 4, 0); //do tilting magic
Creating ECC200 In VS .NET
Using Barcode generation for Reporting Service Control to generate, create DataMatrix image in Reporting Service applications.
www.OnBarcode.com
Making Barcode In Objective-C
Using Barcode printer for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
The Code
Print Barcode In Java
Using Barcode drawer for Android Control to generate, create Barcode image in Android applications.
www.OnBarcode.com
Decoding QR Code ISO/IEC18004 In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Here s the code for the content pipeline namespace that will save the lowest vertex of each ModelMesh in its Tag property:
Data Matrix 2d Barcode Drawer In Visual Studio .NET
Using Barcode generator for ASP.NET Control to generate, create DataMatrix image in ASP.NET applications.
www.OnBarcode.com
European Article Number 13 Drawer In Visual Studio .NET
Using Barcode printer for Reporting Service Control to generate, create UPC - 13 image in Reporting Service applications.
www.OnBarcode.com
C HA PTER 4 WO RK ING WI T H M OD ELS
namespace ModelVector3Pipeline { [ContentProcessor] public class ModelVector3Processor : ModelProcessor { public override ModelContent Process(NodeContent input, ContentProcessorContext context) { List<Vector3> lowestVertices = new List<Vector3>(); lowestVertices = FindLowestVectors(input, lowestVertices); ModelContent usualModel = base.Process(input, context); int i = 0; foreach (ModelMeshContent mesh in usualModel.Meshes) mesh.Tag = lowestVertices[i++]; return usualModel; } private List<Vector3> FindLowestVectors(NodeContent node, List<Vector3> lowestVertices) { Vector3 lowestPos = null; MeshContent mesh = node as MeshContent; foreach (NodeContent child in node.Children) lowestVertices = FindLowestVectors(child, lowestVertices); if (mesh != null) foreach (GeometryContent geo in mesh.Geometry) foreach (Vector3 vertexPos in geo.Vertices.Positions) if ((lowestPos == null) || (vertexPos.Y < lowestPos.Value.Y)) lowestPos = vertexPos; lowestVertices.Add(lowestPos.Value); return lowestVertices; } } } The following code is the method that adjusts a given World matrix in such a way that your Model will be titled so it fits nicely on your terrain. You need to pass it the World matrix of the Model, the Model itself, and the four indices of the ModelMeshes that correspond to the four wheels of the Model.
CHAPTER 4 WORKING WITH MODELS
private Matrix TiltModelAccordingToTerrain(Model model, Matrix worldMatrix, int flID, int frID, int blID, int brID) { Vector3 frontLeftOrig = (Vector3)model.Meshes[flID].Tag; Vector3 frontRightOrig = (Vector3)model.Meshes[frID].Tag; Vector3 backLeftOrig = (Vector3)model.Meshes[blID].Tag; Vector3 backRightOrig = (Vector3)model.Meshes[brID].Tag; model.CopyAbsoluteBoneTransformsTo(modelTransforms); Matrix frontLeftMatrix = modelTransforms[model.Meshes[flID].ParentBone.Index]; Matrix frontRightMatrix = modelTransforms[model.Meshes[frID].ParentBone.Index]; Matrix backLeftMatrix = modelTransforms[model.Meshes[blID].ParentBone.Index]; Matrix backRightMatrix = modelTransforms[model.Meshes[brID].ParentBone.Index]; Vector3 frontLeft = Vector3.Transform(frontLeftOrig, frontLeftMatrix * worldMatrix); Vector3 frontRight = Vector3.Transform(frontRightOrig, frontRightMatrix * worldMatrix); Vector3 backLeft = Vector3.Transform(backLeftOrig, backLeftMatrix * worldMatrix); Vector3 backRight = Vector3.Transform(backRightOrig, backRightMatrix * worldMatrix); Vector3 front = (frontLeft + frontRight) / 2.0f; Vector3 back = (backLeft + backRight) / 2.0f; Vector3 backToFront = front - back; float frontTerHeight = terrain.GetExactHeightAt(front.X, -front.Z); float backTerHeight = terrain.GetExactHeightAt(back.X, -back.Z); float fbTerHeightDiff = frontTerHeight - backTerHeight; float fbAngle = (float)Math.Atan2(fbTerHeightDiff, backToFront.Length()); Quaternion fbRot = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), -fbAngle); 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;
Copyright © OnBarcode.com . All rights reserved.