public static int InterpolateColor(GamePlatform platform, float progress, int[] colors, int colorsLength) { float one = 1; int colora = platform.FloatToInt((colorsLength - 1) * progress); if (colora < 0) { colora = 0; } if (colora >= colorsLength) { colora = colorsLength - 1; } int colorb = colora + 1; if (colorb >= colorsLength) { colorb = colorsLength - 1; } int a = colors[colora]; int b = colors[colorb]; float p = (progress - (one * colora) / (colorsLength - 1)) * (colorsLength - 1); int A = platform.FloatToInt(Game.ColorA(a) + (Game.ColorA(b) - Game.ColorA(a)) * p); int R = platform.FloatToInt(Game.ColorR(a) + (Game.ColorR(b) - Game.ColorR(a)) * p); int G = platform.FloatToInt(Game.ColorG(a) + (Game.ColorG(b) - Game.ColorG(a)) * p); int B = platform.FloatToInt(Game.ColorB(a) + (Game.ColorB(b) - Game.ColorB(a)) * p); return(Game.ColorFromArgb(A, R, G, B)); }
static int VersionToInt(GamePlatform platform, string version) { int max = 1000 * 1000 * 1000; if (!IsVersionDate(platform, version)) { return(max); } FloatRef year = new FloatRef(); FloatRef month = new FloatRef(); FloatRef day = new FloatRef(); if (platform.FloatTryParse(StringTools.StringSubstring(platform, version, 0, 4), year)) { if (platform.FloatTryParse(StringTools.StringSubstring(platform, version, 5, 2), month)) { if (platform.FloatTryParse(StringTools.StringSubstring(platform, version, 8, 2), day)) { int year_ = platform.FloatToInt(year.value); int month_ = platform.FloatToInt(month.value); int day_ = platform.FloatToInt(day.value); return(year_ * 10000 + month_ * 100 + day_); } } } return(max); }
public static BitmapData_ CreateFromBitmap(GamePlatform p, BitmapCi atlas2d_) { BitmapData_ b = new BitmapData_(); b.width = p.FloatToInt(p.BitmapGetWidth(atlas2d_)); b.height = p.FloatToInt(p.BitmapGetHeight(atlas2d_)); b.argb = new int[b.width * b.height]; p.BitmapGetPixelsArgb(atlas2d_, b.argb); return b; }
static int Texture2d(GamePlatform platform, int[] pixelsArgb, float x, float y) { int px = platform.FloatToInt(x * (textureSize - 1)); int py = platform.FloatToInt(y * (textureSize - 1)); px = positive_modulo(px, (textureSize - 1)); py = positive_modulo(py, (textureSize - 1)); return(pixelsArgb[MapUtilCi.Index2d(px, py, textureSize)]); }
public static BitmapData_ CreateFromBitmap(GamePlatform p, BitmapCi atlas2d_) { BitmapData_ b = new BitmapData_(); b.width = p.FloatToInt(p.BitmapGetWidth(atlas2d_)); b.height = p.FloatToInt(p.BitmapGetHeight(atlas2d_)); b.argb = new int[b.width * b.height]; p.BitmapGetPixelsArgb(atlas2d_, b.argb); return(b); }
public BlockPosSide[] LineIntersection(DelegateIsBlockEmpty isEmpty, DelegateGetBlockHeight getBlockHeight, Line3D line, IntRef retCount) { lCount = 0; currentLine = line; currentHit[0] = 0; currentHit[1] = 0; currentHit[2] = 0; ListBox3d l1 = Search(PredicateBox3DHit.Create(this)); for (int i = 0; i < l1.count; i++) { Box3D node = l1.arr[i]; float[] hit = currentHit; float x = node.MinEdge[0]; float y = node.MinEdge[2]; float z = node.MinEdge[1]; if (!isEmpty.IsBlockEmpty(platform.FloatToInt(x), platform.FloatToInt(y), platform.FloatToInt(z))) { Box3D node2 = new Box3D(); node2.MinEdge = Vec3.CloneIt(node.MinEdge); node2.MaxEdge = Vec3.CloneIt(node.MaxEdge); node2.MaxEdge[1] = node2.MinEdge[1] + getBlockHeight.GetBlockHeight(platform.FloatToInt(x), platform.FloatToInt(y), platform.FloatToInt(z)); BlockPosSide b = new BlockPosSide(); float[] hit2 = new float[3]; float[] dir = new float[3]; dir[0] = line.End[0] - line.Start[0]; dir[1] = line.End[1] - line.Start[1]; dir[2] = line.End[2] - line.Start[2]; bool ishit = Intersection.HitBoundingBox(node2.MinEdge, node2.MaxEdge, line.Start, dir, hit2); if (ishit) { //hit2.pos = Vec3.FromValues(x, z, y); b.blockPos = Vec3.FromValues(platform.FloatToInt(x), platform.FloatToInt(z), platform.FloatToInt(y)); b.collisionPos = hit2; l[lCount++] = b; } } } BlockPosSide[] ll = new BlockPosSide[lCount]; for (int i = 0; i < lCount; i++) { ll[i] = l[i]; } retCount.value = lCount; return(ll); }
TextTexture GetTextTexture(string text, FontCi font) { for (int i = 0; i < textTexturesCount; i++) { TextTexture t = textTextures[i]; if (t == null) { continue; } if (t.text == text && t.font.size == font.size && t.font.family == font.family && t.font.style == font.style) { return(t); } } TextTexture textTexture = new TextTexture(); Text_ text_ = new Text_(); text_.text = text; text_.font = font; text_.color = Game.ColorFromArgb(255, 255, 255, 255); BitmapCi textBitmap = textColorRenderer.CreateTextTexture(text_); int texture = p.LoadTextureFromBitmap(textBitmap); IntRef textWidth = new IntRef(); IntRef textHeight = new IntRef(); p.TextSize(text, font, textWidth, textHeight); textTexture.texture = texture; textTexture.texturewidth = p.FloatToInt(p.BitmapGetWidth(textBitmap)); textTexture.textureheight = p.FloatToInt(p.BitmapGetHeight(textBitmap)); textTexture.text = text; textTexture.font = font; textTexture.textwidth = textWidth.value; textTexture.textheight = textHeight.value; p.BitmapDelete(textBitmap); textTextures[textTexturesCount++] = textTexture; return(textTexture); }
public static int InterpolateAngle256(GamePlatform platform, int a, int b, float progress) { if (progress != 0 && b != a) { int diff = NormalizeAngle256(b - a); if (diff >= CircleHalf256) { diff -= CircleFull256; } a += platform.FloatToInt(progress * diff); } return(NormalizeAngle256(a)); }
public static int InterpolateAngle256(GamePlatform platform, int a, int b, float progress) { if (progress != 0 && b != a) { int diff = NormalizeAngle256(b - a); if (diff >= CircleHalf256) { diff -= CircleFull256; } a += platform.FloatToInt(progress * diff); } return NormalizeAngle256(a); }
public int GetInt(string key, int default_) { if (GetString(key, null) == null) { return(default_); } FloatRef ret = new FloatRef(); if (platform.FloatTryParse(GetString(key, null), ret)) { return(platform.FloatToInt(ret.value)); } return(default_); }
void UpdateStatisticsText(float dt) { GamePlatform p = m.GetPlatform(); fpscount++; longestframedt = MathCi.MaxFloat(longestframedt, dt); float elapsed = one * (p.TimeMillisecondsFromStart() - lasttitleupdateMilliseconds) / 1000; if (elapsed >= 1) { lasttitleupdateMilliseconds = p.TimeMillisecondsFromStart(); string fpstext1 = p.IntToString(p.FloatToInt((one * fpscount) / elapsed)); fpstext1 = StringTools.StringAppend(p, fpstext1, p.StringFormat(" (min: {0})", p.IntToString(p.FloatToInt(one / longestframedt)))); longestframedt = 0; fpscount = 0; m.GetPerformanceInfo().Set("FPS", fpstext1); StatsLineCount = 0; for (int i = 0; i < m.GetPerformanceInfo().size; i++) { if (m.GetPerformanceInfo().items[i] == null) { continue; } if (m.GetPerformanceInfo().items[i].key == "Chunk updates") { UpdateChunkHistory(p.IntParse(m.GetPerformanceInfo().items[i].value)); } if (m.GetPerformanceInfo().items[i].key == "Ping") { UpdatePingHistory(p.IntParse(m.GetPerformanceInfo().items[i].value)); } if (StatsLineCount >= StatsMaxLineCount) { // Prevent running out of bounds break; } StatsLines[StatsLineCount++] = p.StringFormat2("{0}: {1}", m.GetPerformanceInfo().items[i].key, m.GetPerformanceInfo().items[i].value); } } }
/// <summary> /// Creates a bitmap from a given string /// </summary> /// <param name="t">The <see cref="Text_"/> object to create an image from</param> /// <returns>A <see cref="BitmapCi"/> containing the rendered text</returns> internal BitmapCi CreateTextTexture(Text_ t) { IntRef partsCount = new IntRef(); TextPart[] parts = DecodeColors(t.text, t.color, partsCount); float totalwidth = 0; float totalheight = 0; int[] sizesX = new int[partsCount.value]; int[] sizesY = new int[partsCount.value]; for (int i = 0; i < partsCount.value; i++) { IntRef outWidth = new IntRef(); IntRef outHeight = new IntRef(); platform.TextSize(parts[i].text, t.font, outWidth, outHeight); sizesX[i] = outWidth.value; sizesY[i] = outHeight.value; totalwidth += outWidth.value; totalheight = MathCi.MaxFloat(totalheight, outHeight.value); } int size2X = NextPowerOfTwo(platform.FloatToInt(totalwidth) + 1); int size2Y = NextPowerOfTwo(platform.FloatToInt(totalheight) + 1); BitmapCi bmp2 = platform.BitmapCreate(size2X, size2Y); int[] bmp2Pixels = new int[size2X * size2Y]; float currentwidth = 0; for (int i = 0; i < partsCount.value; i++) { int sizeiX = sizesX[i]; int sizeiY = sizesY[i]; if (sizeiX == 0 || sizeiY == 0) { continue; } Text_ partText = new Text_(); partText.text = parts[i].text; partText.color = parts[i].color; partText.font = t.font; BitmapCi partBmp = platform.CreateTextTexture(partText); int partWidth = platform.FloatToInt(platform.BitmapGetWidth(partBmp)); int partHeight = platform.FloatToInt(platform.BitmapGetHeight(partBmp)); int[] partBmpPixels = new int[partWidth * partHeight]; platform.BitmapGetPixelsArgb(partBmp, partBmpPixels); for (int x = 0; x < partWidth; x++) { for (int y = 0; y < partHeight; y++) { if (x + currentwidth >= size2X) { continue; } if (y >= size2Y) { continue; } int c = partBmpPixels[MapUtilCi.Index2d(x, y, partWidth)]; if (Game.ColorA(c) > 0) { bmp2Pixels[MapUtilCi.Index2d(platform.FloatToInt(currentwidth) + x, y, size2X)] = c; } } } currentwidth += sizeiX; } platform.BitmapSetPixelsArgb(bmp2, bmp2Pixels); return(bmp2); }
static int Texture2d(GamePlatform platform, int[] pixelsArgb, float x, float y) { int px = platform.FloatToInt(x * (textureSize - 1)); int py = platform.FloatToInt(y * (textureSize - 1)); px = positive_modulo(px, (textureSize - 1)); py = positive_modulo(py, (textureSize - 1)); return pixelsArgb[MapUtilCi.Index2d(px, py, textureSize)]; }
public override bool OnClientCommand(Game game, ClientCommandArgs args) { if (args.command == "cam") { IntRef argumentsLength = new IntRef(); string[] arguments = p.StringSplit(args.arguments, " ", argumentsLength); if (p.StringTrim(args.arguments) == "") { m.DisplayNotification("&6AutoCamera help."); m.DisplayNotification("&6.cam p&f - add a point to path"); m.DisplayNotification("&6.cam start [real seconds]&f - play the path"); m.DisplayNotification("&6.cam rec [real seconds] [video seconds]&f - play and record to .avi file"); m.DisplayNotification("&6.cam stop&f - stop playing and recording"); m.DisplayNotification("&6.cam clear&f - remove all points from path"); m.DisplayNotification("&6.cam save&f - copy path points to clipboard"); m.DisplayNotification("&6.cam load [points]&f - load path points"); return(true); } if (arguments[0] == "p") { m.DisplayNotification("Point defined."); CameraPoint point = new CameraPoint(); point.positionGlX = m.GetLocalPositionX(); point.positionGlY = m.GetLocalPositionY(); point.positionGlZ = m.GetLocalPositionZ(); point.orientationGlX = m.GetLocalOrientationX(); point.orientationGlY = m.GetLocalOrientationY(); point.orientationGlZ = m.GetLocalOrientationZ(); cameraPoints[cameraPointsCount++] = point; } if (arguments[0] == "start" || arguments[0] == "play" || arguments[0] == "rec") { if (!m.IsFreemoveAllowed()) { m.DisplayNotification("Free move not allowed."); return(true); } if (cameraPointsCount == 0) { m.DisplayNotification("No points defined. Enter points with \".cam p\" command."); return(true); } playingSpeed = 1; float totalRecTime = -1; if (arguments[0] == "rec") { if (argumentsLength.value >= 3) { // video time totalRecTime = p.FloatParse(arguments[2]); } avi = m.AviWriterCreate(); avi.Open(p.StringFormat("{0}.avi", p.Timestamp()), framerate, m.GetWindowWidth(), m.GetWindowHeight()); } if (argumentsLength.value >= 2) { // play time float totalTime = p.FloatParse(arguments[1]); playingSpeed = TotalDistance() / totalTime; if (totalRecTime == -1) { recspeed = 10; } else { recspeed = totalTime / totalRecTime; } } playingTime = 0; firstFrameDone = false; previousPositionX = m.GetLocalPositionX(); previousPositionY = m.GetLocalPositionY(); previousPositionZ = m.GetLocalPositionZ(); previousOrientationX = m.GetLocalOrientationX(); previousOrientationY = m.GetLocalOrientationY(); previousOrientationZ = m.GetLocalOrientationZ(); m.ShowGui(0); previousFreemove = m.GetFreemove(); m.SetFreemove(FreemoveLevelEnum.Noclip); m.EnableCameraControl(false); } if (arguments[0] == "stop") { m.DisplayNotification("Camera stopped."); Stop(); } if (arguments[0] == "clear") { m.DisplayNotification("Camera points cleared."); cameraPointsCount = 0; Stop(); } if (arguments[0] == "save") { string s = "1,"; for (int i = 0; i < cameraPointsCount; i++) { CameraPoint point = cameraPoints[i]; s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlX * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlY * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.positionGlZ * 100))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.orientationGlX * 1000))); s = p.StringFormat2("{0}{1},", s, p.IntToString(p.FloatToInt(point.orientationGlY * 1000))); s = p.StringFormat2("{0}{1}", s, p.IntToString(p.FloatToInt(point.orientationGlZ * 1000))); if (i != cameraPointsCount - 1) { s = p.StringFormat("{0},", s); } } p.ClipboardSetText(s); m.DisplayNotification("Camera points copied to clipboard."); } if (arguments[0] == "load") { IntRef pointsLength = new IntRef(); string[] points = p.StringSplit(arguments[1], ",", pointsLength); int n = (pointsLength.value - 1) / 6; cameraPointsCount = 0; for (int i = 0; i < n; i++) { CameraPoint point = new CameraPoint(); point.positionGlX = one * p.IntParse(points[1 + i * 6 + 0]) / 100; point.positionGlY = one * p.IntParse(points[1 + i * 6 + 1]) / 100; point.positionGlZ = one * p.IntParse(points[1 + i * 6 + 2]) / 100; point.orientationGlX = one * p.IntParse(points[1 + i * 6 + 3]) / 1000; point.orientationGlY = one * p.IntParse(points[1 + i * 6 + 4]) / 1000; point.orientationGlZ = one * p.IntParse(points[1 + i * 6 + 5]) / 1000; cameraPoints[cameraPointsCount++] = point; } m.DisplayNotification(p.StringFormat("Camera points loaded: {0}", p.IntToString(n))); } return(true); } return(false); }
int IntParse(string s) { return(p.FloatToInt(FloatParse(s))); }
void ProcessPacket(int client, Packet_Client packet) { switch (packet.GetId()) { case Packet_ClientIdEnum.PlayerIdentification: { if (packet.Identification == null) { return; } SendPacket(client, ServerPackets.Identification(0, MapSizeX, MapSizeY, MapSizeZ, platform.GetGameVersion())); clients[client].Name = packet.Identification.Username; } break; case Packet_ClientIdEnum.RequestBlob: { SendPacket(client, ServerPackets.LevelInitialize()); for (int i = 0; i < blockTypesCount; i++) { Packet_BlockType blocktype = blockTypes[i]; if (blocktype == null) { blocktype = new Packet_BlockType(); } SendPacket(client, ServerPackets.BlockType(i, blocktype)); } SendPacket(client, ServerPackets.BlockTypes()); SendPacket(client, ServerPackets.LevelFinalize()); for (int i = 0; i < clientsCount; i++) { if (clients[i] == null) { continue; } clients[i].glX = spawnGlX; clients[i].glY = spawnGlY; clients[i].glZ = spawnGlZ; Packet_PositionAndOrientation pos = new Packet_PositionAndOrientation(); pos.X = platform.FloatToInt(32 * clients[i].glX); pos.Y = platform.FloatToInt(32 * clients[i].glY); pos.Z = platform.FloatToInt(32 * clients[i].glZ); pos.Pitch = 255 / 2; //SendPacket(client, ServerPackets.Spawn(i, clients[i].Name, pos)); Packet_ServerEntity e = new Packet_ServerEntity(); e.DrawModel = new Packet_ServerEntityAnimatedModel(); e.DrawModel.Model_ = "player.txt"; e.DrawModel.ModelHeight = platform.FloatToInt((one * 17 / 10) * 32); e.DrawModel.EyeHeight = platform.FloatToInt((one * 15 / 10) * 32); e.Position = pos; SendPacket(client, ServerPackets.EntitySpawn(0, e)); SendPacket(client, ServerPackets.PlayerStats(100, 100, 100, 100)); } for (int i = 0; i < modsCount; i++) { mods[i].OnPlayerJoin(client); } clients[client].connected = true; } break; case Packet_ClientIdEnum.Message: { SendPacketToAll(ServerPackets.Message(platform.StringFormat2("{0}: &f{1}", clients[client].Name, packet.Message.Message))); } break; case Packet_ClientIdEnum.SetBlock: { int x = packet.SetBlock.X; int y = packet.SetBlock.Y; int z = packet.SetBlock.Z; int block = packet.SetBlock.BlockType; int mode = packet.SetBlock.Mode; if (mode == Packet_BlockSetModeEnum.Create) { } if (mode == Packet_BlockSetModeEnum.Destroy) { SendPacketToAll(ServerPackets.SetBlock(x, y, z, 0)); } if (mode == Packet_BlockSetModeEnum.Use) { } if (mode == Packet_BlockSetModeEnum.UseWithTool) { } } break; case Packet_ClientIdEnum.PositionandOrientation: { clients[client].glX = one * packet.PositionAndOrientation.X / 32; clients[client].glY = one * packet.PositionAndOrientation.Y / 32; clients[client].glZ = one * packet.PositionAndOrientation.Z / 32; } break; case Packet_ClientIdEnum.InventoryAction: { switch (packet.InventoryAction.Action) { case Packet_InventoryActionTypeEnum.Click: break; } } break; } }
void UpdateTitleFps(float dt) { GamePlatform p = m.GetPlatform(); fpscount++; longestframedt = MathCi.MaxFloat(longestframedt, dt); float elapsed = one * (p.TimeMillisecondsFromStart() - lasttitleupdateMilliseconds) / 1000; if (elapsed >= 1) { string fpstext1 = ""; lasttitleupdateMilliseconds = p.TimeMillisecondsFromStart(); fpstext1 = StringTools.StringAppend(p, fpstext1, p.StringFormat("FPS: {0}", p.IntToString(p.FloatToInt((one * fpscount) / elapsed)))); fpstext1 = StringTools.StringAppend(p, fpstext1, p.StringFormat(" (min: {0})", p.IntToString(p.FloatToInt(one / longestframedt)))); longestframedt = 0; fpscount = 0; m.GetPerformanceInfo().Set("fps", fpstext1); string s = ""; string[] l = new string[64]; int lCount = 0; for (int i = 0; i < m.GetPerformanceInfo().count; i++) { if (m.GetPerformanceInfo().items[i] == null) { continue; } l[lCount++] = m.GetPerformanceInfo().items[i].value; } int perline = 2; for (int i = 0; i < lCount; i++) { s = StringTools.StringAppend(p, s, l[i]); if ((i % perline == 0) && (i != lCount - 1)) { s = StringTools.StringAppend(p, s, ", "); } if (i % perline != 0) { s = StringTools.StringAppend(p, s, "\n"); } } fpstext = s; } }
public static int InterpolateColor(GamePlatform platform, float progress, int[] colors, int colorsLength) { float one = 1; int colora = platform.FloatToInt((colorsLength - 1) * progress); if (colora < 0) { colora = 0; } if (colora >= colorsLength) { colora = colorsLength - 1; } int colorb = colora + 1; if (colorb >= colorsLength) { colorb = colorsLength - 1; } int a = colors[colora]; int b = colors[colorb]; float p = (progress - (one * colora) / (colorsLength - 1)) * (colorsLength - 1); int A = platform.FloatToInt(Game.ColorA(a) + (Game.ColorA(b) - Game.ColorA(a)) * p); int R = platform.FloatToInt(Game.ColorR(a) + (Game.ColorR(b) - Game.ColorR(a)) * p); int G = platform.FloatToInt(Game.ColorG(a) + (Game.ColorG(b) - Game.ColorG(a)) * p); int B = platform.FloatToInt(Game.ColorB(a) + (Game.ColorB(b) - Game.ColorB(a)) * p); return Game.ColorFromArgb(A, R, G, B); }
static int VersionToInt(GamePlatform platform, string version) { int max = 1000 * 1000 * 1000; if (!IsVersionDate(platform, version)) { return max; } FloatRef year = new FloatRef(); FloatRef month = new FloatRef(); FloatRef day = new FloatRef(); if (platform.FloatTryParse(StringTools.StringSubstring(platform, version, 0, 4), year)) { if (platform.FloatTryParse(StringTools.StringSubstring(platform, version, 5, 2), month)) { if (platform.FloatTryParse(StringTools.StringSubstring(platform, version, 8, 2), day)) { int year_ = platform.FloatToInt(year.value); int month_ = platform.FloatToInt(month.value); int day_ = platform.FloatToInt(day.value); return year_ * 10000 + month_ * 100 + day_; } } } return max; }
public ModelData GetSphereModelData2(ModelData data, GamePlatform platform, float radius, float height, int segments, int rings, int[] skyPixels_, int[] glowPixels_, float sunX, float sunY, float sunZ) { int i = 0; if (data == null) { data = new ModelData(); data.xyz = new float[rings * segments * 3]; data.uv = new float[rings * segments * 2]; data.rgba = new byte[rings * segments * 4]; data.SetVerticesCount(segments * rings); data.SetIndicesCount(segments * rings * 6); data.setIndices(SphereModelData.CalculateElements(radius, height, segments, rings)); } // Load data into a vertex buffer or a display list afterwards. for (int y = 0; y < rings; y++) { float yFloat = y; float phiFloat = (yFloat / (rings - 1)) * Game.GetPi(); for (int x = 0; x < segments; x++) { float xFloat = x; float theta = (xFloat / (segments - 1)) * 2 * Game.GetPi(); float vx = radius * Platform.Sin(phiFloat) * Platform.Cos(theta); float vy = height * Platform.Cos(phiFloat); float vz = radius * Platform.Sin(phiFloat) * Platform.Sin(theta); float u = xFloat / (segments - 1); float v = yFloat / (rings - 1); data.xyz[i * 3 + 0] = vx; data.xyz[i * 3 + 1] = vy; data.xyz[i * 3 + 2] = vz; data.uv[i * 2 + 0] = u; data.uv[i * 2 + 1] = v; float vertexLength = platform.MathSqrt(vx * vx + vy * vy + vz * vz); float vertexXNormalized = vx / vertexLength; float vertexYNormalized = vy / vertexLength; float vertexZNormalized = vz / vertexLength; float sunLength = platform.MathSqrt(sunX * sunX + sunY * sunY + sunZ * sunZ); if (sunLength == 0) { sunLength = 1; } float sunXNormalized = sunX / sunLength; float sunYNormalized = sunY / sunLength; float sunZNormalized = sunZ / sunLength; // Compute the proximity of this fragment to the sun. float dx = vertexXNormalized - sunXNormalized; float dy = vertexYNormalized - sunYNormalized; float dz = vertexZNormalized - sunZNormalized; float proximityToSun = 1 - (platform.MathSqrt(dx * dx + dy * dy + dz * dz) / 2); // Look up the sky color and glow colors. float one = 1; int skyColor = Texture2d(platform, skyPixels_, (sunYNormalized + 2) / 4, 1 - ((vertexYNormalized + 1) / 2)); float skyColorA = one * Game.ColorA(skyColor) / 255; float skyColorR = one * Game.ColorR(skyColor) / 255; float skyColorG = one * Game.ColorG(skyColor) / 255; float skyColorB = one * Game.ColorB(skyColor) / 255; int glowColor = Texture2d(platform, glowPixels_, (sunYNormalized + one) / 2, 1 - proximityToSun); float glowColorA = one * Game.ColorA(glowColor) / 255; float glowColorR = one * Game.ColorR(glowColor) / 255; float glowColorG = one * Game.ColorG(glowColor) / 255; float glowColorB = one * Game.ColorB(glowColor) / 255; // Combine the color and glow giving the pixel value. float colorR = skyColorR + glowColorR * glowColorA; float colorG = skyColorG + glowColorG * glowColorA; float colorB = skyColorB + glowColorB * glowColorA; float colorA = skyColorA; if (colorR > 1) { colorR = 1; } if (colorG > 1) { colorG = 1; } if (colorB > 1) { colorB = 1; } if (colorA > 1) { colorA = 1; } data.rgba[i * 4 + 0] = Game.IntToByte(platform.FloatToInt(colorR * 255)); data.rgba[i * 4 + 1] = Game.IntToByte(platform.FloatToInt(colorG * 255)); data.rgba[i * 4 + 2] = Game.IntToByte(platform.FloatToInt(colorB * 255)); data.rgba[i * 4 + 3] = Game.IntToByte(platform.FloatToInt(colorA * 255)); i++; } } //data.setMode(DrawModeEnum.Triangles); return(data); }
public ModelData GetSphereModelData2(ModelData data, GamePlatform platform, float radius, float height, int segments, int rings, int[] skyPixels_, int[] glowPixels_, float sunX, float sunY, float sunZ) { int i = 0; if (data == null) { data = new ModelData(); data.xyz = new float[rings * segments * 3]; data.uv = new float[rings * segments * 2]; data.rgba = new byte[rings * segments * 4]; data.SetVerticesCount(segments * rings); data.SetIndicesCount(segments * rings * 6); data.setIndices(SphereModelData.CalculateElements(radius, height, segments, rings)); } // Load data into a vertex buffer or a display list afterwards. for (int y = 0; y < rings; y++) { float yFloat = y; float phiFloat = (yFloat / (rings - 1)) * Game.GetPi(); for (int x = 0; x < segments; x++) { float xFloat = x; float theta = (xFloat / (segments - 1)) * 2 * Game.GetPi(); float vx = radius * Platform.Sin(phiFloat) * Platform.Cos(theta); float vy = height * Platform.Cos(phiFloat); float vz = radius * Platform.Sin(phiFloat) * Platform.Sin(theta); float u = xFloat / (segments - 1); float v = yFloat / (rings - 1); data.xyz[i * 3 + 0] = vx; data.xyz[i * 3 + 1] = vy; data.xyz[i * 3 + 2] = vz; data.uv[i * 2 + 0] = u; data.uv[i * 2 + 1] = v; float vertexLength = platform.MathSqrt(vx * vx + vy * vy + vz * vz); float vertexXNormalized = vx / vertexLength; float vertexYNormalized = vy / vertexLength; float vertexZNormalized = vz / vertexLength; float sunLength = platform.MathSqrt(sunX * sunX + sunY * sunY + sunZ * sunZ); if (sunLength == 0) { sunLength = 1; } float sunXNormalized = sunX / sunLength; float sunYNormalized = sunY / sunLength; float sunZNormalized = sunZ / sunLength; // Compute the proximity of this fragment to the sun. float dx = vertexXNormalized - sunXNormalized; float dy = vertexYNormalized - sunYNormalized; float dz = vertexZNormalized - sunZNormalized; float proximityToSun = 1 - (platform.MathSqrt(dx * dx + dy * dy + dz * dz) / 2); // Look up the sky color and glow colors. float one = 1; int skyColor = Texture2d(platform, skyPixels_, (sunYNormalized + 2) / 4, 1 - ((vertexYNormalized + 1) / 2)); float skyColorA = one * Game.ColorA(skyColor) / 255; float skyColorR = one * Game.ColorR(skyColor) / 255; float skyColorG = one * Game.ColorG(skyColor) / 255; float skyColorB = one * Game.ColorB(skyColor) / 255; int glowColor = Texture2d(platform, glowPixels_, (sunYNormalized + one) / 2, 1 - proximityToSun); float glowColorA = one * Game.ColorA(glowColor) / 255; float glowColorR = one * Game.ColorR(glowColor) / 255; float glowColorG = one * Game.ColorG(glowColor) / 255; float glowColorB = one * Game.ColorB(glowColor) / 255; // Combine the color and glow giving the pixel value. float colorR = skyColorR + glowColorR * glowColorA; float colorG = skyColorG + glowColorG * glowColorA; float colorB = skyColorB + glowColorB * glowColorA; float colorA = skyColorA; if (colorR > 1) { colorR = 1; } if (colorG > 1) { colorG = 1; } if (colorB > 1) { colorB = 1; } if (colorA > 1) { colorA = 1; } data.rgba[i * 4 + 0] = Game.IntToByte(platform.FloatToInt(colorR * 255)); data.rgba[i * 4 + 1] = Game.IntToByte(platform.FloatToInt(colorG * 255)); data.rgba[i * 4 + 2] = Game.IntToByte(platform.FloatToInt(colorB * 255)); data.rgba[i * 4 + 3] = Game.IntToByte(platform.FloatToInt(colorA * 255)); i++; } } //data.setMode(DrawModeEnum.Triangles); return data; }
void DrawLocalPosition(Game game) { if (DRAW_POSITION) { GamePlatform p = m.GetPlatform(); float heading = (((m.GetLocalOrientationY()) % (2 * Game.GetPi())) / (2 * Game.GetPi())) * 256; float pitch = (((m.GetLocalOrientationX() + Game.GetPi()) % (2 * Game.GetPi())) / (2 * Game.GetPi())) * 256; // Y and Z axis are swapped for display as Z axis depicts height PositionLines[0] = p.StringFormat("X: {0}", p.IntToString(game.MathFloor(m.GetLocalPositionX()))); PositionLines[1] = p.StringFormat("Y: {0}", p.IntToString(game.MathFloor(m.GetLocalPositionZ()))); PositionLines[2] = p.StringFormat("Z: {0}", p.IntToString(game.MathFloor(m.GetLocalPositionY()))); PositionLines[3] = p.StringFormat("Heading: {0}", p.IntToString(Game.IntToByte(p.FloatToInt(heading)))); PositionLines[4] = p.StringFormat("Pitch: {0}", p.IntToString(Game.IntToByte(p.FloatToInt(pitch)))); m.OrthoMode(); for (int i = 0; i < PositionLinesCount; i++) { m.Draw2dText(PositionLines[i], 20, m.GetWindowHeight() - 100 + 1.5f * i * displayFont.size, displayFont); } m.PerspectiveMode(); } }