public IconStyle(float scale, float heading, Icon icon, vec2 hotSpot) { this.scale = scale; this.heading = heading; this.icon = icon; this.hotSpot = hotSpot; }
public mat2(vec2 a, vec2 b) { this.cols = new[] { a, b }; }
public Terrain(vec2 pos,Loader loader,ModelTexture texture) { this.texture = texture; Position.x = pos.x * SIZE; Position.y = pos.y * SIZE; model = generateTerrain(loader); }
public BrickFragmentShader(vec2 size, vec2 pct, vec3 brickColor, vec3 mortColor) { BrickSize = size; BrickPct = pct; BrickColor = brickColor; MortarColor = mortColor; }
/// <summary> /// Initializes a new instance of the <see cref="mat2"/> struct. /// The matrix is initialised with the <paramref name="cols"/>. /// </summary> /// <param name="cols">The colums of the matrix.</param> public mat2(vec2[] cols) { this.cols = new[] { cols[0], cols[1] }; }
public vec2 this[int column] { get { vec2 r = new vec2(GetColumn(column)); return r; } }
public IconStyle(Color color, colorModeEnum colorMode, float scale, Icon icon, vec2 hotSpot) { this.color = color; this.colorMode = colorMode; this.scale = scale; this.icon = icon; this.hotSpot = hotSpot; }
/// <summary> /// Applies a scale transformation to matrix <paramref name="m"/> by vector <paramref name="v"/>. /// </summary> /// <param name="m">The matrix to transform.</param> /// <param name="v">The vector to scale by.</param> /// <returns><paramref name="m"/> scaled by <paramref name="v"/>.</returns> public static mat3 scale(mat3 m, vec2 v) { mat3 result = m; result.col0 = m.col0 * v.x; result.col1 = m.col1 * v.y; result.col2 = m.col2; return result; }
public static vec2 degrees(vec2 radians) { vec2 r; r.x = radians.x * radToDeg; r.y = radians.y * radToDeg; return r; }
public vec4 WangAt(vec2 tex) { var address = tex - mod(tex, 1.0f / 256.0f); var subPos = Fraction(tex * 256.0f) / 4.0f; var offset = texture(WangMap, Fraction(address)).xw; var tc = offset + subPos; var tileScaledTex = tex * new vec2(32.0f / 1.0f); return textureGrad(WangTiles, tc, dFdx(tileScaledTex), dFdy(tileScaledTex)); }
public vec4 WangAt(vec2 tex) { var address = tex - tex % (1.0f / 256.0f); var subPos = Fraction(tex * 256.0f) / 4.0f; var offset = Texture(WangMap, Fraction(address)).xw; var tc = offset + subPos; var tileScaledTex = tex * new vec2(32.0f / 1.0f); return TextureGrad(WangTiles, tc, DeriveTowardsX(tileScaledTex), DeriveTowardsY(tileScaledTex)); }
public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader) { if (bufferName == strPosition) { if (this.positionBufferPtr == null) { const float lower = -0.3f; var positions = new vec2[codedColors.Length * 2 + 4]; for (int i = 0; i < codedColors.Length; i++) { positions[i * 2 + 0] = new vec2(codedColors[i].Coord*2, lower); positions[i * 2 + 1] = new vec2(codedColors[i].Coord * 2, 1); } int index = codedColors.Length * 2 + 0; positions[index++] = new vec2(codedColors[0].Coord * 2, 0); positions[index++] = new vec2(codedColors[codedColors.Length - 1].Coord * 2, 0); positions[index++] = new vec2(codedColors[0].Coord * 2, 1); positions[index++] = new vec2(codedColors[codedColors.Length - 1].Coord * 2, 1); // Move2Cente float min = positions[0].x, max = positions[0].x; for (int i = 1; i < positions.Length; i++) { vec2 value = positions[i]; if (value.x < min) { min = value.x; } if (max < value.x) { max = value.x; } } float mid = max / 2 + min / 2; for (int i = 0; i < positions.Length; i++) { positions[i].x = positions[i].x - mid; } using (var buffer = new PropertyBuffer<vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw)) { buffer.Alloc(positions.Length); unsafe { var array = (vec2*)buffer.Header.ToPointer(); for (int i = 0; i < positions.Length; i++) { array[i] = positions[i]; } } this.positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } } return this.positionBufferPtr; } else { throw new NotImplementedException(); } }
/// <summary> /// Gets or sets the <see cref="vec2"/> column at the specified index. /// </summary> /// <value> /// The <see cref="vec2"/> column. /// </value> /// <param name="column">The column index.</param> /// <returns>The column at index <paramref name="column"/>.</returns> public vec2 this[int column] { get { if (column == 0) { return this.col0; } if (column == 1) { return this.col1; } throw new ArgumentOutOfRangeException(); } set { if (column == 0) { this.col0 = value; } else if (column == 1) { this.col1 = value; } else { throw new ArgumentOutOfRangeException(); } } }
/// <summary> /// Build a look at view matrix. /// transform object's coordinate from world's space to camera's space. /// </summary> /// <param name="eye">The eye.</param> /// <param name="center">The center.</param> /// <param name="up">Up.</param> /// <returns></returns> public static mat3 lookAt(vec2 eye, vec2 center, bool up) { // camera's back in world space coordinate system vec2 back = (eye - center).normalize(); // camera's right in world space coordinate system vec2 right = up.cross(back).normalize(); if (!up) { right = -right; } mat3 viewMatrix = new mat3(1); viewMatrix.col0.x = right.x; viewMatrix.col1.x = right.y; viewMatrix.col0.y = back.x; viewMatrix.col1.y = back.y; // Translation in world space coordinate system viewMatrix.col3.x = -eye.dot(right); viewMatrix.col3.y = -eye.dot(back); return viewMatrix; }
internal override bool SetValue(ValueType value) { #if DEBUG if (value.GetType() != typeof(vec2)) { throw new ArgumentException(string.Format("[{0}] not match [{1}]'s value.", value.GetType().Name, this.GetType().Name)); } #endif var v = (vec2)value; if (v != this.value) { this.value = v; this.Updated = true; return true; } else { return false; } }
public override void main() { vec3 ecPosition = new vec3(MVMatrix * MCvertex); vec3 tnorm = normalize(NormalMatrix * MCnormal); vec3 lightVec = normalize(LightPosition - ecPosition); vec3 reflectVec = reflect(-lightVec, tnorm); vec3 viewVec = normalize(-ecPosition); float diffuse = max(dot(lightVec, tnorm), 0.0f); float spec = 0.0f; if (diffuse > 0.0f) { spec = max(dot(reflectVec, viewVec), 0.0f); spec = pow(spec, 16.0f); } LightIntensity = DiffuseContribution * diffuse + SpecularContribution * spec; MCposition = new vec2(MCvertex); GPPosition = new vec3(MVPMatrix * MCvertex); }
public static void _Apply(Texture2D Current, RenderTarget2D Output) { GridHelper.GraphicsDevice.SetRenderTarget(null); for (int i = 0; i < 10; i++) GridHelper.GraphicsDevice.Textures[i] = null; vec2 OutputSize = new vec2(Output.Width, Output.Height); var instance = new UpdateLife(); var _Current = new Field<cell>(Current); _Current.GetDataFromTexture(); var _Output = new Field<cell>(Output); _Output.GetDataFromTexture(); for (int i = 0; i < Output.Width ; i++) { for (int j = 0; j < Output.Height; j++) { VertexOut v = VertexOut.Zero; v.TexCoords = new vec2(i, j) / OutputSize; __SamplerHelper.TextureCoord = v.TexCoords; var color = (color)instance.FragmentShader(v, _Current).ConvertTo(); //color = rgba(State.Alive, 0,0,0); _Output.clr[i * _Output.Height + j] = new Color(FragSharpMarshal.Marshal(color)); }} _Output.CopyDataToTexture(); }
// --------------------------------- !From events --------------------------------- // //public Edges makeEdges(vec2 posSource, string source, vec2 posStock, string stock, float r, string weight) //{ // if (oriented) return new OrientedEdges(posSource, source, posStock, stock, r, weight); // else return new NonOrientedEdges(posSource, source, posStock, stock, r, weight); //} // ----------------------------- Mouse Events ----------------------------- // private void MainForm_MouseClick(object sender, MouseEventArgs e) { try { if (!_field.Status || tsbtnMove.Checked) { return; } switch (e.Button) { case MouseButtons.Left: { vec2 pos = new vec2((float)e.X, (float)e.Y); if (max.x - pos.x < R || pos.x - left < R || max.y - pos.y < R || pos.y - top < R) { _field.UnmarkGraphModels(); } else if ((selectedKey = _field.GetPosKey(pos, R)) != null && !tsBtnAddVertex.Checked) { _field.MarkGraphModel(selectedKey); var model = _field[selectedKey]; if (model is AVertexModel && _field.MarkedModelsCount <= 2) { if (_field.MarkedVertexModelCount == 1) { sourceModel = (AVertexModel)model; } else if (_field.MarkedVertexModelCount == 2) { stockModel = (AVertexModel)model; } } } else if (_field.GetPosKey(pos, R + R + R / 2) == null && tsBtnAddVertex.Checked) { if (_field.MarkedVertexModelCount > 0 || _field.MarkedEdgeModelCount > 0) { _field.UnmarkGraphModels(); break; } string v = i++.ToString(); var model = new VertexDrawModel(v, pos); AddModelCommandArgs command = new AddModelCommandArgs(model); CommandEntered?.Invoke(this, command); } else { _field.UnmarkGraphModels(); sourceModel = stockModel = null; } break; } default: break; } } catch (Exception ex) { PostErrorMessage(ex.Message); } }
public void update(int time, vec4 col, vec4 c, float size) { if (c != null && (c.z < 0.2f || size < 1f || col.w == 0f)) { update(time, null, null, 0f); return; } this.col = col; this.pos = c == null ? null : c.xy; this.size = size; if (!rendering) { return; } if (c == null) { if (size != SIZE_KEEP_LOOB_TIME) { // yuk! loob_time = -1; } sprite = null; return; } if (isOnScreen(pos, size)) { if (wasOOB && loob_time != -1 && (spritesettings & Sprite.INTERPOLATE_MOVE) > 0) { sprite = null; supdate(loob_time, loob_pos, 0f, loob_col, 1f, v2(loob_size)); loob_time = -1; } wasOOB = false; } else { // last-out-of-bounds data, if movement is interpolated // a dot can suddenly appear onscreen because the last // known pos was oob, so save the latest oob pos and // use that before the first inbounds pos loob_time = time; loob_col = v4(col); loob_pos = v2(c.xy); loob_size = size; // this check is to allow one frame offscreen // so if it's interpolated it will move oob // instead of disappear just before going oob // TODO: YUK this depends on state D: if (wasOOB || (spritesettings & Sprite.INTERPOLATE_MOVE) == 0) { update(time, null, null, SIZE_KEEP_LOOB_TIME); return; } wasOOB = true; } supdate(time, c.xy, 0f, col, 1f, v2(size)); }
public void AddVertex(vec3 p, vec2 u, vec3 n) => vertices.Add(new vertex(p, u, n));
color FragmentShader(VertexOut vertex, Field <data> CurrentData, Field <data> PreviousData, Field <unit> CurrentUnits, Field <unit> PreviousUnits, TextureSampler UnitTexture, TextureSampler ShadowTexture, [Player.Vals] float player, float s, float t, float selection_blend, float selection_size, [Vals.Bool] bool solid_blend_flag, float solid_blend) { // Calculate shadow pixel color shadow = color.TransparentBlack; vec2 shadow_subcell_pos = get_subcell_pos(vertex, CurrentData.Size, vec(0f, -.5f)); var shadow_here = Here + new RelativeIndex(0, -.5f); data shadow_cur = CurrentData[shadow_here], shadow_pre = PreviousData[shadow_here]; unit shadow_cur_unit = CurrentUnits[shadow_here], shadow_pre_unit = PreviousUnits[shadow_here]; if (IsUnit(shadow_cur_unit) || IsUnit(shadow_pre_unit)) { if (Something(shadow_cur) && shadow_cur.change == Change.Stayed) { if (s > .5) { shadow_pre = shadow_cur; } shadow += ShadowSprite(player, shadow_pre, shadow_pre_unit, shadow_subcell_pos, ShadowTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } else { if (IsValid(shadow_cur.direction)) { var prior_dir = prior_direction(shadow_cur); shadow_cur.direction = prior_dir; vec2 offset = (1 - s) * direction_to_vec(prior_dir); shadow += ShadowSprite(player, shadow_cur, shadow_cur_unit, shadow_subcell_pos + offset, ShadowTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } if (IsValid(shadow_pre.direction) && shadow.a < .025f) { vec2 offset = -s *direction_to_vec(shadow_pre.direction); shadow += ShadowSprite(player, shadow_pre, shadow_pre_unit, shadow_subcell_pos + offset, ShadowTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } } } // Calculate unit pixel color output = color.TransparentBlack; vec2 subcell_pos = get_subcell_pos(vertex, CurrentData.Size); data cur = CurrentData[Here], pre = PreviousData[Here]; unit cur_unit = CurrentUnits[Here], pre_unit = PreviousUnits[Here]; if (!IsUnit(cur_unit) && !IsUnit(pre_unit)) { return(shadow); } if (Something(cur) && cur.change == Change.Stayed) { if (s > .5) { pre = cur; } float _s = (cur_unit.anim == _0 ? t : s); if (cur_unit.anim == Anim.DoRaise) { cur_unit.anim = Anim.Die; _s = 1f - _s; } float frame = _s * UnitSpriteSheet.AnimLength + Float(cur_unit.anim); output += Sprite(player, pre, pre_unit, subcell_pos, frame, UnitTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } else { float frame = s * UnitSpriteSheet.AnimLength + Float(Anim.Walk); if (IsValid(cur.direction)) { var prior_dir = prior_direction(cur); cur.direction = prior_dir; vec2 offset = (1 - s) * direction_to_vec(prior_dir); output += Sprite(player, cur, cur_unit, subcell_pos + offset, frame, UnitTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } if (IsValid(pre.direction) && output.a < .025f) { vec2 offset = -s *direction_to_vec(pre.direction); output += Sprite(player, pre, pre_unit, subcell_pos + offset, frame, UnitTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } } if (output.a < .025f) { output = shadow; } return(output); }
public void update(int time, vec2 pos, float rot, vec4 color, float fade, vec2 size) { if (!isPhantomFrame) { if (starttime == -1) { starttime = time; } endtime = time; } vec2 scale = size / sdata.scalemod; fade *= color.w; vec3 col = color.xyz; addCmd <RotCommand, float>(rot, 0f, rotcmds, new RotCommand(time, time, rot, rot), RotCommand.requiresUpdate); rud <vec2> del = MoveCommand.requiresUpdate; if ((settings & INTERPOLATE_MOVE) > 0) { del = rud_true <vec2>; } addCmd <MoveCommand, vec2>(pos, v2(-1f), movecmds, new MoveCommand(time, time, pos, pos), del); addCmd <FadeCommand, float>(fade, 1f, fadecmds, new FadeCommand(time, time, fade, fade), FadeCommand.requiresUpdate); rud <vec3> rr = ColorCommand.requiresUpdate; if ((settings & SESDSC) > 0 || colorcmds.Count == 0 /*1 Feb 2021, if sprite is always white, there will be no colorcmd but a fadecmd * (because it won't appear if there's no cmd) but for some reason this sometimes * resulted in the sprite not showing (very visible in pixelscreen), so making sure * there's a colorcmd now...*/) { rr = rud_true <vec3>; } addCmd <ColorCommand, vec3>(col, v3(1f), colorcmds, new ColorCommand(time, time, col, col), rr); if (scale.x == scale.y) { goto squarescale; } addCmd <VScaleCommand, vec2>(scale, v2(1f), vscalecmds, new VScaleCommand(time, time, scale, scale), VScaleCommand.requiresUpdate); return; squarescale: addCmd <ScaleCommand, float>(scale.x, 1f, scalecmds, new ScaleCommand(time, time, scale.x, scale.x), ScaleCommand.requiresUpdate); }
public void fin(Writer w) { if ((settings & INTERPOLATE_MOVE) > 0) { interpolateMovement(); } if ((settings & EASE_FADE) > 0) { easeFloatCommands <FadeCommand>(fadecmds); } if ((settings & EASE_SCALE) > 0) { easeFloatCommands <ScaleCommand>(scalecmds); } removePhantomCommands(); // do not place this check under the deletion of the only movecmd // or white sprites might disappear (actually happend with zrub) if (allcmds.Count == 0) { return; } if ((settings & COMPRESS_MOVE) > 0) { compressmove(); } fixrotation(); vec2 initialPosition = v2(0f); if (movecmds.Count == 1) { MoveCommand m = movecmds.First.Value; if (m.to.Equals(m.from)) { initialPosition = m.to; allcmds.Remove(m); movecmds.Clear(); } else if (m.to.x == m.from.x) { initialPosition.x = m.to.x; } else if (m.to.y == m.from.y) { initialPosition.y = m.to.y; } } processOverrides(); if ((settings & INTERPOLATE_MOVE) == 0) { if ((settings & NO_ADJUST_LAST) == 0) { adjustLastFrame(); } } else { // ztunnel has seen sprites with single // color and scale command for one frame, // effectively invisible. int firsttime = -1; bool remove = true; foreach (ICommand cmd in allcmds) { if (cmd.start != cmd.end) { remove = false; break; } if (firsttime == -1) { firsttime = cmd.start; } else if (firsttime != cmd.start) { remove = false; break; } } if (remove) { return; } } if (fakesprite_skipusagedata) { addusagedata(); } w.ln(createsprite(initialPosition)); if ((settings & SESDSM) == SESDSM && movecmds.Count > 2) { foreach (MoveCommand m in movecmds) { allcmds.Remove(m); } } if ((settings & SESDSC) > 0 && colorcmds.Count > 2) { foreach (ColorCommand c in colorcmds) { allcmds.Remove(c); } } foreach (ICommand cmd in allcmds) { w.ln(cmd.ToString()); } if ((settings & SESDSM) == SESDSM && movecmds.Count > 2) { string s = "_M,0,"; s += movecmds.First.Value.start; s += ","; s += movecmds.First.Next.Value.start; s += ","; LinkedListNode <MoveCommand> n = movecmds.First; s += Math.Round(n.Value.from.x, ICommand.round_move_decimals.Peek()).ToString(); s += ","; s += Math.Round(n.Value.from.y, ICommand.round_move_decimals.Peek()).ToString(); s += ","; s += Math.Round(n.Value.to.x, ICommand.round_move_decimals.Peek()).ToString(); s += ","; s += Math.Round(n.Value.to.y, ICommand.round_move_decimals.Peek()).ToString(); while ((n = n.Next) != null) { s += ","; s += Math.Round(n.Value.to.x, ICommand.round_move_decimals.Peek()).ToString(); s += ","; s += Math.Round(n.Value.to.y, ICommand.round_move_decimals.Peek()).ToString(); } w.ln(s); } if ((settings & SESDSC) > 0 && colorcmds.Count > 2) { string s = "_C,0,"; s += colorcmds.First.Value.start; s += ","; s += colorcmds.First.Next.Value.start; s += ","; LinkedListNode <ColorCommand> n = colorcmds.First; s += "" + (int)(colorcmds.First.Value.from.x * 255f); s += ","; s += "" + (int)(colorcmds.First.Value.from.y * 255f); s += ","; s += "" + (int)(colorcmds.First.Value.from.z * 255f); while ((n = n.Next) != null) { s += ","; s += "" + (int)(n.Value.from.x * 255f); s += ","; s += "" + (int)(n.Value.from.y * 255f); s += ","; s += "" + (int)(n.Value.from.z * 255f); } w.ln(s); } foreach (string raw in raws) { w.ln(raw); } }
public override void draw(SCENE scene) { vec3[] sp = new vec3[] { v3(0f, 0f, 50f) }; move(sp, Zcamera.mid); Zcamera.adjust(sp); sunpos = sp[0]; //Zharrier.position = v3(0f); lockedharrpos = null; dp = v3(0f); vec3 dir = v3(0f); float rz = 0f; int t = scene.time; if (t < 5041) { // intro dp = v3(lerp(-1000f, 1000f, progress(2000, 5041, t)), 0f, 0f); dir = v3(10f, 0f, 0f); } else if (t < 9950) { // first circling float f = progress(5041, 9950, t) + .7f; if (t > 6625) { f += .2f; } if (t > 8250) { f += .2f; } dp = v3(500f * cos(f * 4f), 500f * sin(f * 4f), -200f); dir = dp - v3(0f, 0f, 0f); } else if (t < 11708) { // i present float f = progress(9950, 11708, t); dp = v3(-lerp(-520f, 520f, f), -200f, -40f); dir = dp - v3(-lerp(-400f, 400f, f), -450f, -20f); } else if (t < 14958) { // more showoff float f = progress(11708, 14666, t) - .1f; if (t > 13200) { f += .2f; } dp = v3(lerp(500f, -500f, f), 0f, -600f); dir = dp - v3(lerp(500f, -500f, f), 0f, 0f); } else if (t < 18291) { // osu sb numero dos int nums = 11; float size = 0.07f; float f = progress(14958, 18291, t) * (1f - nums * size); int tt = t + 75; if (tt > 15375) { f += size; } for (int i = 0; i < 6; i++) { if (t > 15791 + i * 132) { f += size; } } if (tt > 16583) { f += size; } if (tt > 16980) { f += size; } if (tt > 17375) { f += size; } if (tt > 17833) { f += size; } dp = v3(-lerp(-700f, 650f, f), 100f, -25f); dir = v3(0f, 1f, 0f); } else if (t < 31400) { // harr float f = progressx(18291, 24583, t); float fat = f * 0.99f; float fto = clamp(f + 0.1f, 0f, 1f); /* * vec3 ha = v3(-600f, 0f, 0f); * vec3 hp1 = v3(1200f, 200f, 150f); * vec3 hp2 = v3(1000f, -800f, 350f); * vec3 hb = v3(-300f, -300f, 200f); * * vec3 at = cubic(ha, hb, hp1, hp2, fat); * vec3 atn = cubic(ha, hb, hp1, hp2, clamp(fat + 0.001f, 0f, 1f)); * vec3 to = cubic(ha, hb, hp1, hp2, fto); * * Zharrier.position = at; * Zharrier.yaw = atan2(atn.y - at.y, atn.x - at.x); * Zharrier.pitch = -atan2(to.z - at.z, (to.xy - at.xy).length()); * Zharrier.roll = -(atan2(atn.x - at.x, atn.y - at.y) - atan2(to.x - at.x, to.y - at.y));*/ dp = v3() - getCamPos(t); dir = dp + getHarrPos(t); } else if (t < 56333) { // greets vec3 _00_pos = v3(-1097.832f, -1175.126f, 271.0345f); vec3 _00_lok = v3(-1077.637f, -1267.603f, 285.5392f); vec3 _01_lok = v3(0f, 0f, 100f); vec3 _05_pos = v3(759.1069f, -193.1827f, 289.7183f); vec3 _05_lok = lerp(v3(), _05_pos, 0.9f); _05_lok.z = _05_pos.z; vec3 _05_lokb = v3(_05_lok); _05_lok = _05_pos - (_05_pos - _05_lok) * 5f; vec3 _10_pos = _05_pos + v3(-30f, 40f, 0f); vec3 her_dir = v3(0f, -1f, 0f); vec3 her_pos = v3(398f, -115.85317f, 35f); vec3 her_lok = her_pos + her_dir * 50f; vec3 her_int = lerp(_10_pos, her_pos, 0.2f) + v3(0, 400f, 0f); vec3 her_int2 = lerp(_10_pos, her_pos, 0.8f) + v3(0, 400f, 0f); vec3 her_pos2 = v3(398f, -115.85317f, 58f); vec3 her_lok2 = her_pos2 + her_dir * 50f; vec3 qua_lok = v3(300f, 80f, 230f); vec3 qua_pos = v3(-748.7392f, -328.6331f, 80f); qua_lok = lerp(qua_lok, qua_pos, 0.4f); vec3 qua_int = lerp(her_pos2, qua_pos, 0.2f) + v3(0, -200f, 0); vec3 qua_int2 = lerp(her_pos2, qua_pos, 0.8f) + v3(0, -200f, 0); vec3 qua_pos2 = v3(-748.7392f, -270.6331f, 80f); vec3 luk_pos = v3(632.1013f, 358.0017f, 48.1202f); vec3 luk_lok = v3(-263.8631f, 1.909196f, 270f); vec3 luk_pos2 = luk_pos + v3(0f, -40f, 0f); vec3 luk_int = lerp(qua_pos2, luk_pos, 0.5f) + v3(0f, 500f, 200f); vec3 luk_lokint = lerp(qua_lok, luk_lok, 0.5f) + v3(0f, 0f, -400f); if (t < 33125) { // transition from harr float f = progress(31400, 33125, t); dp = v3() - _00_pos; dir = dp + lerp(_00_lok, _01_lok, f); } else if (t < 35708) { // transition to em float f = greetprogress(33125, 35708, 34041, 34791, t, .11f); vec3 to = lerp(_00_pos, _05_pos, f); //to = quadratic(_00_pos, _05_pos, v3(800f, -700f, 0f), f); //to.z = lerp(_00_pos.z, _05_pos.z, f); dp = v3() - to; dir = dp + lerp(_01_lok, _05_lok, f); } else if (t < 39750) { // around em float f = progress(36458, 39750, t); dp = v3() - lerp(_05_pos, _10_pos, f); dir = dp + _05_lokb; } else if (t < 42333) { // transition to herakles float f = greetprogress(39750, 42333, 40666, 41416, t, .11f); dp = v3() - lerp(_10_pos, her_pos, f); dp = v3() - cubic(_10_pos, her_pos, her_int, her_int2, f); dir = dp + lerp(_05_lokb, her_lok, f); rz = lerp(0f, 1f, eq_in_quart(f)); } else if (t < 46375) { // around herakles float f = progress(42333, 46375, t); dp = v3() - lerp(her_pos, her_pos2, f); dir = dp + lerp(her_lok, her_lok2, f); rz = 1f; } else if (t < 48850) { // transition to quack float f = greetprogress(46375, 48850, 47333, 48000, t, .11f); dp = v3() - cubic(her_pos2, qua_pos, qua_int, qua_int2, f); dir = dp + lerp(her_lok2, qua_lok, eq_in_cubic(f)); rz = lerp(1f, 0f, f); } else if (t < 51333) { // around quack float f = progress(48850, 51333, t); dp = v3() - lerp(qua_pos, qua_pos2, f); dir = dp + qua_lok; rz = lerp(0f, -0.2f, f); } else if (t < 53900) { // transition to luki float f = greetprogress(51333, 53900, 52291, 53000, t, .11f); dp = v3() - quadratic(qua_pos2, luk_pos, luk_int, f); dir = dp + quadratic(qua_lok, luk_lok, luk_lokint, f); rz = lerp(-0.2f, 0f, f); } else { // around luki float f = progress(53900, 56333, t); dp = v3() - lerp(luk_pos, luk_pos2, f); dir = dp + luk_lok; } if (t < 40000) { Zctext.position = _05_lokb; Zctext.rotation = quat(0f, 0f, 1.5f); float f = progress(36458, 39125, t); Zctext.showbg = f >= 0f; Zctext.bgsize = eq_out_circ(clamp(f * 2.2f, 0f, 1f)); Zctext.bgcol = v4(1f, .42f, .8f, 1f - eq_in_expo(f)); Zctext.bgstyle = 0; } else if (t < 47000) { Zctext.position = v3(400f, -205f, 40f); Zctext.rotation = quat(-PI2, 0f, PI); float f = progress(43040, 44750, t); Zctext.showbg = f >= 0f; Zctext.bgsize = eq_out_circ(clamp(f * 2.2f, 0f, 1f)); Zctext.bgcol = v4(.4f, .7f, 1f, 1f - eq_in_expo(f)); Zctext.bgstyle = 1; } else if (t < 52000) { Zctext.position = lerp(qua_lok, lerp(qua_pos, qua_pos2, 0.8f), 0.9f); Zctext.rotation = quat(0f, 0f, -1.5f); float f = progress(49583, 50916, t); Zctext.showbg = f >= 0f; Zctext.bgsize = eq_out_circ(clamp(f * 2.2f, 0f, 1f)); Zctext.bgcol = v4(.4f, .7f, 1f, 1f - eq_in_expo(f)); Zctext.bgstyle = 1; } else if (t < 56541) { Zctext.position = lerp(luk_lok, lerp(luk_pos, luk_pos2, 0.6f), 0.95f); Zctext.rotation = quat(0f, 0f, 1.9f); float f = progress(54400, 55800, t); Zctext.showbg = f >= 0f; Zctext.bgsize = eq_out_circ(clamp(f * 2.2f, 0f, 1f)); Zctext.bgcol = v4(.4f, .7f, 1f, 1f - eq_in_expo(f)); Zctext.bgstyle = 1; } } else if (t < 58000) { // transition to shad (first appearance) (but not actually, mc is in between) float tt = t / 200f; int seg = (58000 - 56333) / 6; switch ((t - 56333) / seg) { case 0: dp = v3(17f, 17f, -15f); break; case 1: dp = v3(-20f, -18f, 19f); break; case 2: dp = v3(20f, -18f, 0f); break; case 3: dp = v3(20f, -20f, -20f); break; case 4: dp = v3(-16f, 5f, 15f); break; default: dp = v3(20f, -20f, -20f); rz = 3.3f; break; } dir = dp - v3(0f); } else if (t < 64250) { // mc dp = v3(-25f, 0f, -10f); dir = dp - v3(0f); } else if (t < 67600) { // shad (first.5 appearance) float p = progressx(64250, 67458, t) * 3.5f; p += 3.2f * step(t, 64350); //float tt = t; //tt += 2000.0f * step(64350, t) - 200f; //tt /= 200.0f; float a, b; //a = tt / -4f; //b = tt / 6f; a = p + -.75f; b = p + 6.5f; float xymod = (1f + .1f * abs(sin(b))); float dist = 25f + progressx(67600 - 500, 67600, t) * 200.0f; dp = v3(dist * cos(a) * xymod, dist * sin(a) * xymod, 14f * cos(b)); dir = dp - v3(0f); } else if (t < 104085) { // harrier breakdown dp = v3(-38f, 40f, -20f); dir = dp - v3(0f, 20f, -5f); } else { // shad (second appearance) dp = v3(20f, 0f, 0f); dir = dp - v3(0f); } vec2 vd = viewdir(dir); lquatx = quat(0f, 0f, vd.x); lquaty = quat(0f, vd.y, 0f); lquatz = quat(rz, 0f, 0f); }
// Classic Perlin noise float cnoise(vec3 P) { vec3 Pi0 = floor(P); // Integer part for indexing vec3 Pi1 = Pi0 + vec3(1.0f); // Integer part + 1 Pi0 = mod289(Pi0); Pi1 = mod289(Pi1); vec3 Pf0 = fract(P); // Fractional part for interpolation vec3 Pf1 = Pf0 - vec3(1.0f); // Fractional part - 1.0 vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x); vec4 iy = vec4(Pi0.yy, Pi1.yy); vec4 iz0 = Pi0.zzzz; vec4 iz1 = Pi1.zzzz; vec4 ixy = permute(permute(ix) + iy); vec4 ixy0 = permute(ixy + iz0); vec4 ixy1 = permute(ixy + iz1); vec4 gx0 = ixy0 * (1.0f / 7.0f); vec4 gy0 = fract(floor(gx0) * (1.0f / 7.0f)) - 0.5f; gx0 = fract(gx0); vec4 gz0 = vec4(0.5f) - abs(gx0) - abs(gy0); vec4 sz0 = step(gz0, vec4(0.0f)); gx0 -= sz0 * (step(0.0f, gx0) - 0.5f); gy0 -= sz0 * (step(0.0f, gy0) - 0.5f); vec4 gx1 = ixy1 * (1.0f / 7.0f); vec4 gy1 = fract(floor(gx1) * (1.0f / 7.0f)) - 0.5f; gx1 = fract(gx1); vec4 gz1 = vec4(0.5f) - abs(gx1) - abs(gy1); vec4 sz1 = step(gz1, vec4(0.0f)); gx1 -= sz1 * (step(0.0f, gx1) - 0.5f); gy1 -= sz1 * (step(0.0f, gy1) - 0.5f); vec3 g000 = vec3(gx0.x, gy0.x, gz0.x); vec3 g100 = vec3(gx0.y, gy0.y, gz0.y); vec3 g010 = vec3(gx0.z, gy0.z, gz0.z); vec3 g110 = vec3(gx0.w, gy0.w, gz0.w); vec3 g001 = vec3(gx1.x, gy1.x, gz1.x); vec3 g101 = vec3(gx1.y, gy1.y, gz1.y); vec3 g011 = vec3(gx1.z, gy1.z, gz1.z); vec3 g111 = vec3(gx1.w, gy1.w, gz1.w); vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110))); g000 *= norm0.x; g010 *= norm0.y; g100 *= norm0.z; g110 *= norm0.w; vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111))); g001 *= norm1.x; g011 *= norm1.y; g101 *= norm1.z; g111 *= norm1.w; float n000 = dot(g000, Pf0); float n100 = dot(g100, vec3(Pf1.x, Pf0.yz)); float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z)); float n110 = dot(g110, vec3(Pf1.xy, Pf0.z)); float n001 = dot(g001, vec3(Pf0.xy, Pf1.z)); float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z)); float n011 = dot(g011, vec3(Pf0.x, Pf1.yz)); float n111 = dot(g111, Pf1); vec3 fade_xyz = fade(Pf0); vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z); vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y); float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); return(2.2f * n_xyz); }
public void main() { gl_Position = ubo.proj * ubo.view * ubo.model * new vec4(inPosition, 1f); // fragColor = inColor; fragTextCoord = inTextCoord; }
private void OnCursor(double x, double y, double deltaX, double deltaY) => MousePosition = new vec2((float)x, (float)y);
geo FragmentShader(VertexOut vertex, Field <geo> Geo) { geo here = Geo[Here], right = Geo[RightOne], up = Geo[UpOne], left = Geo[LeftOne], down = Geo[DownOne], up_right = Geo[UpRight], up_left = Geo[UpLeft], down_right = Geo[DownRight], down_left = Geo[DownLeft]; if (here.dir == _0) { return(here); } vec2 extr_here = geo_pos_id(here), extr_right = geo_pos_id(right), extr_up = geo_pos_id(up), extr_left = geo_pos_id(left), extr_down = geo_pos_id(down), extr_up_right = geo_pos_id(up_right), extr_up_left = geo_pos_id(up_left), extr_down_right = geo_pos_id(down_right), extr_down_left = geo_pos_id(down_left); float val_here = flatten(extr_here), val_right = flatten(extr_right), val_up = flatten(extr_up), val_left = flatten(extr_left), val_down = flatten(extr_down), val_up_right = flatten(extr_up_right), val_up_left = flatten(extr_up_left), val_down_right = flatten(extr_down_right), val_down_left = flatten(extr_down_left); if (val_here < val_right) { here.pos_storage = right.pos_storage; val_here = val_right; } if (val_here < val_up) { here.pos_storage = up.pos_storage; val_here = val_up; } if (val_here < val_left) { here.pos_storage = left.pos_storage; val_here = val_left; } if (val_here < val_down) { here.pos_storage = down.pos_storage; val_here = val_down; } if (val_here < val_up_right) { here.pos_storage = up_right.pos_storage; val_here = val_up_right; } if (val_here < val_up_left) { here.pos_storage = up_left.pos_storage; val_here = val_up_left; } if (val_here < val_down_right) { here.pos_storage = down_right.pos_storage; val_here = val_down_right; } if (val_here < val_down_left) { here.pos_storage = down_left.pos_storage; val_here = val_down_left; } return(here); }
public void VertexMain() { _fragNormal = Normal; gl_Position = ModelviewProjection * Vertex; }
private bool isoob(vec2 pos, float scale) { return(all.isOnScreen(pos, sdata.size * scale)); }
public override void RefreshPos() { vec2 sourcePos = Source.Pos; vec2 stockPos = Stock.Pos; vec2 direction = stockPos - sourcePos; vec2 normDirection = direction.Normalize(); vec2 incr = normDirection * GlobalParameters.Radius; PosA = sourcePos + incr; PosB = stockPos - incr; if (Weighted) { vec2 delta = sourcePos.y > stockPos.y ? sourcePos - stockPos : stockPos - sourcePos; float koef = delta.x / delta.Length(); WeightAngle = (float)(Math.Acos(koef) * 180 / Math.PI); float x, y; vec2 AB = sourcePos - stockPos; if (AB.x == 0f) { AB.x = 0.0001f; } if (AB.y == 0f) { AB.y = 0.0001f; } if (stockPos.x != sourcePos.y) { if (sourcePos.x > stockPos.x) { y = -10f; } else { y = 10f; } vec2 v = new vec2(0f, y); x = -(AB.y * v.y) / AB.x; } else { if (sourcePos.y > stockPos.y) { x = -10f; } else { x = 10f; } vec2 v = new vec2(x, 0f); y = (-AB.x * v.x) / AB.y; } vec2 norm = new vec2(x, y).Normalize(); delta = PosB - PosA; var ln = delta.Length(); delta = delta.Normalize(); float charPX = 5f; float strLength = charPX * StringRepresent.Length; if (sourcePos.x < stockPos.x) { strLength *= -1f; norm *= -20f; } else { norm *= 20; } float offset = (ln / 2f) + (strLength / 2); WeightPos = PosA + (delta * offset); WeightPos += norm; } }
float flatten(vec2 pos) { return(pos.x + 4096 * pos.y); }
public vertex(vec3 p, vec2 u, vec3 n) { pos = p; texcoord = u; normal = n; }
/// <summary>Returns a 1D noise value based on the input value x.</summary> protected static float noise1(vec2 x) { throw _invalidAccess; }
public void FragmentMain() { _position = Vertex; _uv = Vertex.xy * 0.5f + new vec2(0.5f); }
/// <summary>Returns a 4D noise value based on the input value x.</summary> protected static vec4 noise4(vec2 x) { throw _invalidAccess; }
public void AttackMoveApply(float Player, vec2 Pos, vec2 Selected_BL, vec2 Selected_Size, vec2 Destination_BL, vec2 Destination_Size, float filter) { SetSelectedAction.Apply(CurrentData, CurrentUnits, SimShader.UnitAction.Attacking, Player, Output: Temp1); Swap(ref CurrentData, ref Temp1); var ConversionRatio = Destination_Size / Selected_Size; ActionAttackSquare.Apply(CurrentData, CurrentUnits, TargetData, Destination_BL, Selected_BL, ConversionRatio, Player, filter, Output: Temp1); Swap(ref TargetData, ref Temp1); ActionAttack2.Apply(CurrentData, CurrentUnits, Extra, Pos, Player, filter, Output: Temp1); Swap(ref Extra, ref Temp1); }
public void SetupUv(vec2 UvBl, vec2 UvTr) { const float Z = 0.0f; vec2 _UvBl = new vec2(UvBl.x, UvTr.y); vec2 _UvTr = new vec2(UvTr.x, UvBl.y); vec2 _UvBr = new vec2(UvTr.x, UvTr.y); vec2 _UvTl = new vec2(UvBl.x, UvBl.y); vertexData[TOP_LEFT].TextureCoordinate = _UvTl; vertexData[TOP_RIGHT].TextureCoordinate =_UvTr; vertexData[BOTTOM_RIGHT].TextureCoordinate = _UvBr; vertexData[BOTTOM_LEFT].TextureCoordinate = _UvBl; }
private void supdate(int time, vec2 pos, float rot, vec4 col, float fade, vec2 size) { if (sprite == null) { sprite = new Sprite(spritename, spritesettings); sprites.Add(sprite); foreach (ICommand cmd in overrides) { sprite.addOverride(cmd.copy()); } } sprite.update(time, pos, rot, col, fade, size); }
vec2 Rotate(vec2 v, float Angle, vec2 Center) { v -= Center; float c = cos(Angle); float s = sin(Angle); return Center + vec(c * v.x + -s * v.y, s * v.x + c * v.y); }
Vector2 convert(vec2 v2) { return(new Vector2(v2.x, v2.y)); }
public static void Draw(GraphicsDevice GraphicsDevice, vec2 pos, vec2 size, float Angle = 0) { ScratchQuad.SetupVertices(pos - size, pos + size, vec2.Zero, vec2.Ones, Angle, pos); ScratchQuad.Draw(GraphicsDevice); }
private void DrawScanLine(PrimitiveContext ctx, int y, float xe, float xd) { int xmin = glm.Max((int)xe, 0); int xmax = glm.Min((int)xd, Viewport.Width); int ib = ctx.baseIndex; float w0 = ctx.w[ctx.iV0]; float w1 = ctx.w[ctx.iV1]; float w2 = ctx.w[ctx.iV2]; vec4 C0 = ctx.bcolors[ib + ctx.iV0]; vec4 C1 = ctx.bcolors[ib + ctx.iV1]; vec4 C2 = ctx.bcolors[ib + ctx.iV2]; vec2 T0 = ctx.btc[ib + ctx.iV0]; vec2 T1 = ctx.btc[ib + ctx.iV1]; vec2 T2 = ctx.btc[ib + ctx.iV2]; float dn01 = Linear2Homo(ctx.dfd01, w0, w1); float dn12 = Linear2Homo(ctx.dfd12, w1, w2); float dn02 = Linear2Homo(ctx.dfe02, w0, w2); float dn21 = Linear2Homo(ctx.dfe21, w2, w1); float dr01 = 1f - dn01; float dr12 = 1f - dn12; float dr02 = 1f - dn02; float dr21 = 1f - dn21; float bn012 = ctx.dfd012; float bn021 = ctx.dfe021; float br012 = 1f - bn012; float br021 = 1f - bn021; float R0 = dr01 * br012; float R1 = dr02 * br021; float R23 = dn01 * br012 + dr12 * bn012; float R4 = dn21 * bn021; float R5 = dn12 * bn012; float R67 = dn02 * br021 + dr21 * bn021; float wLeft = w0 * R1 + w1 * R4 + w2 * R67; float wRight = w0 * R0 + w1 * R23 + w2 * R5; vec4 CE = C0 * R1 + C1 * R4 + C2 * R67; vec4 CD = C0 * R0 + C1 * R23 + C2 * R5; vec2 TE = T0 * R1 + T1 * R4 + T2 * R67; vec2 TD = T0 * R0 + T1 * R23 + T2 * R5; float zLeft = ctx.v[ctx.iV0].z * R1 + ctx.v[ctx.iV1].z * R4 + ctx.v[ctx.iV2].z * R67; float zRight = ctx.v[ctx.iV0].z * R0 + ctx.v[ctx.iV1].z * R23 + ctx.v[ctx.iV2].z * R5; vec4 CDE = CD - CE; vec2 TDE = TD - TE; float deltaDx = (xd != xe) ? 1f / (float)(xd - xe) : 0f; for (int x = xmin; x <= xmax; x++) { float dx = (float)(x - xe) * deltaDx; dx = Linear2Homo(dx, wLeft, wRight); float z = zLeft + (zRight - zLeft) * dx; if (z >= DepthBuffer.GetPoint(x, y)) { continue; } DepthBuffer.SetPoint(x, y, z); vec4 vertexColor = CE + (CDE * dx); vec2 textureCoord = TE + (TDE * dx); vec4 textureColor = CurrentTexture.GetTexel(textureCoord.x, textureCoord.y); vec4 color = vec4.Mix(vertexColor, textureColor, TextureBlendFactor); DrawPoint(x, y, Util.ToARGB(color)); } }
private void LoadFontData(string[] fontdata) { var values = new Dictionary <string, string>(); fontdata = fontdata.Where(x => !string.IsNullOrEmpty(x)).ToArray(); int _getInt(string key) => int.Parse(values[key]); int[] _getArray(string key) => values[key].Split(',').Select(x => int.Parse(x)).ToArray(); int lineIndex = 0; bool _next() { values.Clear(); if (lineIndex >= fontdata.Length) { return(false); } var line = fontdata[lineIndex]; // end if line is empty string: if (string.IsNullOrEmpty(line)) { return(false); } foreach (var item in line.Split(' ')) { var s = item.Split('='); if (s.Length != 2) { continue; } values.Add(s[0], s[1]); } lineIndex++; return(true); } // load padding _next(); var p = _getArray("padding"); paddingTop = p[0]; paddingLeft = p[1]; paddingBottom = p[2]; paddingRight = p[3]; // load line height _next(); lineHeight = _getInt("lineHeight"); // load characters _next(); // skip page _next(); // skip chars count var atlasSize = new vec2(Atlas.width, Atlas.height); while (_next()) { glyphs.Add( new Glyph( _getInt("id"), new vec2(_getInt("x"), _getInt("y")) / atlasSize, new vec2(_getInt("width"), _getInt("height")) / atlasSize, new vec2(_getInt("xoffset"), _getInt("yoffset")) / atlasSize, _getInt("xadvance") / atlasSize.x )); } }
public static vec2 ToVec2(this float[] array, int startIndex = 0) { vec2 result = new vec2(array[startIndex], array[startIndex + 1]); return result; }
/// <summary> /// OuterProduct treats the first parameter c as a column vector (matrix with one column) and the second parameter r as a row vector (matrix with one row) and does a linear algebraic matrix multiply c * r, yielding a matrix whose number of rows is the number of components in c and whose number of columns is the number of components in r. /// </summary> public static mat2x3 OuterProduct(vec3 c, vec2 r) => vec3.OuterProduct(c, r);
public Quad() { size = vec2.Ones; offset = vec2.Zero; rotation = vec2.Zero; }
geo_info FragmentShader(VertexOut vertex, Field <geo> Geo, Field <geo_info> Info) { geo here = Geo[Here], right = Geo[RightOne], up = Geo[UpOne], left = Geo[LeftOne], down = Geo[DownOne]; float dist_right = polar_dist(Info[RightOne]), dist_up = polar_dist(Info[UpOne]), dist_left = polar_dist(Info[LeftOne]), dist_down = polar_dist(Info[DownOne]); if (here.dir == _0) { return(geo_info.Zero); } float dist = 0; // Calculate the geo_id of this cell geo temp_geo = geo.Nothing; vec2 pos = vertex.TexCoords * Geo.Size; set_geo_pos_id(ref temp_geo, pos); // ... if that geo_id matches the id of the geo info here, then this is the "master" or "12 o' clock" cell of the geodesic line going through this cell. if (here.pos_storage == temp_geo.pos_storage) { // That means its polar distance is 0 by definition. dist = 0; } else { // If this geodesic flows into another tile, then the polar distance here should be 1 less than the distance of the tile it flows into. // This is a fail safe condition that covers degenerate tiles which have nothing flowing into them and only flow out. if (here.dir == Dir.Left) { dist = max(_0, dist_left - 1); } if (here.dir == Dir.Right) { dist = max(_0, dist_right - 1); } if (here.dir == Dir.Up) { dist = max(_0, dist_up - 1); } if (here.dir == Dir.Down) { dist = max(_0, dist_down - 1); } // The polar distance is also 1 plus the polar distance of whatever cell comes "before" it (by following the geo backwards "counterclockwise"). if (right.dir == Dir.Left && dist_right >= dist) { dist = dist_right + 1; } if (left.dir == Dir.Right && dist_left >= dist) { dist = dist_left + 1; } if (up.dir == Dir.Down && dist_up >= dist) { dist = dist_up + 1; } if (down.dir == Dir.Up && dist_down >= dist) { dist = dist_down + 1; } } // Pack the polar distance into 2-bytes and return it in geo_info output = geo_info.Zero; set_polar_dist(ref output, dist); return(output); }
/// <summary> /// Applies a translation transformation to matrix <paramref name="m"/> by vector <paramref name="v"/>. /// </summary> /// <param name="m">The matrix to transform.</param> /// <param name="v">The vector to translate by.</param> /// <returns><paramref name="m"/> translated by <paramref name="v"/>.</returns> public static mat3 translate(mat3 m, vec2 v) { mat3 result = m; result.col2 = m.col0 * v.x + m.col1 * v.y + m.col2; return result; }
public Quad(vec2 size) { this.size = size; offset = vec2.Zero; rotation = vec2.Zero; }
/// <summary>Returns a 3D noise value based on the input value x.</summary> protected static vec3 noise3(vec2 x) { throw _invalidAccess; }
public Quad(vec2 size, vec2 offset) { this.size = size; this.offset = offset; rotation = vec2.Zero; }
public void SetupPosition(vec2 PositionBl, vec2 PositionTr) { const float Z = 0.0f; vec3 _PositionBl = new vec3(PositionBl.x, PositionBl.y, Z); vec3 _PositionTr = new vec3(PositionTr.x, PositionTr.y, Z); vec3 _PositionBr = new vec3(PositionTr.x, PositionBl.y, Z); vec3 _PositionTl = new vec3(PositionBl.x, PositionTr.y, Z); vertexData[TOP_LEFT].Position = _PositionTl; vertexData[TOP_RIGHT].Position = _PositionTr; vertexData[BOTTOM_RIGHT].Position = _PositionBr; vertexData[BOTTOM_LEFT].Position = _PositionBl; }
public Quad(vec2 size, vec2 offset, vec2 rotation) { this.size = size; this.offset = offset; this.rotation = rotation; }
public void SetupVertices(vec2 PositionBl, vec2 PositionTr, vec2 UvBl, vec2 UvTr, float Angle = 0, vec2 Center = default(vec2)) { const float Z = 0.0f; vec3 _PositionBl = new vec3(PositionBl.x, PositionBl.y, Z); vec3 _PositionTr = new vec3(PositionTr.x, PositionTr.y, Z); vec3 _PositionBr = new vec3(PositionTr.x, PositionBl.y, Z); vec3 _PositionTl = new vec3(PositionBl.x, PositionTr.y, Z); if (Angle != 0) { _PositionBl.xy = Rotate(_PositionBl.xy, Angle, Center); _PositionTr.xy = Rotate(_PositionTr.xy, Angle, Center); _PositionBr.xy = Rotate(_PositionBr.xy, Angle, Center); _PositionTl.xy = Rotate(_PositionTl.xy, Angle, Center); } vec2 _UvBl = new vec2(UvBl.x, UvTr.y); vec2 _UvTr = new vec2(UvTr.x, UvBl.y); vec2 _UvBr = new vec2(UvTr.x, UvTr.y); vec2 _UvTl = new vec2(UvBl.x, UvBl.y); vertexData = new VertexPositionColorTexture[4]; vertexData[TOP_LEFT] = new VertexPositionColorTexture(_PositionTl, Color.White, _UvTl); vertexData[TOP_RIGHT] = new VertexPositionColorTexture(_PositionTr, Color.White, _UvTr); vertexData[BOTTOM_RIGHT] = new VertexPositionColorTexture(_PositionBr, Color.White, _UvBr); vertexData[BOTTOM_LEFT] = new VertexPositionColorTexture(_PositionBl, Color.White, _UvBl); }
public virtual void Move(vec2 offset) { this.offset += offset; }
public RectangleQuad(vec2 PositionBl, vec2 PositionTr, vec2 UvBl, vec2 UvTr) { SetupVertices(PositionBl, PositionTr, UvBl, UvTr); }
void LoadModel(string path, bool flip = true) { modelPath = path; modelName = Path.GetFileName(path); FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(stream); header = new md2_t(); header.ident = br.ReadInt32(); header.version = br.ReadInt32(); header.skinheight = br.ReadInt32(); header.skinwidth = br.ReadInt32(); header.framesize = br.ReadInt32(); header.num_skins = br.ReadInt32(); header.num_xyz = br.ReadInt32(); header.num_st = br.ReadInt32(); header.num_tris = br.ReadInt32(); header.num_glcmds = br.ReadInt32(); header.num_frames = br.ReadInt32(); header.ofs_skins = br.ReadInt32(); header.ofs_st = br.ReadInt32(); header.ofs_tris = br.ReadInt32(); header.ofs_frames = br.ReadInt32(); header.ofs_glcmds = br.ReadInt32(); header.ofs_end = br.ReadInt32(); anim_t a1 = new anim_t(); a1.first_frame = 0; a1.last_frame = header.num_frames; a1.fps = 9; animlist.Add(a1); MD2AnimationNames.Add("AllAnimations"); br.BaseStream.Seek(header.ofs_skins, SeekOrigin.Begin); skins = new List <string>(); for (int i = 0; i < header.num_skins; i++) { string s = new string(br.ReadChars(64)); //skins.Add(s); string t = ""; int j = 0; for (j = s.Length - 1; j >= 0; j--) { if (s[j] == '/') { break; } } j++; for (int o = j; o < s.Length; o++) { t += s[o]; if (s[o] == 'x' && s[o - 1] == 'c' && s[o - 2] == 'p') { break; } } skins.Add(t); } UVData = new List <vec2>(); br.BaseStream.Seek(header.ofs_st, SeekOrigin.Begin); for (int i = 0; i < header.num_st; i++) { vec2 uv = new vec2(); uv.x = ((float)br.ReadInt16()) / header.skinwidth; uv.y = ((float)br.ReadInt16()) / header.skinheight; UVData.Add(uv); } int x = header.num_xyz - header.num_st; if (x > 0) { for (int i = 0; i < x; i++) { UVData.Add(new vec2(0)); } } indices = new List <int>(); br.BaseStream.Seek(header.ofs_tris, SeekOrigin.Begin); for (int i = 0; i < header.num_tris; i++) { indices.Add(br.ReadUInt16()); indices.Add(br.ReadUInt16()); indices.Add(br.ReadUInt16()); br.ReadUInt16(); br.ReadUInt16(); br.ReadUInt16(); //loop on indices each 3 consecutive vertices compute normal } br.BaseStream.Seek(header.ofs_frames, SeekOrigin.Begin); vVertices = new List <List <vec3> >(); vNormalsindex = new List <List <int> >(); vNormals = new List <List <vec3> >(); for (int i = 0; i < header.num_frames; i++) { br.BaseStream.Seek((header.ofs_frames + (i * header.framesize)), SeekOrigin.Begin); vVertices.Add(new List <vec3>(header.num_xyz)); vNormalsindex.Add(new List <int>(header.num_xyz)); vNormals.Add(new List <vec3>(header.num_xyz)); vec3 scale = new vec3(); byte[] buffer; buffer = br.ReadBytes(4); scale.x = BitConverter.ToSingle(buffer, 0); buffer = br.ReadBytes(4); scale.y = BitConverter.ToSingle(buffer, 0); buffer = br.ReadBytes(4); scale.z = BitConverter.ToSingle(buffer, 0); vec3 trans = new vec3(); buffer = br.ReadBytes(4); trans.x = BitConverter.ToSingle(buffer, 0); buffer = br.ReadBytes(4); trans.y = BitConverter.ToSingle(buffer, 0); buffer = br.ReadBytes(4); trans.z = BitConverter.ToSingle(buffer, 0); string name = new string(br.ReadChars(16)); List <vertex_t> vts = new List <vertex_t>(); for (int j = 0; j < header.num_xyz; j++) { vertex_t vt = new vertex_t(); vt.v = br.ReadBytes(3); vt.lightnormalindex = br.ReadByte(); vts.Add(vt); } frame_t f = new frame_t(); f.scale = scale.to_array(); f.translate = trans.to_array(); f.name = name.ToCharArray(); f.verts = vts; for (int j = 0; j < header.num_xyz; j++) { vVertices[i].Add(new vec3(0)); vNormals[i].Add(new vec3(0)); vVertices[i][j] = new vec3() { x = f.translate[0] + ((float)f.verts[j].v[0]) * f.scale[0], y = f.translate[1] + ((float)f.verts[j].v[1]) * f.scale[1], z = f.translate[2] + ((float)f.verts[j].v[2]) * f.scale[2] }; vNormalsindex[i].Add(f.verts[j].lightnormalindex); } for (int j = 0; j < indices.Count - 3; j += 3) { vec3 n1 = vVertices[i][indices[j + 1]] - vVertices[i][indices[j]]; vec3 n2 = vVertices[i][indices[j + 2]] - vVertices[i][indices[j]]; vec3 normal = glm.cross(n1, n2); vNormals[i][indices[j]] = normal; vNormals[i][indices[j + 1]] = normal; vNormals[i][indices[j + 2]] = normal; } } Texture tex = null; string folder = Path.GetDirectoryName(path); if (skins.Count != 0) { tex = new Texture(folder + "\\" + skins[0] + ".png", 20, true); //if (tex.width == 0) //{ // int handle = FreeImage.FreeImage_Load(FIF.FIF_PCX, folder + "\\" + skins[0], 0); // FreeImage.FreeImage_Save(FIF.FIF_PNG, handle, folder + "\\" + skins[0] + ".png", 0); // FreeImage.FreeImage_Unload(handle); //} } if (tex == null || tex.height == 0) { if (skins.Count > 1) { tex = new Texture(skins[1], 20, true); texpath = skins[1]; } else { FileInfo fi = new FileInfo(path); string name = fi.Name; int index = fi.FullName.IndexOf(name, StringComparison.CurrentCulture); string filePath = ""; for (int i = 0; i < index; i++) { filePath += fi.FullName[i]; } string[] extensions = { "jpg", "jpeg", "png", "bmp", "tga" }; for (int i = 0; i < 4; i++) { string stry = filePath + name.Split('.')[0] + "." + extensions[i]; tex = new Texture(stry, 20, true); if (tex.width > 0) { texpath = filePath + name.Split('.')[0] + "." + extensions[i]; hasTex = 1; break; } } } } else { hasTex = 1; texpath = folder + "\\" + skins[0] + ".png"; } br.BaseStream.Seek(header.ofs_glcmds, SeekOrigin.Begin); List <int> cmds = new List <int>(); renderModes = new List <int>(); numRenderVertices = new List <int>(); anotherUV = new List <vec2>(); AvVertices = new List <List <vec3> >(); AvNormals = new List <List <vec3> >(); CvNormals = new List <vec3>(); CvVertices = new List <vec3>(); for (int j = 0; j < header.num_frames; j++) { AvVertices.Add(new List <vec3>()); AvNormals.Add(new List <vec3>()); } for (int i = 0; i < header.num_glcmds; i++) { cmds.Add(br.ReadInt32()); } int k = 0; while (true) { int action; if (cmds.Count > 0) { action = cmds[k]; if (action == 0) { break; } } else { action = 1; } int renderMode = action < 0 ? Gl.GL_TRIANGLE_FAN : Gl.GL_TRIANGLE_STRIP; int numVertices = action < 0 ? -action : action; k++; renderModes.Add(renderMode); numRenderVertices.Add(numVertices); for (int i = 0; i < numVertices; i++) { unsafe { int sd = cmds[k++]; int td = cmds[k++]; float s = *((float *)(&sd)); float t = *((float *)(&td)); if (flip) { t = 1 - t; } int vi = cmds[k++]; anotherUV.Add(new vec2(s, t)); for (int j = 0; j < header.num_frames; j++) { AvVertices[j].Add(vVertices[j][vi]); AvNormals[j].Add(vNormals[j][vi]); CvVertices.Add(new vec3(0, 0, 0)); CvNormals.Add(new vec3(0, 0, 0)); } } } } mVertices = vVertices[0]; m = new Model(); m.indices = indices; m.texture = tex; m.vertices = vVertices[0]; m.uvCoordinates = UVData; m.normals = vNormals[0]; vs = new float[AvVertices[0].Count * 3]; ns = new float[AvNormals[0].Count * 3]; if (AvVertices.Count > 0) { vertexBufferID = GPU.GenerateBuffer(AvVertices[0]); } if (AvNormals.Count > 0) { normalBufferID = GPU.GenerateBuffer(AvNormals[0]); } if (anotherUV.Count > 0) { uvBufferID = GPU.GenerateBuffer(anotherUV); } }
public void VertexMain() { _uv = Texcoord; gl_Position = ModelviewProjection * Vertex; }
public VerletPoint2D(vec2 p) { Position = p; OldPosition = p; }