public BillboardsSystem(ContentManager content, BillboardMode mode, Model model, Matrix[] instancedModelBones, Matrix[] instanceTransforms, Vector3 position, Vector3 rotation, Vector3 scale, Vector3 LightDirection, Vector3 LightColor, Vector3 AmbientLight, GraphicsDevice graphicsDevice) { this.model = model; modelTransforms = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(modelTransforms); buildBoundingSphere(); this.position = position; this.rotation = rotation; this.scale = scale; this.graphicsDevice = graphicsDevice; this.instancedModelBones = instancedModelBones; this.instanceTransforms = instanceTransforms; // this.LightDirection = LightDirection; // this.LightColor = LightColor; // this.AmbientColor = AmbientLight; this.mode = mode; effect = content.Load<Effect>("Effects//AlphaBlending"); _effect = content.Load<Effect>("shaders//LPPMainEffect"); //SetModelEffect(effect, false); }
public Billboard(Vector3D position, Size size, Material material, BillboardMode billboardMode = BillboardMode.CameraFacing) : base(position) { mode = billboardMode; planeQuad = new PlaneQuad(size, material); OnDraw<BillboardRenderer>(); }
public Billboard(Vector3D position, Size size, Material material, BillboardMode billboardMode = BillboardMode.CameraFacing) : base(position) { mode = billboardMode; planeQuad = new PlaneQuad(size, material); OnDraw <BillboardRenderer>(); }
public void SetDifferentBillBoardModes(BillboardMode mode) { var emitterData = GetEmitterData(logo); emitterData.BillboardMode = mode; emitterData.DoParticlesTrackEmitter = true; new ParticleEmitter(emitterData, Vector3D.Zero); Assert.DoesNotThrow(() => AdvanceTimeAndUpdateEntities()); }
public SpriteAnimationComponent(SpriteRenderer renderer, SpriteAnimation animation, bool unscaled, BillboardMode billboard) { _component = new CachedUnityComponent <SpriteRenderer>(renderer); Animation = animation; Unscaled = unscaled; Billboard = billboard; CurrentFrameIndex = 0; UpdateFrame(Unscaled ? TimeManager.TimeUnscaled : TimeManager.Time); }
public SpriteAnimationComponent(SerializationInfo info, StreamingContext context) { _component = info.GetValue(nameof(_component), _component); Unscaled = info.GetValue(nameof(Unscaled), Unscaled); Billboard = info.GetValue(nameof(Billboard), Billboard); NextUpdateTime = info.GetValue(nameof(NextUpdateTime), NextUpdateTime); CurrentFrameIndex = info.GetValue(nameof(CurrentFrameIndex), CurrentFrameIndex); LastAngleHeight = info.GetValue(nameof(LastAngleHeight), LastAngleHeight); ItemPool.LoadAsset <SpriteAnimation>(info.GetValue(nameof(Animation), ""), a => Animation = a); }
/// <summary> /// 個々のパラメータを細かに設定させるタイプのコンストラクタにしているが、 /// 構造体にまとめてもいいかもしれない。 /// </summary> /// <param name="position">エミッタの中心位置。パーティクルの出現位置</param> /// <param name="texture"></param> /// <param name="particleNum"></param> /// <param name="particleSize"></param> /// <param name="lifespan">パーティクルの寿命[second]</param> /// <param name="fadeInTime">フェードインする時間[second]。0ならば即座に描画される</param> /// <param name="movementType">移動のタイプ</param> /// <param name="speed">速さ</param> /// <param name="initialize">すぐに初期化するかどうか</param> public ExplosionParticleEmitter(GraphicsDevice graphicsDevice, ContentManager content, Vector3 position, Texture2D texture, int particleNum, Vector2 particleSize, float lifespan, float fadeInTime, int movementType, float speed, BillboardMode mode, bool initialize) : base(graphicsDevice, content, texture, position, particleNum, particleSize, lifespan, fadeInTime, mode, initialize) { //emitNumPerFrame = 100;//50; this.Type = movementType; this.Speed = speed; //speed = 4.0f * 5; //MoveParticle(); }
//ncrunch: no coverage start private void AlignBillboardDirection(BillboardMode mode) { if ((mode & BillboardMode.UpAxis) != 0) AlignToZAxis(); else if ((mode & BillboardMode.FrontAxis) != 0) AlignToYAxis(); else if ((mode & BillboardMode.RightAxis) != 0) AlignToXAxis(); else if ((mode & BillboardMode.Ground) != 0) AlignToXYPlane(); }
public ProjectileTemplate(DataEntry data) { Data = data; ID = data.ID; Type = data.TryGetValue("Type", data.ID); Movement = data.TryGetValue("Movement", "Simple"); Speed = data.TryGetValue("Speed", 0f); Rotation = data.TryGetValue("Rotation", 0f); CollisionDistance = data.TryGetValue("CollisionDistance", 0.25f); Size = data.TryGetValue("Size", 0f); Length = data.TryGetValue("Length", 0f); Timeout = data.TryGetValue(DatabaseFields.Timeout, _defaultTimeout.Value); GlowPower = data.TryGetValue("GlowPower", 0f); TrailAmount = data.TryGetValue("TrailAmount", 0); TrailFrequency = data.TryGetValue("TrailFrequency", 0f); TrailColor = data.TryGetValue("TrailColor", Color.black); Radius = ParseUtilities.TryParseEnum(data.GetValue <string>("Radius"), ImpactRadiusTypes.Single); Billboard = ParseUtilities.TryParseEnum(data.GetValue <string>("Billboard"), BillboardMode.FaceCamYDiff); MainColor = data.TryGetValue("MainColor", Color.white); OffsetColor = data.TryGetValue("OffsetColor", Color.white); PoolSize = data.TryGetValue("PoolSize", _defaultPool); var afx = data.GetValue <string>(DatabaseFields.ActionFx); if (!string.IsNullOrEmpty(afx)) { ActionFx = ItemPool.LoadAsset <ActionFx>(UnityDirs.ActionFx, afx); } var model = data.GetValue <string>(DatabaseFields.Model); switch (Type) { default: case "Simple": break; case "SpherePhysics": if (!string.IsNullOrEmpty(model)) { Animation = ItemPool.LoadAsset <SpriteAnimation>(UnityDirs.ActionSpawn, model); } break; case "VolumeLaser": Prefab = model; break; } Components = data.Get(DatabaseFields.Components) as DataList; }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { fCamera.Update(gameTime); float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds; if (fBillboard1 == null) { InitBillboard(); } if (this.Manager.KeyPressed(Keys.V)) { fUseVertexBuffer = !fUseVertexBuffer; fBillboard1.UseVertexBuffer = fBillboard2.UseVertexBuffer = fBillboard3.UseVertexBuffer = fUseVertexBuffer; } else if (this.Manager.KeyPressed(Keys.H)) { fHalted = !fHalted; } else if (this.Manager.KeyPressed(Keys.M)) { if (fDrawMode == BillboardMode.PointList) { fDrawMode = BillboardMode.Quad; } else { fDrawMode = BillboardMode.PointList; } fBillboard1.Mode = fBillboard2.Mode = fBillboard3.Mode = fDrawMode; InitBillboard(); } else if (this.Manager.KeyPressed(Keys.T)) { if (fTextureMode == TextureMode.Faces) { fTextureMode = TextureMode.Test; } else { fTextureMode = TextureMode.Faces; } } base.Update(gameTime); }
private void UpdateTransformMatrix(Particle particle, BillboardMode mode) { lastFacingDirection = inverseView.Translation - particle.Position; lastCameraUp = inverseView.Up; AlignBillboardDirection(mode); lastCameraUp.Normalize(); lastFacingDirection.Normalize(); Vector3D right = Vector3D.Cross(lastCameraUp, lastFacingDirection); Vector3D up = Vector3D.Cross(lastFacingDirection, right); lastParticleTransform = Matrix.Identity; lastParticleTransform.Right = -right; lastParticleTransform.Up = lastFacingDirection; lastParticleTransform.Forward = up; lastParticleTransform *= Matrix.CreateRotationZYX(lastParticleTransform.Forward.X, lastParticleTransform.Forward.Y, lastParticleTransform.Forward.Z); lastParticleTransform.Translation = particle.Position; }
//ncrunch: no coverage start private void AlignBillboardDirection(BillboardMode mode) { if ((mode & BillboardMode.UpAxis) != 0) { AlignToZAxis(); } else if ((mode & BillboardMode.FrontAxis) != 0) { AlignToYAxis(); } else if ((mode & BillboardMode.RightAxis) != 0) { AlignToXAxis(); } else if ((mode & BillboardMode.Ground) != 0) { AlignToXYPlane(); } }
public static void Apply(this BillboardMode mode, Transform transform, bool backwards) { switch (mode) { case BillboardMode.ForceUp: case BillboardMode.TrUp: var lookPos = transform.position + Game.SpriteCamera.transform.rotation * Vector3.forward; transform.LookAt(backwards ? lookPos : -lookPos, mode == BillboardMode.TrUp ? transform.up : Game.SpriteCamera.transform.rotation * Vector3.up); break; case BillboardMode.CamFwd: transform.forward = backwards ? -Game.SpriteCamera.transform.forward : Game.SpriteCamera.transform.forward; break; case BillboardMode.NoYAxis: Vector3 viewDirection = new Vector3(Game.SpriteCamera.transform.forward.x, 0, Game.SpriteCamera.transform.forward.z); transform.LookAt(transform.position + (backwards ? viewDirection : -viewDirection)); break; case BillboardMode.CamRot: transform.rotation = backwards ? Quaternion.Inverse(Game.SpriteCamera.transform.rotation) : Game.SpriteCamera.transform.rotation; break; case BillboardMode.CamRot45: case BillboardMode.CamRot90: case BillboardMode.CamRot60: float factor = -45f; switch (mode) { case BillboardMode.CamRot90: factor = -90f; break; case BillboardMode.CamRot60: factor = -60f; break; } var rot = Quaternion.LookRotation(Game.SpriteCamera.transform.forward) * Quaternion.Euler(factor, 0, 0); transform.rotation = backwards ? Quaternion.Inverse(rot) : rot; break; } }
protected override void LoadData(Stream fileData) { var emitterData = (ParticleEmitterData)new BinaryReader(fileData).Create(); SpawnInterval = emitterData.SpawnInterval; LifeTime = emitterData.LifeTime; MaximumNumberOfParticles = emitterData.MaximumNumberOfParticles; StartVelocity = emitterData.StartVelocity; Acceleration = emitterData.Acceleration; Size = emitterData.Size; StartRotation = emitterData.StartRotation; Color = emitterData.Color; ParticleMaterial = emitterData.ParticleMaterial; ParticlesPerSpawn = emitterData.ParticlesPerSpawn; RotationSpeed = emitterData.RotationSpeed; PositionType = emitterData.PositionType; StartPosition = emitterData.StartPosition; ParticlesPerSpawn = emitterData.ParticlesPerSpawn; DoParticlesTrackEmitter = emitterData.DoParticlesTrackEmitter; BillboardMode = emitterData.BillboardMode; }
/// <summary> /// BillboardModeをパラメータに含めたコンストラクタ。 /// 試験用としてコンストラクタを分けたが後で上とまとめても良い。 /// </summary> public ParticleEmitter(GraphicsDevice graphicsDevice, ContentManager content, Texture2D texture, Vector3 position, int particleNum, Vector2 particleSize, float lifespan, float fadeInTime, BillboardMode mode, bool initialize) { this.ParticleNum = particleNum; this.ParticleSize = particleSize; this.Lifespan = lifespan; this.graphicsDevice = graphicsDevice; this.Texture = texture; this.Position = position; this.FadeInTime = fadeInTime; this.Mode = mode; effect = content.Load<Effect>("Billboard\\ParticleEffect"); // 基本的にはすぐに初期化。 // Cloneして使うときなどはfalseを与えておく。 if (initialize) { Initialize(); } }
protected override void LoadData(Stream fileData) { var emitterData = (ParticleEmitterData) new BinaryReader(fileData).Create(); SpawnInterval = emitterData.SpawnInterval; LifeTime = emitterData.LifeTime; MaximumNumberOfParticles = emitterData.MaximumNumberOfParticles; StartVelocity = emitterData.StartVelocity; Acceleration = emitterData.Acceleration; Size = emitterData.Size; StartRotation = emitterData.StartRotation; Color = emitterData.Color; ParticleMaterial = emitterData.ParticleMaterial; ParticlesPerSpawn = emitterData.ParticlesPerSpawn; RotationSpeed = emitterData.RotationSpeed; PositionType = emitterData.PositionType; StartPosition = emitterData.StartPosition; ParticlesPerSpawn = emitterData.ParticlesPerSpawn; DoParticlesTrackEmitter = emitterData.DoParticlesTrackEmitter; BillboardMode = emitterData.BillboardMode; }
public void LoadFromFile(Stream fileData) { if (fileData.Length == 0) { throw new EmptyEmitterDataFileGiven(); } var reader = new BinaryReader(fileData); reader.BaseStream.Position = 0; string shortName = reader.ReadString(); var dataVersion = reader.ReadBytes(4); bool justSaveName = reader.ReadBoolean(); bool noFieldData = reader.ReadBoolean(); string name = reader.ReadString(); reader.BaseStream.Position++; SpawnInterval = reader.ReadSingle(); LifeTime = reader.ReadSingle(); MaximumNumberOfParticles = reader.ReadInt32(); StartVelocity = ReadRangeOfVectors(reader); Acceleration = ReadRangeOfVectors(reader); Size = ReadRangeOfSizes(reader); StartRotation = ReadRangeOfRanges(reader); RotationSpeed = ReadRangeOfRanges(reader); Color = ReadRangeOfColors(reader); reader.ReadBoolean(); var materialType = reader.ReadString(); var justName = reader.ReadBoolean(); ParticleMaterial = justName ? ContentLoader.Load <Material>(reader.ReadString()) : LoadCustomMaterial(reader); PositionType = (ParticleEmitterPositionType)reader.ReadInt32(); StartPosition = ReadRangeOfVectors(reader); ParticlesPerSpawn = ReadRangeOfRanges(reader); DoParticlesTrackEmitter = reader.ReadBoolean(); BillboardMode = (BillboardMode)reader.ReadInt32(); }
public NiBillboardNode(BinaryReader reader, NiFile file) : base(reader, file) { Mode = (BillboardMode)reader.ReadUInt16(); }
public SpriteBillboardComponent(SerializationInfo info, StreamingContext context) { Facing = info.GetValue(nameof(Facing), Facing); Billboard = info.GetValue(nameof(Billboard), Billboard); Backwards = info.GetValue(nameof(Backwards), Backwards); }
public SpriteBillboardComponent(SpriteFacing facing, bool backwards, BillboardMode billboard) { Facing = facing; Backwards = backwards; Billboard = billboard; }
public void LoadFromFile(Stream fileData) { if (fileData.Length == 0) throw new EmptyEmitterDataFileGiven(); var reader = new BinaryReader(fileData); reader.BaseStream.Position = 0; string shortName = reader.ReadString(); var dataVersion = reader.ReadBytes(4); bool justSaveName = reader.ReadBoolean(); bool noFieldData = reader.ReadBoolean(); string name = reader.ReadString(); reader.BaseStream.Position++; SpawnInterval = reader.ReadSingle(); LifeTime = reader.ReadSingle(); MaximumNumberOfParticles = reader.ReadInt32(); StartVelocity = ReadRangeOfVectors(reader); Acceleration = ReadRangeOfVectors(reader); Size = ReadRangeOfSizes(reader); StartRotation = ReadRangeOfRanges(reader); RotationSpeed = ReadRangeOfRanges(reader); Color = ReadRangeOfColors(reader); reader.ReadBoolean(); var materialType = reader.ReadString(); var justName = reader.ReadBoolean(); ParticleMaterial = justName ? ContentLoader.Load<Material>(reader.ReadString()) : LoadCustomMaterial(reader); PositionType = (ParticleEmitterPositionType)reader.ReadInt32(); StartPosition = ReadRangeOfVectors(reader); ParticlesPerSpawn = ReadRangeOfRanges(reader); DoParticlesTrackEmitter = reader.ReadBoolean(); BillboardMode = (BillboardMode)reader.ReadInt32(); }
public NiBillboardNode() { billboardMode = (BillboardMode)0; }
public static void Apply(this BillboardMode mode, Transform transform, bool backwards, ref float lastAngleHeight) { var position = transform.position; Vector3 lookPosition = Vector3.zero; switch (mode) { case BillboardMode.ForceUp: case BillboardMode.TrUp: lookPosition = position + Game.SpriteCamera.transform.rotation * Vector3.forward; //transform.LookAt(backwards ? lookPos : -lookPos, mode == BillboardMode.TrUp ? transform.up : Game.SpriteCamera.transform.rotation * Vector3.up); break; case BillboardMode.CamFwd: transform.forward = backwards ? -Game.SpriteCamera.transform.forward : Game.SpriteCamera.transform.forward; break; case BillboardMode.NoYAxis: Vector3 viewDirection = new Vector3(Game.SpriteCamera.transform.forward.x, 0, Game.SpriteCamera.transform.forward.z); transform.LookAt(position + (backwards ? viewDirection : -viewDirection)); break; case BillboardMode.CamRot: transform.rotation = backwards ? Quaternion.Inverse(Game.SpriteCamera.transform.rotation) : Game.SpriteCamera.transform.rotation; break; case BillboardMode.FaceCam: lookPosition = Game.SpriteCamera.transform.position; lookPosition.y = position.y; //transform.LookAt(position); //transform.rotation = Quaternion.LookRotation(position - position); break; case BillboardMode.FaceCamYDiff: lookPosition = Game.SpriteCamera.transform.position; var yHeight = transform.parent.position.y; var yDiff = Mathf.Abs(yHeight - lookPosition.y); var targetY = yDiff < _yMinDiff ? yHeight : lookPosition.y; lastAngleHeight = Mathf.MoveTowards(lastAngleHeight, targetY, _changeSpeed * TimeManager.DeltaUnscaled); lookPosition.y = lastAngleHeight; //transform.LookAt(camPos); //transform.rotation = Quaternion.LookRotation(camPos - transform.position); break; case BillboardMode.CamRot45: case BillboardMode.CamRot90: case BillboardMode.CamRot60: float factor = -45f; switch (mode) { case BillboardMode.CamRot90: factor = -90f; break; case BillboardMode.CamRot60: factor = -60f; break; } var rot = Quaternion.LookRotation(Game.SpriteCamera.transform.forward) * Quaternion.Euler(factor, 0, 0); transform.rotation = backwards ? Quaternion.Inverse(rot) : rot; break; } Vector3 dir = !backwards ? (lookPosition - position) : (position - lookPosition); switch (mode) { case BillboardMode.ForceUp: case BillboardMode.FaceCam: case BillboardMode.FaceCamYDiff: transform.rotation = Quaternion.LookRotation(dir); break; case BillboardMode.TrUp: transform.rotation = Quaternion.LookRotation(dir, transform.up); break; } }