本文整理汇总了C#中Quaternion.FromAngleAxis方法的典型用法代码示例。如果您正苦于以下问题:C# Quaternion.FromAngleAxis方法的具体用法?C# Quaternion.FromAngleAxis怎么用?C# Quaternion.FromAngleAxis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Quaternion
的用法示例。
在下文中一共展示了Quaternion.FromAngleAxis方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Core.Singleton.Initialise();
Core.Singleton.m_CurrentMap = new Map();
Core.Singleton.m_CurrentMap.SetGraphicsMesh("Level.mesh");
Core.Singleton.m_CurrentMap.SetCollisionMesh("LevelCol.mesh");
CharacterProfile profile = new CharacterProfile();
profile.m_BodyMass = 70;
profile.m_BodyScaleFactor = new Vector3(1.5f, 1, 1.5f);
profile.m_HeadOffset = new Vector3(0, 0.8f, 0);
profile.m_MeshName = "Man.mesh";
profile.m_WalkSpeed = 2.5f;
Character player = new Character(profile);
player.SetPosition(new Vector3(0, 2, 0));
Core.Singleton.m_ObjectManager.Add(player);
Core.Singleton.m_GameCamera.Character = player;
Core.Singleton.m_GameCamera.Distance = 4;
Core.Singleton.m_GameCamera.Angle = new Degree(20);
Light light = Core.Singleton.m_SceneManager.CreateLight();
light.Type = Light.LightTypes.LT_DIRECTIONAL;
light.Direction = new Vector3(1, -3, 1).NormalisedCopy;
light.DiffuseColour = new ColourValue(0.2f, 0.2f, 0.2f);
Core.Singleton.m_SceneManager.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_MODULATIVE;
while (true)
{
Quaternion rotation = new Quaternion();
rotation.FromAngleAxis(new Degree(120 * Core.Singleton.m_TimeStep), Vector3.UNIT_Y);
Core.Singleton.Update();
if (Core.Singleton.m_Keyboard.IsKeyDown(MOIS.KeyCode.KC_ESCAPE))
break;
if (Core.Singleton.m_Keyboard.IsKeyDown(MOIS.KeyCode.KC_A))
player.m_Orientation *= Vector3.UNIT_Z.GetRotationTo(new Vector3(0.01f, 0, 1.0f).NormalisedCopy);
if (Core.Singleton.m_Keyboard.IsKeyDown(MOIS.KeyCode.KC_D))
player.m_Orientation *= Vector3.UNIT_Z.GetRotationTo(new Vector3(-0.01f, 0, 1.0f).NormalisedCopy);
if (Core.Singleton.m_Keyboard.IsKeyDown(MOIS.KeyCode.KC_W))
player.m_State = Character.CharacterState.WALK;
else
player.m_State = Character.CharacterState.IDLE;
if (Core.Singleton.m_Keyboard.IsKeyDown(MOIS.KeyCode.KC_F3))
Core.Singleton.m_NewtonDebugger.ShowDebugInformation();
else
Core.Singleton.m_NewtonDebugger.HideDebugInformation();
}
}
示例2: GlobalEulerToQuat
static Quaternion GlobalEulerToQuat(Radian rotX, Radian rotY, Radian rotZ)
{
Quaternion q1 = new Quaternion(),
q2 = new Quaternion(),
q3 = new Quaternion(),
q = new Quaternion();
q1.FromAngleAxis(rotX, Vector3.UNIT_X);
q2.FromAngleAxis(rotY, Vector3.UNIT_Y);
q3.FromAngleAxis(rotZ, Vector3.UNIT_Z);
// global axes
q = q3 * q2 * q1;
return q;
}
示例3: HandleMovement
// @@ funkcja odpowiedzialna za całokształt poruszania się
private void HandleMovement()
{
Quaternion rotation = new Quaternion();
rotation.FromAngleAxis(new Degree(2), Vector3.UNIT_Y);
if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_Z)) // tzw. skok
User.Camera.Position = new Vector3(User.Camera.Position.x, User.Camera.Position.y + 1, User.Camera.Position.z);
if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_X)) // wypisanie w konsoli aktualnej pozycji postaci
{
Console.Write("Pozycja: ");
Console.Write(User.Camera.Position.x);
Console.Write(", ");
Console.Write(User.Camera.Position.y);
Console.Write(", ");
Console.WriteLine(User.Camera.Position.z);
}
if (Engine.Singleton.IsKeyTyped(MOIS.KeyCode.KC_TAB)) // @@ Otwarcie ekwipunku
SwitchState(HumanControllerState.INVENTORY);
User.Camera.TurnY = -Engine.Singleton.Mouse.MouseState.X.rel * 0.1f;
User.Camera.TurnX = -Engine.Singleton.Mouse.MouseState.Y.rel * 0.1f;
if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_A)) // obrót postaci
User.Camera.Position += User.Camera.Orientation * Vector3.UNIT_X * -User.WalkSpeed;
if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_D))
User.Camera.Position += User.Camera.Orientation * Vector3.UNIT_X * User.WalkSpeed;
if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_Q)) // chodzenie w górę
User.Camera.Position += User.Camera.Orientation * Vector3.UNIT_Y * User.WalkSpeed;
else if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_E)) // chodzenie w dół
User.Camera.Position += User.Camera.Orientation * Vector3.UNIT_Y * -User.WalkSpeed;
if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_W)) // chodzenie do przodu
{
User.Camera.Position += User.Camera.Orientation * Vector3.UNIT_Z * -User.WalkSpeed;
}
if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_S))
{
User.Camera.Position += User.Camera.Orientation * Vector3.UNIT_Z * User.WalkSpeed;
}
if (Engine.Singleton.IsKeyTyped(MOIS.KeyCode.KC_F)) // usuwanie obiektu z Usera
{
switch (HUD.Category)
{
case HUD.InventoryCategory.DESCRIBED:
User.InventoryItem = null;
break;
case HUD.InventoryCategory.CHARACTER:
User.InventoryCharacter = null;
break;
case HUD.InventoryCategory.ENEMY:
User.InventoryCharacter = null;
break;
}
HUD.UpdateChosenItem();
}
if (Engine.Singleton.Mouse.MouseState.ButtonDown(MOIS.MouseButtonID.MB_Left))
{
while (Engine.Singleton.Mouse.MouseState.ButtonDown(MOIS.MouseButtonID.MB_Left))
{
Engine.Singleton.Mouse.Capture(); //petla, zeby nie klikal mi milion razy, tylko raz :)
}
switch (HUD.Category)
{
case HUD.InventoryCategory.DESCRIBED:
if (User.InventoryItem != null)
User.AddItem(true);
break;
case
HUD.InventoryCategory.CHARACTER:
if (User.InventoryCharacter != null)
User.AddItem(true);
break;
case HUD.InventoryCategory.ENEMY:
if (User.InventoryCharacter != null)
User.AddItem(true);
break;
case HUD.InventoryCategory.WAYPOINT:
User.AddItem(true);
break;
}
}
if (Engine.Singleton.IsKeyTyped(MOIS.KeyCode.KC_GRAVE))
{
HUD.lastCategory = HUD.Category;
HUD.Category = WorldCreator.HUD.InventoryCategory.WAYPOINT;
}
if (Engine.Singleton.IsKeyTyped(MOIS.KeyCode.KC_1))
{
HUD.Category = HUD.lastCategory;
//.........这里部分代码省略.........
示例4: LocalEulerToQuat
/// <summary>
/// Converts three euler angles of the local axes to an equivalent quaternion. This assumes that the given angles are in radians and not degrees.
/// </summary>
private static Quaternion LocalEulerToQuat(Radian rotX, Radian rotY, Radian rotZ)
{
Quaternion q1 = new Quaternion(),
q2 = new Quaternion(),
q3 = new Quaternion(),
q = new Quaternion();
q1.FromAngleAxis(rotX, Vector3.UNIT_X);
q2.FromAngleAxis(rotY, Vector3.UNIT_Y);
q3.FromAngleAxis(rotZ, Vector3.UNIT_Z);
// local axes
q = q1 * q2 * q3;
return q;
}
示例5: HandleMouseMove
private void HandleMouseMove(Point delta)
{
if (this.mRotating)
{
cameraRef.Yaw(new Degree(delta.X * this.mRot));
cameraRef.Pitch(new Degree(delta.Y * this.mRot));
WasCameraChangedByUser = true;
}
if (this.mSliding)
{
Vector3 v = cameraRef.Orientation * ((Vector3.UNIT_Y * delta.Y) + (Vector3.UNIT_X * -delta.X));
cameraRef.Move(new Vector3(v.x * mSlide, v.y * mSlide, v.z * mSlide));
WasCameraChangedByUser = true;
}
if (this.mOrbiting)
{
Quaternion cameraRotationAboutWorldY = new Quaternion();
Quaternion cameraRotationAboutWorldX = new Quaternion();
cameraRotationAboutWorldY.FromAngleAxis(new Degree(delta.X * mOrbit), Vector3.UNIT_Y);
cameraRotationAboutWorldX.FromAngleAxis(new Degree(delta.Y * mOrbit), cameraRef.Right);
// Get the result
Quaternion result = cameraRotationAboutWorldX * cameraRotationAboutWorldY;
cameraRef.Position *= result.ToRotationMatrix();
cameraRef.LookAt(ModelPosition);
WasCameraChangedByUser = true;
}
}
示例6: CreateScene
public void CreateScene()
{
scene.SetSkyBox(true, "Examples/SpaceSkyBox");
SetupLighting();
Plane plane = new Plane();
plane.normal = Vector3.UNIT_Y;
plane.d = 0;
MeshManager.Singleton.CreatePlane("MyPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 14500, 14500, 10, 10, true, 1, 50, 50, Vector3.UNIT_Z);
Entity planeEnt = scene.CreateEntity("plane", "MyPlane");
planeEnt.SetMaterialName("Examples/GrassFloor");
planeEnt.CastShadows = false;
scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEnt);
Vector3 minV = new Vector3(-2000, 0, -2000);
Vector3 maxV = new Vector3(2000, 0, 2000);
CreateGrassMesh();
Entity e = scene.CreateEntity("1", GRASS_MESH_NAME);
StaticGeometry s = scene.CreateStaticGeometry("bing");//, 1);
s.RegionDimensions = new Vector3(1000, 1000, 1000);
s.Origin = new Vector3(-500, 500, -500); //Set the region origin so the centre is at 0 world
for (int x = -1950; x < 1950; x += 150) {
for (int z = -1950; z < 1950; z += 150) {
Vector3 pos = new Vector3(x + Math.RangeRandom(-25, 25), 0, z + Math.RangeRandom(-25, 25));
Quaternion orientation =new Quaternion();
orientation.FromAngleAxis(Math.RangeRandom(0, 359), Vector3.UNIT_Y);
Vector3 scale = new Vector3(1, Math.RangeRandom(0.85f, 1.15f), 1);
s.AddEntity(e, pos, orientation, scale);
}
}
s.Build();
StaticGeom = s;
//Mesh mesh = MeshManager.Singleton.Load("ogrehead.mesh", ResourceGroupManager.DefaultResourceGroupName);
//short src, dest;
//if (!mesh.SuggestTangentVectorBuildParams( VertexElementSemantic.VES_POSITION, out src, out dest)) {
// mesh.BuildTangentVectors( VertexElementSemantic.VES_POSITION,src, dest);
//}
//e = scene.CreateEntity("head", "ogrehead.mesh");
//e.SetMaterialName("Examples/OffsetMapping/Specular");
//HeadNode = scene.RootSceneNode.CreateChildSceneNode();
//HeadNode.AttachObject(e);
//HeadNode.Scale = new Vector3(7, 7, 7);
//HeadNode.Position = new Vector3(0, 200, 0);
//if (e.GetSubEntity(0).NormalizeNormals == false) {
// LogManager.Singleton.LogMessage("aie aie aie");
//}
Root.Singleton.RenderSystem.SetNormaliseNormals(true);
//camera.Move(new Vector3(0, 350, 0));
}
示例7: CreateGrassMesh
private void CreateGrassMesh()
{
// Each grass section is 3 planes at 60 degrees to each other
// Normals point straight up to simulate correct lighting
Mesh msh = MeshManager.Singleton.CreateManual(GRASS_MESH_NAME, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, null);
SubMesh sm = msh.CreateSubMesh();
sm.useSharedVertices = false;
sm.vertexData = new VertexData();
sm.vertexData.vertexStart = 0;
sm.vertexData.vertexCount = 12;
VertexDeclaration dcl = sm.vertexData.vertexDeclaration;
uint offset = 0;
dcl.AddElement(0, offset, VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_POSITION);
offset += VertexElement.GetTypeSize(VertexElementType.VET_FLOAT3);
dcl.AddElement(0, offset, VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_NORMAL);
offset += VertexElement.GetTypeSize(VertexElementType.VET_FLOAT3);
dcl.AddElement(0, offset, VertexElementType.VET_FLOAT2, VertexElementSemantic.VES_TEXTURE_COORDINATES);
offset += VertexElement.GetTypeSize(VertexElementType.VET_FLOAT2);
HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager.Singleton.CreateVertexBuffer(offset, 12, HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY);
int i;
unsafe {
float* pData = (float*)(vbuf.Lock(HardwareBuffer.LockOptions.HBL_DISCARD));
Vector3 baseVec = new Vector3(GRASS_WIDTH / 2, 0, 0);
Vector3 vec = baseVec;
Quaternion rot = new Quaternion();
rot.FromAngleAxis(Math.DegreesToRadians(60), Vector3.UNIT_Y);
for (i = 0; i < 3; ++i) {
//position
*pData++ = -vec.x;
*pData++ = GRASS_HEIGHT;
*pData++ = -vec.z;
// normal
*pData++ = 0;
*pData++ = 1;
*pData++ = 0;
// uv
*pData++ = 0;
*pData++ = 0;
// position
*pData++ = vec.x;
*pData++ = GRASS_HEIGHT;
*pData++ = vec.z;
// normal
*pData++ = 0;
*pData++ = 1;
*pData++ = 0;
// uv
*pData++ = 1;
*pData++ = 0;
// position
*pData++ = -vec.x;
*pData++ = 0;
*pData++ = -vec.z;
// normal
*pData++ = 0;
*pData++ = 1;
*pData++ = 0;
// uv
*pData++ = 0;
*pData++ = 1;
// position
*pData++ = vec.x;
*pData++ = 0;
*pData++ = vec.z;
// normal
*pData++ = 0;
*pData++ = 1;
*pData++ = 0;
// uv
*pData++ = 1;
*pData++ = 1;
vec = rot * vec;
} //for
} //unsafe
vbuf.Unlock();
sm.vertexData.vertexBufferBinding.SetBinding(0, vbuf);
sm.indexData.indexCount = 6 * 3;
sm.indexData.indexBuffer = HardwareBufferManager.Singleton.CreateIndexBuffer(HardwareIndexBuffer.IndexType.IT_16BIT, 6 * 3, HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY);
unsafe {
ushort* pI = (ushort*)(sm.indexData.indexBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD));
for (i = 0; i < 3; ++i) {
int off = i * 4;
*pI++ = (ushort)(off);
*pI++ = (ushort)(off + 3);
*pI++ = (ushort)(off + 1);
//.........这里部分代码省略.........