public static CompoundTransform create_from( ClassTransformManager obj, CompoundVector2 size, CompoundVector2 handle, CompoundRadians angle, CompoundVector2 scale, CompoundVector2 position, bool hflip, bool vflip) { double handle_x = handle.property_x; double handle_y = handle.property_y; double size_x = size.property_x; double size_y = size.property_y; double scale_x = scale.property_x; double scale_y = scale.property_y; if (hflip || vflip) { handle_x -= size_x / 2.0; handle_y -= size_y / 2.0; } double cost = Math.Cos(angle.property_value); double sint = Math.Sin(angle.property_value); double r1c1 = cost*scale_x; double r1c2 = -sint*scale_y; double r1c3 = position.property_x - scale_x*handle_x*cost + sint*scale_y*handle_y; double r2c1 = sint*scale_x; double r2c2 = cost*scale_y; double r2c3 = position.property_y - scale_x*handle_x*sint - cost*scale_y*handle_y; Matrix2x3 m = new Matrix2x3(r1c1,r1c2,r1c3,r2c1,r2c2,r2c3); if (hflip || vflip) { if (hflip) { if (vflip) { m = m.times( new Matrix2x3(-1,0,0,0,-1,0) ); } else { m = m.times( new Matrix2x3(-1,0,0,0,1,0) ); } } else { m = m.times( new Matrix2x3(1,0,0,0,-1,0) ); } // translate by -size/2 m = m.times( new Matrix2x3(1,0,-size_x/2.0,0,1,-size_y/2.0) ); } return new CompoundTransform( new CompoundTransformRow(m.r1c1,m.r1c2,m.r1c3), new CompoundTransformRow(m.r2c1,m.r2c2,m.r2c3) ); }
public static Vector3 v3( CompoundVector2 v ) { return new Vector3( (float) v.property_x, (float) v.property_y, 0f ); }
public static void init( ClassTexture texture, CompoundVector2 size, int pixel_format ) { int w = (int) size.property_x; int h = (int) size.property_y; int wp2 = 1; while (wp2 < w) wp2 <<= 1; int hp2 = 1; while (hp2 < h) hp2 <<= 1; Texture2D tex = new Texture2D( Plasmacore.device, wp2, hp2, false, SurfaceFormat.Color ); texture.property_native_data = new NativeTextureData(tex); texture.property_image_size.property_x = w; texture.property_image_size.property_y = h; texture.property_texture_size.property_x = wp2; texture.property_texture_size.property_y = hp2; }
public static void set( ClassTexture texture, ClassBitmap bitmap, CompoundVector2 pos ) { int[] data = bitmap.property_data; int count = data.Length; int w = bitmap.property_width; int h = bitmap.property_height; Color[] colors = new Color[w*h]; int src_pos = -1; int dest_pos = -1; for (int j=h; j>0; --j) { for (int i=w; i>0; --i) { // premultiply color components by alpha component int c = data[++src_pos]; int a = (c >> 24) & 255; int r = (c >> 16) & 255; int g = (c >> 8) & 255; int b = c & 255; colors[++dest_pos] = new Color( (r*a)/255, (g*a)/255, (b*a)/255, a ); } } Texture2D tex = ((NativeTextureData) texture.property_native_data).texture; tex.SetData<Color>( 0, new Rectangle((int)pos.property_x,(int)pos.property_y,w,h), colors, 0, w*h ); }
public static void init( ClassTexture texture, CompoundVector2 size ) { // TODO: implement for offscreen buffers /* int w = (int) size.property_x; int h = (int) size.property_y; int wp2 = 1; while (wp2 < w) wp2 <<= 1; int hp2 = 1; while (hp2 < h) hp2 <<= 1; Texture2D tex = new Texture2D( Plasmacore.device, wp2, hp2, false, SurfaceFormat.Color ); texture.property_native_data = new NativeTextureData(tex); texture.property_image_size.property_x = w; texture.property_image_size.property_y = h; texture.property_texture_size.property_x = wp2; texture.property_texture_size.property_y = hp2; */ }
public static void draw_tile( ClassTexture texture, CompoundCorners uv, CompoundVector2 pos, CompoundVector2 size, int render_flags) { Bard.log("TODO: NativeTexture::draw_tile()"); }
public static void draw_tile( ClassTexture texture, CompoundCorners uv, CompoundVector2 pos, CompoundVector2 size, CompoundRender render_flags) { draw_tile( texture, uv, pos, size, render_flags.property_flags ); }
public static void draw( ClassTexture texture, CompoundCorners uv, CompoundVector2 size, CompoundColor color, CompoundRender render_flags, CompoundBlend blend_fn, ClassTexture alpha_texture, CompoundCorners alpha_uv) { Bard.log("TODO: NativeTexture::draw()"); }
public static void draw( ClassTexture texture, CompoundCorners uv, CompoundVector2 size, CompoundColor color, CompoundRender render_flags, CompoundBlend blend_fn) { DrawBuffer.set_render_flags( render_flags.property_flags, blend_fn.property_src_blend, blend_fn.property_dest_blend ); DrawBuffer.set_textured_triangle_mode( texture, null ); Vector3 pt1 = new Vector3( 0, 0, 0 ); Vector3 pt2 = new Vector3( (float) size.property_x, 0, 0 ); Vector3 pt3 = new Vector3( (float) size.property_x, (float) size.property_y, 0 ); Vector3 pt4 = new Vector3( 0, (float) size.property_y, 0 ); NativeTransformManager.update(); pt1 = NativeTransformManager.transform.transform( pt1 ); pt2 = NativeTransformManager.transform.transform( pt2 ); pt3 = NativeTransformManager.transform.transform( pt3 ); pt4 = NativeTransformManager.transform.transform( pt4 ); Color c; //if ((render_flags.property_flags & DrawBuffer.RENDER_FLAG_FIXED_COLOR) != 0) //{ //c = Color.White; //} //else //{ int argb = color.property_argb; c = new Color((argb>>16)&255,(argb>>8)&255,argb&255,(argb>>24)&255); //} float uv_a_x = (float) uv.property_top_left.property_x; float uv_a_y = (float) uv.property_top_left.property_y; float uv_b_x = (float) uv.property_bottom_right.property_x; float uv_b_y = (float) uv.property_bottom_right.property_y; VertexPositionColorTexture v1, v2, v3, v4; v1 = new VertexPositionColorTexture( pt1, c, new Vector2( uv_a_x, uv_a_y ) ); v2 = new VertexPositionColorTexture( pt2, c, new Vector2( uv_b_x, uv_a_y ) ); v3 = new VertexPositionColorTexture( pt3, c, new Vector2( uv_b_x, uv_b_y ) ); v4 = new VertexPositionColorTexture( pt4, c, new Vector2( uv_a_x, uv_b_y ) ); DrawBuffer.add( v1, v2, v4 ); DrawBuffer.add( v4, v2, v3 ); }