public virtual AnimationFrame Calculate(float dt, AnimationFrame cur, AnimationFrame next) { m_CurBlendValue += (dt / m_Duration); m_Reciprocal = 1 - m_CurBlendValue; return cur; }
virtual public AnimationFrame Calculate(float dt, AnimationFrame cur, AnimationFrame next) { m_CurBlendValue += (dt / m_Duration); m_Reciprocal = 1 - m_CurBlendValue; return(cur); }
public static void Update(float dt) { AnimationFrame currentFrame = null; AnimationFrame resultFrame = null; AnimationFrame nextFrame = null; switch (m_State) { case State.Animating: // animating so we only need to worry about the current ani m_CurrentAnimation.Update(dt); resultFrame = m_CurrentAnimation.GetCurrentFrame(); if (m_CurrentAnimation.Finished) { // get the blender to use m_Blender = GetNextBlender(); m_Blender.Start(); // get the next animation we can blend to m_NextAnimation = GetNextAnimation(); m_NextAnimation.Start(); m_State = State.Blending; } break; case State.Blending: // update both anis since we're blending between the two m_CurrentAnimation.Update(dt); m_NextAnimation.Update(dt); currentFrame = m_CurrentAnimation.GetCurrentFrame(); nextFrame = m_NextAnimation.GetCurrentFrame(); resultFrame = m_Blender.Calculate(dt, currentFrame, nextFrame); if (m_Blender.Finished) { // done blending the current to next. Next now is current. m_State = State.Animating; m_CurrentAnimation.Stop(); m_CurrentAnimation = m_NextAnimation; } break; } // let the dome know about the new frame Dome.SetFrame(resultFrame); }
public static void SetFrame(AnimationFrame nextFrame) { int bufferIndex = 0; byte[] buffer = new byte[TOTAL_LEDS_DOME * 3]; //channel 0 for (int rib = 0; rib < Dome.NUM_RIBS / 2; ++rib) { for (int row = 0; row < Dome.LEDS_PER_RIB; ++row) { Color newColor = nextFrame.GetDomeLEDColor(rib, row); if (rib % 2 == 0) bufferIndex = (rib * Dome.LEDS_PER_RIB + row) * 3; else bufferIndex = (rib * Dome.LEDS_PER_RIB + (Dome.LEDS_PER_RIB - row - 1)) * 3; buffer[bufferIndex + 0] = newColor.B; buffer[bufferIndex + 1] = newColor.G; buffer[bufferIndex + 2] = newColor.R; } } //channel 1 for (int rib = Dome.NUM_RIBS - 1; rib >= Dome.NUM_RIBS / 2; --rib) { for (int row = 0; row < Dome.LEDS_PER_RIB; ++row) { Color newColor = nextFrame.GetDomeLEDColor(rib, row); if (rib % 2 == 1) bufferIndex = ((Dome.NUM_RIBS - rib + 17) * Dome.LEDS_PER_RIB + row) * 3; else bufferIndex = ((Dome.NUM_RIBS - rib + 17) * Dome.LEDS_PER_RIB + (Dome.LEDS_PER_RIB - row - 1)) * 3; buffer[bufferIndex + 0] = newColor.B; buffer[bufferIndex + 1] = newColor.G; buffer[bufferIndex + 2] = newColor.R; } } if (m_RenderEnabled) { RenderLEDs(nextFrame.GetDomeLEDColor, SetRendererDomeLight, Dome.NUM_RIBS, Dome.LEDS_PER_RIB); RenderLEDs(nextFrame.GetPendantLEDColor, SetRendererPendantLight, Dome.NUM_PENDANTS_MAX, Dome.LEDS_PER_PENDANT_MAX); RenderLEDs(nextFrame.GetSatelliteLEDColor, SetRendererSatelliteLight, Dome.NUM_SATELLITES, Dome.LEDS_PER_SATELLITE); // Send frame-light data to the simulator: m_VB.SetData(m_Lights); } // Send frame-light data to the Jellyfish light controller: //MainForm.ConsoleWriteLine("."); if (m_Socket == null && m_AttemptConnect) { MainForm.ConsoleWriteLine("Connecting to dome..."); try { m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); m_Socket.Connect(JELLYBRAIN_ADDRESS, 80); } catch (Exception e) { m_Socket.Dispose(); m_Socket = null; m_AttemptConnect = false; e.ToString(); } } if (m_Socket != null) { byte[] recvBuffer = new byte[16]; m_Socket.Send(buffer); m_Socket.Receive(recvBuffer, 1, 0); } //if (m_ShowOnce) //{ // m_ShowOnce = false; // //SatelliteDevices.UpdateSatellites(nextFrame.SatelliteData, nextFrame.PendantData); //} }
public static void SetFrame(AnimationFrame nextFrame) { int index = 0; int bufferIndex = 0; byte[] buffer = new byte[TOTAL_LEDS * 3]; //channel 0 for (int rib = 0; rib < Dome.NUM_RIBS / 2; ++rib) { for (int row = 0; row < Dome.LEDS_PER_RIB; ++row) { Color newColor = nextFrame.GetLedColor(rib, row); if (m_RenderEnabled) { index = (rib * Dome.LEDS_PER_RIB + row) * 4; m_Lights[index + 0].Color = newColor; m_Lights[index + 1].Color = newColor; m_Lights[index + 2].Color = newColor; m_Lights[index + 3].Color = newColor; } if (rib % 2 == 0) { bufferIndex = (rib * Dome.LEDS_PER_RIB + row) * 3; } else { bufferIndex = (rib * Dome.LEDS_PER_RIB + (Dome.LEDS_PER_RIB - row - 1)) * 3; } buffer[bufferIndex + 0] = newColor.B; buffer[bufferIndex + 1] = newColor.G; buffer[bufferIndex + 2] = newColor.R; } } //channel 1 for (int rib = Dome.NUM_RIBS - 1; rib >= Dome.NUM_RIBS / 2; --rib) { for (int row = 0; row < Dome.LEDS_PER_RIB; ++row) { Color newColor = nextFrame.GetLedColor(rib, row); if (m_RenderEnabled) { index = (rib * Dome.LEDS_PER_RIB + row) * 4; m_Lights[index + 0].Color = newColor; m_Lights[index + 1].Color = newColor; m_Lights[index + 2].Color = newColor; m_Lights[index + 3].Color = newColor; } if (rib % 2 == 1) { bufferIndex = ((Dome.NUM_RIBS - rib + 17) * Dome.LEDS_PER_RIB + row) * 3; } else { bufferIndex = ((Dome.NUM_RIBS - rib + 17) * Dome.LEDS_PER_RIB + (Dome.LEDS_PER_RIB - row - 1)) * 3; } buffer[bufferIndex + 0] = newColor.B; buffer[bufferIndex + 1] = newColor.G; buffer[bufferIndex + 2] = newColor.R; } } if (m_Socket != null) { byte[] recvBuffer = new byte[16]; m_Socket.Send(buffer); m_Socket.Receive(recvBuffer, 1, 0); } if (m_RenderEnabled) { m_VB.SetData(m_Lights); } }
public static void SetFrame(AnimationFrame nextFrame) { int index = 0; int bufferIndex = 0; byte[] buffer = new byte[TOTAL_LEDS * 3]; //channel 0 for (int rib = 0; rib < Dome.NUM_RIBS / 2; ++rib) { for (int row = 0; row < Dome.LEDS_PER_RIB; ++row) { Color newColor = nextFrame.GetLedColor(rib, row); if (m_RenderEnabled) { index = (rib * Dome.LEDS_PER_RIB + row) * 4; m_Lights[index + 0].Color = newColor; m_Lights[index + 1].Color = newColor; m_Lights[index + 2].Color = newColor; m_Lights[index + 3].Color = newColor; } if (rib % 2 == 0) bufferIndex = (rib * Dome.LEDS_PER_RIB + row) * 3; else bufferIndex = (rib * Dome.LEDS_PER_RIB + (Dome.LEDS_PER_RIB - row - 1)) * 3; buffer[bufferIndex + 0] = newColor.B; buffer[bufferIndex + 1] = newColor.G; buffer[bufferIndex + 2] = newColor.R; } } //channel 1 for (int rib = Dome.NUM_RIBS - 1; rib >= Dome.NUM_RIBS / 2; --rib) { for (int row = 0; row < Dome.LEDS_PER_RIB; ++row) { Color newColor = nextFrame.GetLedColor(rib, row); if (m_RenderEnabled) { index = (rib * Dome.LEDS_PER_RIB + row) * 4; m_Lights[index + 0].Color = newColor; m_Lights[index + 1].Color = newColor; m_Lights[index + 2].Color = newColor; m_Lights[index + 3].Color = newColor; } if (rib % 2 == 1) bufferIndex = ((Dome.NUM_RIBS - rib + 17) * Dome.LEDS_PER_RIB + row) * 3; else bufferIndex = ((Dome.NUM_RIBS - rib + 17) * Dome.LEDS_PER_RIB + (Dome.LEDS_PER_RIB - row - 1)) * 3; buffer[bufferIndex + 0] = newColor.B; buffer[bufferIndex + 1] = newColor.G; buffer[bufferIndex + 2] = newColor.R; } } if (m_Socket != null) { byte[] recvBuffer = new byte[16]; m_Socket.Send(buffer); m_Socket.Receive(recvBuffer, 1, 0); } if(m_RenderEnabled) { m_VB.SetData(m_Lights); } }