/// <summary> /// Constructor /// </summary> /// <param name="instanceCount">creating instance count</param> /// <param name="textureFileName">texture file name</param> public TracerBullets(int id, int instanceCount, string textureFileName, GameSceneNode sceneParent) { this.id = id; textureResource = FrameworkCore.ResourceManager.LoadTexture(textureFileName); bullets = new BulletObject[instanceCount]; // Create instance bullets for (int i = 0; i < bullets.Length; i++) { bullets[i] = new BulletObject(i); } tracerBulletBillboard = new GameBillboard(); tracerBulletBillboard.Create(instanceCount, textureResource.Texture2D, RenderingSpace.World, false); tracerBulletBillboard.SourceBlend = Blend.SourceAlpha; tracerBulletBillboard.DestinationBlend = Blend.One; tracerBulletBillboard.BlendFunction = BlendFunction.Add; tracerBulletBillboard.AlphaBlendEnable = true; tracerBulletBillboard.DepthBufferEnable = true; tracerBulletBillboard.DepthBufferWriteEnable = false; tracerBulletBillboard.DepthBufferFunction = CompareFunction.Less; tracerBulletBillboard.AlphaFunction = CompareFunction.Greater; tracerBulletBillboard.CullMode = CullMode.None; sceneParent.AddChild(tracerBulletBillboard); }
/// <summary> /// by using the particle information, a particle object is created /// and initialized. /// </summary> public void Create() { // Initialize Particle Information Info.Initialize(); Name = sequenceInfo.Name; sceneRoot.RemoveAllChild(false); if (sequenceInfo.TextureFileName.Length > 0) { string resourceFullPath = Path.Combine(resourcePath, sequenceInfo.TextureFileName); GameResourceTexture2D resource = FrameworkCore.ResourceManager.LoadTexture(resourceFullPath); // Set to texture Texture = resource.Texture2D; // Set to texture in TextureSequence if (TextureSequence != null) TextureSequence.SetTexture(Texture); } enableRotate = false; switch (Info.ParticleType) { // PointSprite case ParticleInfo.ParticleObjectType.PointSprite: { scenePointSprite = new GamePointSprite(); scenePointSprite.Create(Info.MaxObjectCount, Texture, RenderingSpace.World, false); scenePointSprite.AlphaBlendEnable = sequenceInfo.AlphaBlendEnable; scenePointSprite.DepthBufferEnable = sequenceInfo.DepthBufferEnable; scenePointSprite.SourceBlend = sequenceInfo.SourceBlend; scenePointSprite.DestinationBlend = sequenceInfo.DestinationBlend; scenePointSprite.BlendFunction = sequenceInfo.BlendFunction; scenePointSprite.DepthBufferEnable = true; scenePointSprite.DepthBufferWriteEnable = false; scenePointSprite.DepthBufferFunction = CompareFunction.Less; scenePointSprite.AlphaFunction = CompareFunction.Greater; scenePointSprite.CullMode = CullMode.None; sceneRoot.AddChild(scenePointSprite); } break; // Sprite3D case ParticleInfo.ParticleObjectType.Sprite: { sceneSprite3D = new GameSprite3D(); sceneSprite3D.Create(Info.MaxObjectCount, Texture, RenderingSpace.World, false); sceneSprite3D.AlphaBlendEnable = sequenceInfo.AlphaBlendEnable; sceneSprite3D.DepthBufferEnable = sequenceInfo.DepthBufferEnable; sceneSprite3D.SourceBlend = sequenceInfo.SourceBlend; sceneSprite3D.DestinationBlend = sequenceInfo.DestinationBlend; sceneSprite3D.BlendFunction = sequenceInfo.BlendFunction; sceneSprite3D.DepthBufferEnable = true; sceneSprite3D.DepthBufferWriteEnable = false; sceneSprite3D.DepthBufferFunction = CompareFunction.Less; sceneSprite3D.AlphaFunction = CompareFunction.Greater; sceneSprite3D.CullMode = CullMode.None; sceneRoot.AddChild(sceneSprite3D); enableRotate = true; // Possible to rotation } break; // Billboard case ParticleInfo.ParticleObjectType.AnchorBillboard: case ParticleInfo.ParticleObjectType.Billboard: { sceneBillboard = new GameBillboard(); sceneBillboard.Create(Info.MaxObjectCount, Texture, RenderingSpace.World, false); sceneBillboard.AlphaBlendEnable = sequenceInfo.AlphaBlendEnable; sceneBillboard.DepthBufferEnable = sequenceInfo.DepthBufferEnable; sceneBillboard.SourceBlend = sequenceInfo.SourceBlend; sceneBillboard.DestinationBlend = sequenceInfo.DestinationBlend; sceneBillboard.BlendFunction = sequenceInfo.BlendFunction; sceneBillboard.DepthBufferEnable = true; sceneBillboard.DepthBufferWriteEnable = false; sceneBillboard.DepthBufferFunction = CompareFunction.Less; sceneBillboard.AlphaFunction = CompareFunction.Greater; sceneBillboard.CullMode = CullMode.None; sceneRoot.AddChild(sceneBillboard); } break; // Mesh case ParticleInfo.ParticleObjectType.Scene: { if( Info.MeshData != null) { int vertextCount = Info.MeshData.Position.Count; int indexCount = 0; if (Info.MeshData.Index != null) indexCount = Info.MeshData.Index.Count; sceneMesh = new GameMesh(); sceneMesh.Create(vertextCount, indexCount, Texture); sceneMesh.AlphaBlendEnable = sequenceInfo.AlphaBlendEnable; sceneMesh.DepthBufferEnable = sequenceInfo.DepthBufferEnable; sceneMesh.SourceBlend = sequenceInfo.SourceBlend; sceneMesh.DestinationBlend = sequenceInfo.DestinationBlend; sceneMesh.BlendFunction = sequenceInfo.BlendFunction; sceneMesh.DepthBufferEnable = true; sceneMesh.DepthBufferWriteEnable = false; sceneMesh.DepthBufferFunction = CompareFunction.Less; sceneMesh.AlphaFunction = CompareFunction.Greater; sceneMesh.CullMode = CullMode.None; // Has position data if (Info.MeshData.HasPosition ) { sceneMesh.SetPositionData( Info.MeshData.Position.ToArray()); } // Has color data if (Info.MeshData.HasColor ) { sceneMesh.SetColorData( Info.MeshData.Color.ToArray()); } // Has texture coordinate data if (Info.MeshData.HasTextureCoord ) { sceneMesh.SetTextureCoordData( Info.MeshData.TextureCoord.ToArray()); } // Has index data if (Info.MeshData.HasIndex ) { sceneMesh.SetIndexData(Info.MeshData.Index.ToArray()); } // Use VB and IB if (sceneMesh.userPrimitive == false) { sceneMesh.BindVertexBuffer(); sceneMesh.BindIndexBuffer(); } sceneRoot.AddChild(sceneMesh); } enableRotate = true; // can rotate } break; } SetSceneEnable(false); // Particle Object particleObjectList.Clear(); for (int i = 0; i < Info.MaxObjectCount; i++) { ParticleObject obj = new ParticleObject(); particleObjectList.Add(obj); } // Emit Right & Up Vector { Matrix mtx = Helper3D.MakeMatrixWithAt(Info.EmitDirection, Info.UpVector); emitRight = mtx.Right; emitUp = mtx.Up; } // Up Right & At Vector { Matrix mtx = Helper3D.MakeMatrixWithUp(Info.UpVector, Matrix.Identity.Forward); upRight = mtx.Right; upAt = mtx.Forward; } posArgCount = 0; for (int i = ParticleInfo.FuncCount - 1; i >= 0; i--) { if (Info.PositionFunc[i] != ParticleInfo.FuncType.None) { posArgCount = i + 1; break; } } scaleArgCount = 0; for (int i = ParticleInfo.FuncCount - 1; i >= 0; i--) { if (Info.ScaleFunc[i] != ParticleInfo.FuncType.None) { scaleArgCount = i + 1; break; } } if( Info.IsPositionStyle( ParticleInfo.ParamStyles.Interpolate)) positionInterpolate = KeyFrameTable.Interpolation.Lerp; else positionInterpolate = KeyFrameTable.Interpolation.None; if (Info.IsScaleStyle(ParticleInfo.ParamStyles.Interpolate)) scaleInterpolate = KeyFrameTable.Interpolation.Lerp; else scaleInterpolate = KeyFrameTable.Interpolation.None; if (Info.IsColorStyle(ParticleInfo.ParamStyles.Interpolate)) colorInterpolate = KeyFrameTable.Interpolation.Lerp; else colorInterpolate = KeyFrameTable.Interpolation.None; rObjectLifeTime = 1.0f / Info.ObjectLifeTime; isStarting = false; isStopping = false; }