public void RunScript() { GameObject newGameObject = new GameObject(); newGameObject.Position = (new CatVector3(Vector3.Zero)); ModelComponent modelComponent = new ModelComponent(newGameObject); newGameObject.AddComponent(modelComponent); QuadRender quadRender = new QuadRender(newGameObject); newGameObject.AddComponent(quadRender); Mgr <Scene> .Singleton._gameObjectList.AddGameObject(newGameObject); }
public override void Update(int timeLastFrame) { base.Update(timeLastFrame); QuadRender quadRender = (QuadRender)m_gameObject.GetComponent(typeof(QuadRender)); if (quadRender == null) { Console.WriteLine("Error! BackgroundController needs QuadRender Component."); return; } float quadWidth = 0.0f; if (UseThisWidth) { quadWidth = PictureWidth; } else { quadWidth = quadRender.Size.X; } float viewWidth = Mgr <Camera> .Singleton.maxWidth; float cameraX = Mgr <Camera> .Singleton.CameraPosition.X; float activeWidth = quadWidth - viewWidth; Vector2 sceneXBound = Mgr <Scene> .Singleton._XBound; float cameraPositionPercent = (cameraX - sceneXBound.X) / (sceneXBound.Y - sceneXBound.X); if (!UseThisWidth) { m_gameObject.Position = new Vector3(cameraX + activeWidth / 2.0f - cameraPositionPercent * activeWidth, m_gameObject.Position.Y, m_gameObject.Position.Z); } else { m_gameObject.Position = new Vector3(pictureOffsetX + cameraX + activeWidth / 2.0f - cameraPositionPercent * activeWidth, m_gameObject.Position.Y, m_gameObject.Position.Z); } if (m_yAdjust) { Debug.Assert(false, "Rewrite this"); } }
public void RunScript() { if (Mgr <CatProject> .Singleton == null) { return; } // ask for model string modelName = ResourceSelectorWindow.SelectResource(ResourceSelectorWindow.ObserveType.Model, ""); if (modelName == "") { return; } CatModel model = Mgr <CatProject> .Singleton.modelList1.GetModel(modelName); if (model != null) { CatMaterial material = model.GetMaterial(); if (material == null || !material.HasParameter("DiffuseMap")) { // TODO: give warning return; } } else { return; } // ask for texture string textureName = ResourceSelectorWindow.SelectResource(ResourceSelectorWindow.ObserveType.Texture, ""); if (textureName == "") { return; } Texture2D texture = Mgr <CatProject> .Singleton.contentManger.Load <Texture2D>("image\\" + textureName); if (texture == null) { return; } GameObject newGameObject = new GameObject(); if (Mgr <Camera> .Singleton != null) { newGameObject.Position = new Vector3(Mgr <Camera> .Singleton.TargetPosition.X, Mgr <Camera> .Singleton.TargetPosition.Y, 0.0f); } else { newGameObject.Position = Vector3.Zero; } ModelComponent modelComponent = new ModelComponent(newGameObject); newGameObject.AddComponent(modelComponent); modelComponent.Model = model; modelComponent.GetCatModelInstance().GetMaterial().SetParameter("DiffuseMap", new CatTexture(texture)); QuadRender quadRender = new QuadRender(newGameObject); newGameObject.AddComponent(quadRender); quadRender.OptimalSize = true; Mgr <Scene> .Singleton._gameObjectList.AddGameObject(newGameObject); }
public override void Update(int timeLastFrame) { base.Update(timeLastFrame); ModelComponent modelComponent = (ModelComponent)m_gameObject.GetComponent(typeof(ModelComponent).ToString()); if (modelComponent == null) { Console.Out.WriteLine("No ModelComponent for Animator."); return; } Animation animation = modelComponent.Model.GetAnimation(); QuadRender quadRender = (QuadRender)m_gameObject.GetComponent(typeof(QuadRender).ToString()); float width_per_frame = 1.0f / animation.m_tiltUV.X; float height_per_frame = 1.0f / animation.m_tiltUV.Y; if (m_isPlaying) { m_timeLastFrame += timeLastFrame; } if (m_timeLastFrame >= m_millionSecondPreFrame) { m_timeLastFrame -= m_millionSecondPreFrame; AnimationClip current_clip = animation.getAnimationClip(m_currentAnimationName); if (current_clip == null) { Console.WriteLine("Error! Can not find animation clip: " + m_currentAnimationName); return; } if (current_clip.m_mode == AnimationClip.PlayMode.PINGPONG) { if (!m_isPong) // ping { if (m_currentIndex < current_clip.m_endIndex) { ++m_currentIndex; } else { --m_currentIndex; m_isPong = true; } } else { // pong if (m_currentIndex > current_clip.m_beginIndex) { --m_currentIndex; } else { ++m_currentIndex; m_isPong = false; } } } else { if (m_currentIndex < current_clip.m_endIndex) { ++m_currentIndex; } else { if (current_clip.m_mode == AnimationClip.PlayMode.CLAMP) { m_isPlaying.SetValue(false); } else if (current_clip.m_mode == AnimationClip.PlayMode.LOOP) { m_currentIndex = current_clip.m_beginIndex; } else if (current_clip.m_mode == AnimationClip.PlayMode.STOP) { m_currentIndex = current_clip.m_beginIndex; m_isPlaying.SetValue(false); } } } } Point current_nxm = new Point(); current_nxm.X = m_currentIndex % animation.m_tiltUV.X; current_nxm.Y = m_currentIndex / animation.m_tiltUV.X; quadRender.m_vertex[0].TextureCoordinate.X = current_nxm.X * width_per_frame; quadRender.m_vertex[0].TextureCoordinate.Y = (current_nxm.Y + 1) * height_per_frame; quadRender.m_vertex[1].TextureCoordinate.X = current_nxm.X * width_per_frame; quadRender.m_vertex[1].TextureCoordinate.Y = current_nxm.Y * height_per_frame; quadRender.m_vertex[2].TextureCoordinate.X = (current_nxm.X + 1) * width_per_frame; quadRender.m_vertex[2].TextureCoordinate.Y = (current_nxm.Y + 1) * height_per_frame; quadRender.m_vertex[3].TextureCoordinate.X = (current_nxm.X + 1) * width_per_frame; quadRender.m_vertex[3].TextureCoordinate.Y = current_nxm.Y * height_per_frame; }