public void DrawModel() { int width = Controls[(SoftwareRendering ? 2 : 1)].Width; int height = Controls[(SoftwareRendering ? 2 : 1)].Height; Array.Copy(checkerboard, pixel_buffer, pixel_buffer.Length); DrawingArea.initDrawingArea(height, width, pixel_buffer); Rasterizer.method364(); bool success = false; if (SelectedModel != null) { try { int k3 = Rasterizer.center_x; int j4 = Rasterizer.center_y; Rasterizer.center_x = c_x + DrawingArea.width / 2; Rasterizer.center_y = c_y + DrawingArea.height / 2; while (Yaw < 0) { Yaw += Model.SIN.Length; } while (Pitch < 0) { Pitch += Model.COS.Length; } while (Roll < 0) { Roll += Model.COS.Length; } Yaw %= Model.SIN.Length; Pitch %= Model.COS.Length; Roll %= Model.COS.Length; int i5 = Rasterizer.SIN[Yaw] * c_z >> 16; int l5 = Rasterizer.COS[Yaw] * c_z >> 16; bool animated = false; //interfaceIsSelected(class9_1); int i7; /*if (animated) * i7 = class9_1.anInt258; * else * i7 = class9_1.anInt257; * Model model; * if (i7 == -1) * { * model = class9_1.method209(-1, -1, animated); * } * else * { * Animation animation = Animation.anims[i7]; * model = class9_1.method209(animation.anIntArray354[class9_1.anInt246], animation.anIntArray353[class9_1.anInt246], animated); * }*/ if (SelectedModel != null) { SelectedModel.Render(Pitch, Roll, Yaw, 0, i5, l5); } Rasterizer.center_x = k3; Rasterizer.center_y = j4; if (!SoftwareRendering) { Gl.glClearColor(.5f, 1, 1, 1); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(0, width, 0, height, -1, 1); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glViewport(0, 0, width, height); Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, 0, 0, width, height, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, DrawingArea.pixels); Gl.glBegin(Gl.GL_QUADS); Gl.glTexCoord2d(0.0, 1.0); Gl.glVertex2d(0.0, 0.0); Gl.glTexCoord2d(1.0, 1.0); Gl.glVertex2d(width, 0.0); Gl.glTexCoord2d(1.0, 0.0); Gl.glVertex2d(width, height); Gl.glTexCoord2d(0.0, 0.0); Gl.glVertex2d(0.0, height); Gl.glEnd(); gl_control.Invalidate(); } else { software_control.Image = DrawingArea.ToBitmap(); } success = true; } catch (Exception) { success = false; } } else { Controls[(SoftwareRendering ? 2 : 1)].Visible = false; Controls[0].Visible = true; this.Invalidate(); } if (!success) { Controls[(SoftwareRendering ? 2 : 1)].Visible = false; Controls[0].Visible = true; if (!SoftwareRendering) { gl_control.Invalidate(); } else { software_control.Invalidate(); } } else { Controls[(SoftwareRendering ? 2 : 1)].Visible = true; Controls[0].Visible = false; } }
public static RSImage GetModelSprite(int id, int amount, int selection_color) { Color k_color = Color.FromArgb(selection_color); ItemDefinition itemDef = GetItem(id); if (itemDef.StackedItemIDs == null) { amount = -1; } if (amount > 1) { int i1 = -1; for (int j1 = 0; j1 < 10; j1++) { if (amount >= itemDef.StackChangeAmounts[j1] && itemDef.StackChangeAmounts[j1] != 0) { i1 = itemDef.StackedItemIDs[j1]; } } if (i1 != -1) { itemDef = GetItem(i1); } } Model model = itemDef.GetModel(1); if (model == null) { return(null); } RSImage sprite = null; if (itemDef.NotedModelItemID != -1) { sprite = GetModelSprite(itemDef.NotedID, 10, -1); if (sprite == null) { return(null); } } RSImage sprite2 = new RSImage(32, 32); int k1 = Rasterizer.center_x; int l1 = Rasterizer.center_y; int[] ai = Rasterizer.line_pixel_locations; int[] ai1 = DrawingArea.pixels; int i2 = DrawingArea.width; int j2 = DrawingArea.height; int k2 = DrawingArea.topX; int l2 = DrawingArea.bottomX; int i3 = DrawingArea.topY; int j3 = DrawingArea.bottomY; Rasterizer.aBoolean1464 = false; DrawingArea.initDrawingArea(32, 32, new int[32 * 32]); DrawingArea.method336(32, 0, 0, 0, 32); Rasterizer.method364(); int k3 = itemDef.Zoom; if (selection_color == -1) { k3 = (int)((double)k3 * 1.5D); } if (selection_color > 0) { k3 = (int)((double)k3 * 1.04D); } int l3 = Rasterizer.SIN[itemDef.RotationX] * k3 >> 16; int i4 = Rasterizer.COS[itemDef.RotationX] * k3 >> 16; model.Render(itemDef.RotationY, itemDef.RotationZ, itemDef.RotationX, itemDef.SpriteX, l3 + model.modelHeight / 2 + itemDef.SpriteY, i4 + itemDef.SpriteY); //draw the black outline for (int i5 = 31; i5 >= 0; i5--) { for (int j4 = 31; j4 >= 0; j4--) { if (DrawingArea.pixels[i5 + j4 * 32] == 0) { if (i5 > 0 && DrawingArea.pixels[(i5 - 1) + j4 * 32] > 1) { DrawingArea.pixels[i5 + j4 * 32] = 1; } else if (j4 > 0 && DrawingArea.pixels[i5 + (j4 - 1) * 32] > 1) { DrawingArea.pixels[i5 + j4 * 32] = 1; } else if (i5 < 31 && DrawingArea.pixels[i5 + 1 + j4 * 32] > 1) { DrawingArea.pixels[i5 + j4 * 32] = 1; } else if (j4 < 31 && DrawingArea.pixels[i5 + (j4 + 1) * 32] > 1) { DrawingArea.pixels[i5 + j4 * 32] = 1; } } } } //draw the selection outline or shadow if (selection_color > 0) //selection outline { for (int j5 = 31; j5 >= 0; j5--) { for (int k4 = 31; k4 >= 0; k4--) { if (DrawingArea.pixels[j5 + k4 * 32] == 0) { if (j5 > 0 && DrawingArea.pixels[(j5 - 1) + k4 * 32] == 1) { DrawingArea.pixels[j5 + k4 * 32] = selection_color; } else if (k4 > 0 && DrawingArea.pixels[j5 + (k4 - 1) * 32] == 1) { DrawingArea.pixels[j5 + k4 * 32] = selection_color; } else if (j5 < 31 && DrawingArea.pixels[j5 + 1 + k4 * 32] == 1) { DrawingArea.pixels[j5 + k4 * 32] = selection_color; } else if (k4 < 31 && DrawingArea.pixels[j5 + (k4 + 1) * 32] == 1) { DrawingArea.pixels[j5 + k4 * 32] = selection_color; } } } } } else if (selection_color == 0) //shadow { for (int k5 = 31; k5 >= 0; k5--) { for (int l4 = 31; l4 >= 0; l4--) { if (DrawingArea.pixels[k5 + l4 * 32] == 0 && k5 > 0 && l4 > 0 && DrawingArea.pixels[(k5 - 1) + (l4 - 1) * 32] > 0) { DrawingArea.pixels[k5 + l4 * 32] = 0x302020; } } } } if (itemDef.NotedModelItemID != -1) { int l5 = sprite.WholeWidth; int j6 = sprite.WholeHeight; sprite.WholeWidth = 32; sprite.WholeHeight = 32; DrawingArea.DrawRSImage(sprite, 0, 0); sprite.WholeWidth = l5; sprite.WholeHeight = j6; } sprite2.SetPixels(DrawingArea.pixels); DrawingArea.initDrawingArea(j2, i2, ai1); DrawingArea.setDrawingArea(j3, k2, l2, i3); Rasterizer.center_x = k1; Rasterizer.center_y = l1; Rasterizer.line_pixel_locations = ai; Rasterizer.aBoolean1464 = true; if (itemDef.Stackable) { sprite2.WholeWidth = 33; } else { sprite2.WholeWidth = 32; } sprite2.WholeHeight = amount; return(sprite2); }