/// <summary> /// Moves the object by given absolute vector. This will affect the Transforms <see cref="Vel">velocity</see> value. /// </summary> /// <param name="value"></param> public void MoveByAbs(Vector3 value) { // Accumulate velocity if (MathF.Abs(Time.TimeMult) > float.Epsilon) { this.tempVelAbs += value / Time.TimeMult; } this.posAbs += value; if (this.parentTransform != null) { this.pos = this.posAbs; Vector3.Subtract(ref this.pos, ref this.parentTransform.posAbs, out this.pos); Vector3.Divide(ref this.pos, this.parentTransform.scaleAbs, out this.pos); MathF.TransformCoord(ref this.pos.X, ref this.pos.Y, -this.parentTransform.angleAbs); this.tempVel = this.tempVelAbs; Vector3.Subtract(ref this.tempVel, ref this.parentTransform.tempVelAbs, out this.tempVel); Vector3.Divide(ref this.tempVel, this.parentTransform.scaleAbs, out this.tempVel); MathF.TransformCoord(ref this.tempVel.X, ref this.tempVel.Y, -this.parentTransform.angleAbs); } else { this.pos = this.posAbs; this.tempVel = this.tempVelAbs; } this.changes |= DirtyFlags.Pos; this.UpdateAbsChild(true); }
// Check if dirty flags are set and also clear them. protected bool CheckDirty(DirtyFlags flags) { bool result = ((dirtyFlags & flags) != 0); dirtyFlags &= ~flags; return(result); }
void SetDirty(DirtyFlags flags) { if (m_IsUsedInstance) { if (flags.HasFlag(DirtyFlags.Target)) { EditorUtility.SetDirty(target); } if (flags.HasFlag(DirtyFlags.Shader)) { m_NeedToRefreshShader = true; } if (flags.HasFlag(DirtyFlags.Noise)) { m_NeedToReloadNoise = true; } if (flags.HasFlag(DirtyFlags.GlobalMesh)) { GlobalMesh.Destroy(); } if (flags.HasFlag(DirtyFlags.AllBeamGeom)) { VolumetricLightBeam._EditorSetAllBeamGeomDirty(); } if (flags.HasFlag(DirtyFlags.AllMeshes)) { VolumetricLightBeam._EditorSetAllMeshesDirty(); } } }
private void OnSplineChanged(BezierSpline spline, DirtyFlags dirtyFlags) { #if UNITY_EDITOR if (!executeInEditMode && !EditorApplication.isPlaying) { return; } if (BuildPipeline.isBuildingPlayer) { return; } #if UNITY_2018_3_OR_NEWER // Don't execute the script in prefab mode PrefabStage openPrefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (openPrefabStage != null && openPrefabStage.IsPartOfPrefabContents(gameObject)) { return; } #endif #endif if (m_autoRefresh && (dirtyFlags & (DirtyFlags.SplineShapeChanged | DirtyFlags.NormalsChanged)) != DirtyFlags.None) { Refresh(); } }
public virtual void UpdateParameters() { if (DirtyFlags.Has(DirtyFlag.WorldViewProjection)) { Matrix.Multiply(ref _world, ref _view, out Matrix worldView); Matrix.Multiply(ref worldView, ref _projection, out Matrix worldViewProjection); WorldViewProjection = worldViewProjection; WorldViewProjectionParameter.SetValue(worldViewProjection); DirtyFlags -= DirtyFlag.WorldViewProjection; } if (DirtyFlags.Has(DirtyFlag.MaterialColor)) { Vector4 diffuseColor = new Vector4( DiffuseColor.R / 255f, DiffuseColor.G / 255f, DiffuseColor.B / 255f, (DiffuseColor.A / 255f) * Alpha ); DiffuseColorParameter.SetValue(diffuseColor); DirtyFlags -= DirtyFlag.MaterialColor; } if (DirtyFlags.Has(DirtyFlag.TechniqueIndex)) { OnUpdateTechniqueIndex(); DirtyFlags -= DirtyFlag.TechniqueIndex; } }
public void SetDirty(DirtyFlags flag) { #if UNITY_EDITOR //EditorUtility.SetDirty(this); if (flag == DirtyFlags.All || flag == DirtyFlags.Geometry) { EditorUtility.SetDirty(Geometry); } if (flag == DirtyFlags.All || flag == DirtyFlags.Shading) { EditorUtility.SetDirty(Shading); } if (flag == DirtyFlags.All || flag == DirtyFlags.Rendering) { EditorUtility.SetDirty(Rendering); } if (flag == DirtyFlags.All || flag == DirtyFlags.Foliage) { EditorUtility.SetDirty(Foliage); } #endif Shading.UpdateMaterials(); if (Dirty != null) { Dirty(flag); } if (GlobalDirty != null) { GlobalDirty(this, flag); } }
public void SetDepthBias(float slopeFactor, float constantFactor, float clamp) { _depthBiasSlopeFactor = slopeFactor; _depthBiasConstantFactor = constantFactor; _depthBiasClamp = clamp; _dirty |= DirtyFlags.DepthBias; }
private void RefreshInternal(DirtyFlags dirtyFlags) { if (!m_spline || m_spline.Count < 2) { return; } if (!m_updatePosition && m_updateRotation == RotationMode.No) { return; } BezierSpline.Segment segment = m_spline.GetSegmentAt(m_normalizedT); switch (m_updateRotation) { case RotationMode.UseSplineNormals: if (m_rotationOffset == Vector3.zero) { transform.rotation = Quaternion.LookRotation(segment.GetTangent(), segment.GetNormal()); } else { transform.rotation = Quaternion.LookRotation(segment.GetTangent(), segment.GetNormal()) * Quaternion.Euler(m_rotationOffset); } break; case RotationMode.UseEndPointRotations: if (m_rotationOffset == Vector3.zero) { transform.rotation = Quaternion.LerpUnclamped(segment.point1.rotation, segment.point2.rotation, segment.localT); } else { transform.rotation = Quaternion.LerpUnclamped(segment.point1.rotation, segment.point2.rotation, segment.localT) * Quaternion.Euler(m_rotationOffset); } break; } if (m_updatePosition && (dirtyFlags & DirtyFlags.SplineShapeChanged) == DirtyFlags.SplineShapeChanged) { if (m_positionOffset == Vector3.zero) { transform.position = segment.GetPoint(); } else { transform.position = segment.GetPoint() + transform.rotation * m_positionOffset; } } #if UNITY_EDITOR transform.hasChanged = false; #endif }
public void UpdateWorldMatrix() { if (DirtyFlags.HasFlag(DirtyFlags.MatrixIsDirty)) { NumUpdates++; //TODO: Xform.UpdateMatrix(false); DirtyFlags = 0; } }
public void UpdateWorldPRSParent() { if ((DirtyFlags & (DirtyFlags.RotationIsDirty | DirtyFlags.PositionIsDirty)) != 0) { Parent?.UpdateWorldPRSParent(); //TODO: Xform.Update(); DirtyFlags &= ~(DirtyFlags.RotationIsDirty | DirtyFlags.PositionIsDirty); } }
protected bool CleanDirtyFlags(DirtyFlags mask) { if ((DirtyMask & mask) != 0) { DirtyMask &= ~mask; return(true); } return(false); }
/// <summary> /// Propagates dirty flags to all descendants by provided mask. /// </summary> protected internal void PropagateDirtyFlags(DirtyFlags mask = DirtyFlags.All) { if ((DirtyMask & mask) == mask) { return; } Window.Current?.Invalidate(); PropagateDirtyFlagsHelper(mask); }
/// <summary> /// Updates the Transforms data all at once. /// </summary> /// <param name="pos"></param> /// <param name="vel"></param> /// <param name="scale"></param> /// <param name="angle"></param> /// <param name="angleVel"></param> public void SetRelativeTransform(Vector3 pos, float scale, float angle) { this.pos = pos; this.angle = angle; this.scale = scale; this.changes |= DirtyFlags.All; this.UpdateAbs(); }
/// <summary> /// Public constructor. Creates a new transform component. /// </summary> /// <param name="name">The name of the component.</param> public TransformComponent(string name) : base(name) { _children = new List<TransformComponent>(); _scale = Vector3.One; _rotation = Quaternion.Identity; _translation = Vector3.Zero; _dirtyFlag = DirtyFlags.All; }
/// <summary> /// Updates the Transforms data all at once. /// </summary> /// <param name="pos"></param> /// <param name="vel"></param> /// <param name="scale"></param> /// <param name="angle"></param> /// <param name="angleVel"></param> public void SetTransform(Vector3 pos, float scale, float angle) { this.posAbs = pos; this.angleAbs = angle; this.scaleAbs = scale; this.changes |= DirtyFlags.All; this.UpdateRel(); this.UpdateAbsChild(); }
private void Init() { Name = "unnamed"; Parent = null; //Xform.setScaleChildOffset(true); //Xform.setScale(new Vector3(1.0f, 1.0f, 1.0f)); DirtyFlags = DirtyFlags.MatrixIsDirty | DirtyFlags.RotationIsDirty | DirtyFlags.PositionIsDirty; UpdateXform = true; Support = SupportCategory.Base; End = new Vector3(0.0f, 0.0f, 0.0f); }
private void PropagateDirtyFlagsHelper(DirtyFlags mask) { DirtyMask |= mask; for (var n = FirstChild; n != null; n = n.NextSibling) { if ((n.DirtyMask & mask) != mask) { n.PropagateDirtyFlagsHelper(mask); } } }
private void OnSplineChanged(BezierSpline spline, DirtyFlags dirtyFlags) { #if UNITY_EDITOR if (!executeInEditMode && !UnityEditor.EditorApplication.isPlaying) { return; } #endif RefreshInternal(dirtyFlags); }
/// <summary> /// Moves the object by the given vector. This will affect the Transforms <see cref="Vel">velocity</see> value. /// </summary> /// <param name="value"></param> public void MoveBy(Vector3 value) { // Accumulate velocity if (MathF.Abs(Time.TimeMult) > float.Epsilon) { this.tempVel += value / Time.TimeMult; } this.pos += value; this.changes |= DirtyFlags.Pos; this.UpdateAbs(true); }
void ICmpUpdatable.OnUpdate() { _isInOverlay = (this.VisibilityGroup & VisibilityFlag.ScreenOverlay) != VisibilityFlag.None; if ((_dirtyFlags & DirtyFlags.Status) != DirtyFlags.None) { OnStatusChange(); } OnUpdate(Time.LastDelta / 1000f); _dirtyFlags = DirtyFlags.None; }
/// <summary> /// Turns the object by the given radian angle. This will affect the Transforms <see cref="AngleVel">angular velocity</see> value. /// </summary> /// <param name="value"></param> public void TurnBy(float value) { // Accumulate velocity if (MathF.Abs(Time.TimeMult) > float.Epsilon) { this.tempAngleVel += value / Time.TimeMult; this.tempAngleVelAbs += value / Time.TimeMult; } this.angle = MathF.NormalizeAngle(this.angle + value); this.changes |= DirtyFlags.Angle; this.UpdateAbs(true); }
/// <summary> /// Sets the entire grid as dirty, essentially re-rendering all values in the shader. /// </summary> public void SetDirty() { int width = DirtyFlags.GetLength(0); int height = DirtyFlags.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { DirtyFlags[x, y] = true; } } }
// Constructor. protected ToolkitGraphicsBase(IToolkit toolkit) { this.toolkit = toolkit; clip = null; compositingMode = CompositingMode.SourceOver; compositingQuality = CompositingQuality.Default; interpolationMode = InterpolationMode.Default; pixelOffsetMode = PixelOffsetMode.Default; renderingOrigin = new Point(0, 0); smoothingMode = SmoothingMode.Default; textContrast = 4; textRenderingHint = TextRenderingHint.SystemDefault; dirtyFlags = DirtyFlags.All; }
private void OnSplineChanged(BezierSpline spline, DirtyFlags dirtyFlags) { #if UNITY_EDITOR if (!executeInEditMode && !UnityEditor.EditorApplication.isPlaying) { return; } #endif if ((dirtyFlags & DirtyFlags.SplineShapeChanged) == DirtyFlags.SplineShapeChanged) { Refresh(m_smoothness); } }
/// <summary> /// Checks whether transform values have been changed, clears the changelist and fires the appropriate events /// </summary> /// <param name="sender"></param> public void CommitChanges(Component sender = null) { if (this.changes == DirtyFlags.None) { return; } if (this.eventTransformChanged != null) { this.eventTransformChanged( sender ?? this, new TransformChangedEventArgs(this, this.changes)); } this.changes = DirtyFlags.None; }
void ICmpInitializable.OnInit(Component.InitContext context) { if (context == InitContext.AddToGameObject) { this.GameObj.EventParentChanged += new EventHandler <GameObjectParentChangedEventArgs>(GameObj_EventParentChanged); FixRelativeZ(); } if (Status != WidgetStatus.Disabled) { Status = WidgetStatus.Normal; } _dirtyFlags |= DirtyFlags.Status; OnInit(context); }
public void SetStencilMasks( uint backCompareMask, uint backWriteMask, uint backReference, uint frontCompareMask, uint frontWriteMask, uint frontReference) { _backCompareMask = backCompareMask; _backWriteMask = backWriteMask; _backReference = backReference; _frontCompareMask = frontCompareMask; _frontWriteMask = frontWriteMask; _frontReference = frontReference; _dirty |= DirtyFlags.Stencil; }
/// <summary> /// Constructor /// </summary> public OBB(Vector3 center, Vector3 bounds, Matrix rotation) { _center = center; _bounds = bounds; _rotation = rotation; _inverseRotation = Matrix.Identity; _worldTransform = Matrix.Identity; _aabb = new BoundingBox(Vector3.Zero, Vector3.Zero); _dirtyFlags = DirtyFlags.WorldTransformDirty | DirtyFlags.InverseRotationDirty | DirtyFlags.LocalAABBDirty; }
public OBB(Vector3 center, Vector3 bounds, Matrix rotation) { this.center = center; this.bounds = bounds; this.rotation = rotation; this.inverseRotation = Matrix.Identity; worldTransform = Matrix.Identity; this.aabb = new BoundingBox(); this.dirtyFlags = DirtyFlags.WorldTransformDirty | DirtyFlags.InverseRotationDirty | DirtyFlags.LocalAABBDirty; }
/// <summary> /// Sets all dirty flags for all children, recursively. /// </summary> /// <param name="flags"></param> public void Touch(DirtyFlags flags = DirtyFlags.EverythingIsDirty) { if ((flags | DirtyFlags) != DirtyFlags) { NumTouches++; DirtyFlags |= flags; DirtyFlags childFlags = flags; if ((flags & DirtyFlags.RotationIsDirty) != 0) { childFlags |= DirtyFlags.PositionIsDirty; } foreach (LLJoint child in Children) { child.Touch(childFlags); } } }
/// <summary> /// エフェクト (GaussianBlur.fx) を指定してインスタンスを生成します。 /// </summary> /// <param name="sourceEffect">エフェクト。</param> public GaussianBlurEffect(Effect sourceEffect) { if (sourceEffect == null) throw new ArgumentNullException("sourceEffect"); this.sourceEffect = sourceEffect; kernelSizeParameter = sourceEffect.Parameters["KernelSize"]; kernelsParameter = sourceEffect.Parameters["Kernels"]; horizontalKernels = new Vector3[MaxKernelSize]; verticalKernels = new Vector3[MaxKernelSize]; radius = DefaultRadius; amount = DefaultAmount; width = 1; height = 1; dirtyFlags |= DirtyFlags.KernelSize | DirtyFlags.KernelOffsets | DirtyFlags.KernelWeights; }
/// <summary> /// エフェクト (ShadowMap.fx) を指定してインスタンスを生成します。 /// </summary> /// <param name="sourceEffect">エフェクト。</param> public ShadowMapEffect(Effect sourceEffect) { if (sourceEffect == null) throw new ArgumentNullException("sourceEffect"); this.sourceEffect = sourceEffect; worldParameter = sourceEffect.Parameters["World"]; lightViewProjectionParameter = sourceEffect.Parameters["LightViewProjection"]; basicTechnique = sourceEffect.Techniques["Basic"]; varianceTechnique = sourceEffect.Techniques["Variance"]; world = Matrix.Identity; lightViewProjection = Matrix.Identity; Form = ShadowMapEffectForm.Basic; dirtyFlags = DirtyFlags.World | DirtyFlags.LightViewProjection; }
public void UpdateAndBindDescriptorSets(CommandBufferScoped cbs, PipelineBindPoint pbp) { if ((_dirty & DirtyFlags.All) == 0) { return; } // System.Console.WriteLine("modified " + _dirty + " " + _modified + " on program " + _program.GetHashCode().ToString("X")); if (_dirty.HasFlag(DirtyFlags.Uniform)) { UpdateAndBind(cbs, PipelineBase.UniformSetIndex, DirtyFlags.Uniform, pbp); } if (_dirty.HasFlag(DirtyFlags.Storage)) { UpdateAndBind(cbs, PipelineBase.StorageSetIndex, DirtyFlags.Storage, pbp); } if (_dirty.HasFlag(DirtyFlags.Texture)) { UpdateAndBind(cbs, PipelineBase.TextureSetIndex, DirtyFlags.Texture, pbp); } if (_dirty.HasFlag(DirtyFlags.Image)) { UpdateAndBind(cbs, PipelineBase.ImageSetIndex, DirtyFlags.Image, pbp); } if (_dirty.HasFlag(DirtyFlags.BufferTexture)) { UpdateAndBind(cbs, PipelineBase.BufferTextureSetIndex, DirtyFlags.BufferTexture, pbp); } if (_dirty.HasFlag(DirtyFlags.BufferImage)) { UpdateAndBind(cbs, PipelineBase.BufferImageSetIndex, DirtyFlags.BufferImage, pbp); } _dirty = DirtyFlags.None; }
/// <summary> /// Updates the local axis in case the entity has been rotated. Does /// use a custom implementation of a quaternion to matrix conversion /// to save some calculations. Could also have been done by using /// Matrix.CreateFromQuaternion and then by calling the three axis /// available as properties of the matrix. /// </summary> /// <remarks> /// Based on the quaternion to matrix conversion available on /// euclideanspace.com: /// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/index.htm /// </remarks> protected void UpdateLocalAxis() { float xx = _rotation.X * _rotation.X; float xy = _rotation.X * _rotation.Y; float xz = _rotation.X * _rotation.Z; float xw = _rotation.X * _rotation.W; float yy = _rotation.Y * _rotation.Y; float yz = _rotation.Y * _rotation.Z; float yw = _rotation.Y * _rotation.W; float zz = _rotation.Z * _rotation.Z; float zw = _rotation.Z * _rotation.W; // Calculate the right vector (X-Axis: M11, M12, M13) _right.X = 1f - 2f * (yy + zz); _right.Y = 2f * (xy + zw); _right.Z = 2f * (xz - yw); // Calculate the up vector (Y-Axis: M21, M22, M23) _up.X = 2f * (xy - zw); _up.Y = 1f - 2f * (xx + zz); _up.Z = 2f * (yz + xw); // Calculate the forward vector (-Z-Axis: -M31, -M32, -M33) _forward.X = -2f * (xz + yw); _forward.Y = -2f * (yz - xw); _forward.Z = -1f * (1f - 2f * (xx + yy)); // Clear the flag _dirtyFlag &= ~DirtyFlags.LocalAxis; }
void SetKernelOffsets() { if ((dirtyFlags & DirtyFlags.KernelOffsets) != 0) { var dx = 1.0f / (float) width; var dy = 1.0f / (float) height; horizontalKernels[0].X = 0.0f; horizontalKernels[0].Y = 0.0f; verticalKernels[0].X = 0.0f; verticalKernels[0].Y = 0.0f; for (int i = 0; i < kernelSize / 2; i++) { int baseIndex = i * 2; int left = baseIndex + 1; int right = baseIndex + 2; // XNA BloomPostprocess サンプルに従ってオフセットを決定。 float sampleOffset = i * 2 + 1.5f; var offsetX = dx * sampleOffset; var offsetY = dy * sampleOffset; horizontalKernels[left].X = offsetX; horizontalKernels[right].X = -offsetX; verticalKernels[left].Y = offsetY; verticalKernels[right].Y = -offsetY; } dirtyFlags &= ~DirtyFlags.KernelOffsets; } }
public OBB( Vector3 center, Vector3 bounds, Matrix rotation ) { this.center = center; this.bounds = bounds; this.rotation = rotation; this.inverseRotation = Matrix.Identity; worldTransform = Matrix.Identity; this.aabb = new BoundingBox(); this.dirtyFlags = DirtyFlags.WorldTransformDirty | DirtyFlags.InverseRotationDirty | DirtyFlags.LocalAABBDirty; }
void SetKernelWeights() { if ((dirtyFlags & DirtyFlags.KernelWeights) != 0) { var totalWeight = 0.0f; var sigma = (float) radius / amount; var weight = CalculateGaussian(sigma, 0); horizontalKernels[0].Z = weight; verticalKernels[0].Z = weight; totalWeight += weight; for (int i = 0; i < kernelSize / 2; i++) { int baseIndex = i * 2; int left = baseIndex + 1; int right = baseIndex + 2; weight = CalculateGaussian(sigma, i + 1); totalWeight += weight * 2; horizontalKernels[left].Z = weight; horizontalKernels[right].Z = weight; verticalKernels[left].Z = weight; verticalKernels[right].Z = weight; } // Normalize float inverseTotalWeights = 1.0f / totalWeight; for (int i = 0; i < kernelSize; i++) { horizontalKernels[i].Z *= inverseTotalWeights; verticalKernels[i].Z *= inverseTotalWeights; } dirtyFlags &= ~DirtyFlags.KernelWeights; } }
/// <summary> /// エフェクト (DrawModel.fx) を指定してインスタンスを生成します。 /// </summary> /// <param name="sourceEffect">エフェクト。</param> public DrawModelEffect(Effect sourceEffect) { this.sourceEffect = sourceEffect; worldParameter = sourceEffect.Parameters["World"]; viewParameter = sourceEffect.Parameters["View"]; projectionParameter = sourceEffect.Parameters["Projection"]; lightViewProjectionParameter = sourceEffect.Parameters["LightViewProjection"]; lightDirectionParameter = sourceEffect.Parameters["LightDirection"]; depthBiasParameter = sourceEffect.Parameters["DepthBias"]; ambientColorParameter = sourceEffect.Parameters["AmbientColor"]; textureParameter = sourceEffect.Parameters["Texture"]; shadowMapParameter = sourceEffect.Parameters["ShadowMap"]; basicTechnique = sourceEffect.Techniques["Basic"]; varianceTechnique = sourceEffect.Techniques["Variance"]; dirtyFlags = DirtyFlags.World | DirtyFlags.View | DirtyFlags.Projection | DirtyFlags.LightViewProjection | DirtyFlags.LightDirection | DirtyFlags.DepthBias | DirtyFlags.AmbientColor; }
/// <summary> /// Refreshes the property values. /// </summary> public void Refresh() { this.Dirty = DirtyFlags.All; }
/// <summary> /// Rotates the entity around a certain axis. /// </summary> /// <param name="axis">The axis to rotate around.</param> /// <param name="radians">The angle in radians.</param> public void RotateAround(Vector3 axis, float radians) { // Perform rotation Quaternion rotate; Quaternion.CreateFromAxisAngle(ref axis, radians, out rotate); Quaternion.Multiply(ref _rotation, ref rotate, out _rotation); // Accumulate for numerical errors _rotation.Normalize(); // Force an update of dependent properties _dirtyFlag |= (DirtyFlags.LocalAxis | DirtyFlags.Transform); _propertyChangedFlag |= PropertyChangedFlag.Orientation; }
/// <summary> /// Checks whether transform values have been changed, clears the changelist and fires the appropriate events /// </summary> /// <param name="sender"></param> public void CommitChanges(Component sender = null) { if (this.changes == DirtyFlags.None) return; if (sender == null) sender = this; if (this.eventTransformChanged != null) this.eventTransformChanged(sender, new TransformChangedEventArgs(this, this.changes)); this.changes = DirtyFlags.None; }
/// <summary> /// Resets the current component to its original state. /// </summary> public void Reset() { _scale = Vector3.One; _rotation = Quaternion.Identity; _translation = Vector3.Zero; _dirtyFlag = DirtyFlags.All; _propertyChangedFlag = PropertyChangedFlag.All; }
/// <summary> /// Forces the entity to look at the specified target position. /// </summary> /// <param name="target">The position to look at.</param> /// <param name="up">A vector which specifies the up direction of the entity.</param> public void LookAt(Vector3 target, Vector3 up) { // Calculate the new facing vector Vector3 forward = Vector3.Normalize(target - _translation); // Calculate the rotation axis Vector3 rotationAxis = Vector3.Normalize(Vector3.Cross(Forward, forward)); // Calculate the dot product which will be used to calculate the // rotation angle float dotProduct = Vector3.Dot(Forward, forward); // Ensure that the two forward vectors do not point in opposite // directions if (Math.Abs(dotProduct + 1f) < float.Epsilon) _rotation = new Quaternion(up, MathHelper.Pi); // Ensure that both forward vectors do not point in the same // direction else if (Math.Abs(dotProduct - 1f) < float.Epsilon) _rotation = Quaternion.Identity; // Calculate the absolute rotation to look at the target point else Quaternion.CreateFromAxisAngle(ref rotationAxis, (float)Math.Acos(dotProduct), out _rotation); // Force an update of dependent properties _dirtyFlag |= (DirtyFlags.LocalAxis | DirtyFlags.Transform); _propertyChangedFlag |= PropertyChangedFlag.Orientation; }
/// <summary> /// Resets local position, scaling and rotation. /// </summary> protected override void OnReset() { this.LocalPosition = Vector3.Zero; this.LocalRotation = Quaternion.Identity; this.LocalScaling = Vector3.One; this.Dirty = DirtyFlags.All; }
void SetKernelSize() { if ((dirtyFlags & DirtyFlags.KernelSize) != 0) { kernelSize = radius * 2 + 1; kernelSizeParameter.SetValue(kernelSize); dirtyFlags &= ~DirtyFlags.KernelSize; dirtyFlags |= DirtyFlags.KernelOffsets | DirtyFlags.KernelWeights; } }
public void Move(ref Vector3 movement) { Vector3.Add(ref position, ref movement, out position); dirtyFlags |= DirtyFlags.View; }
/// <summary> /// エフェクトの状態をグラフィックス デバイスへ適用します。 /// </summary> public void Apply() { if ((dirtyFlags & DirtyFlags.World) != 0) { worldParameter.SetValue(World); dirtyFlags &= ~DirtyFlags.World; } if ((dirtyFlags & DirtyFlags.View) != 0) { viewParameter.SetValue(View); dirtyFlags &= ~DirtyFlags.View; } if ((dirtyFlags & DirtyFlags.Projection) != 0) { projectionParameter.SetValue(Projection); dirtyFlags &= ~DirtyFlags.Projection; } if ((dirtyFlags & DirtyFlags.LightViewProjection) != 0) { lightViewProjectionParameter.SetValue(LightViewProjection); dirtyFlags &= ~DirtyFlags.LightViewProjection; } if ((dirtyFlags & DirtyFlags.LightDirection) != 0) { lightDirectionParameter.SetValue(LightDirection); dirtyFlags &= ~DirtyFlags.LightDirection; } if ((dirtyFlags & DirtyFlags.DepthBias) != 0) { depthBiasParameter.SetValue(DepthBias); dirtyFlags &= ~DirtyFlags.DepthBias; } if ((dirtyFlags & DirtyFlags.AmbientColor) != 0) { ambientColorParameter.SetValue(AmbientColor); dirtyFlags &= ~DirtyFlags.AmbientColor; } if ((dirtyFlags & DirtyFlags.Texture) != 0) { textureParameter.SetValue(Texture); dirtyFlags &= ~DirtyFlags.Texture; } if ((dirtyFlags & DirtyFlags.ShadowMap) != 0) { shadowMapParameter.SetValue(ShadowMap); dirtyFlags &= ~DirtyFlags.ShadowMap; } if (ShadowMapEffectForm == ShadowMapEffectForm.Variance) { sourceEffect.CurrentTechnique = varianceTechnique; } else { sourceEffect.CurrentTechnique = basicTechnique; } sourceEffect.CurrentTechnique.Passes[0].Apply(); }
/// <summary> /// Moves the entity the specified amount into the specified /// direction. /// </summary> /// <param name="direction">The direction to move.</param> /// <param name="amount">The amount to move the entity into that direction.</param> /// <param name="space">The coordinate system that should be used to move the entity: local or world space.</param> public void Move(Vector3 direction, float amount, TransformationSpace space) { if (space == TransformationSpace.Local) { Vector3.Transform(ref direction, ref _rotation, out direction); direction.Normalize(); } _translation += direction * amount; _dirtyFlag |= DirtyFlags.Transform; _propertyChangedFlag |= PropertyChangedFlag.Translation; }
public void Rotate(ref Vector3 axis, float angle) { Quaternion rotation; Quaternion.CreateFromAxisAngle(ref axis, angle, out rotation); rotation.Normalize(); Quaternion newOrientation; Quaternion.Concatenate(ref orientation, ref rotation, out newOrientation); orientation = newOrientation; dirtyFlags |= DirtyFlags.View; }
/// <summary> /// Rotates the entity using roll, yaw and pitch values. /// </summary> /// <param name="x">The angle used to roll the entity in radians (rotate around x-Axis).</param> /// <param name="y">The angle used to yaw the entity in radians (rotate around y-Axis).</param> /// <param name="z">The angle used to pitch the entity in radians (rotate around z-Axis).</param> /// <param name="space">The coordinate system that should be used to rotate the entity: local or world space.</param> public void Rotate(float x, float y, float z, TransformationSpace space) { // Perform rotation Quaternion rotate = Quaternion.CreateFromYawPitchRoll(y, x, z); switch (space) { case TransformationSpace.Local: Quaternion.Multiply(ref _rotation, ref rotate, out _rotation); break; case TransformationSpace.World: Quaternion.Multiply(ref rotate, ref _rotation, out _rotation); break; } // Accumulate for numerical errors _rotation.Normalize(); // Force an update of dependent properties _dirtyFlag |= (DirtyFlags.LocalAxis | DirtyFlags.Transform); _propertyChangedFlag |= PropertyChangedFlag.Orientation; }
void UpdateProjection() { if ((dirtyFlags & DirtyFlags.Projection) != 0) { Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, nearClipDistance, farClipDistance, out Projection); dirtyFlags &= ~DirtyFlags.Projection; } }
void UpdateView() { if ((dirtyFlags & DirtyFlags.View) != 0) { Matrix rotation; Matrix.CreateFromQuaternion(ref orientation, out rotation); Matrix transposeRotation; Matrix.Transpose(ref rotation, out transposeRotation); Vector3 translation; Vector3.Transform(ref position, ref transposeRotation, out translation); View = transposeRotation; View.M41 = -translation.X; View.M42 = -translation.Y; View.M43 = -translation.Z; dirtyFlags &= ~DirtyFlags.View; } }
/// <summary> /// Updates the world transformation matrix of the current entity. /// Accounts for the relation to the parent component. /// </summary> protected void UpdateTransform() { // Calculate the local transformation _transform = Matrix.CreateScale(_scale) * Matrix.CreateFromQuaternion(_rotation) * Matrix.CreateTranslation(_translation); // Include the parent transformation if (_parent != null) _transform = _transform * _parent.WorldTransform; // Clear the flag _dirtyFlag &= ~DirtyFlags.Transform; }