Oxygine  1
2g game engine
MaskedRenderer.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "STDRenderer.h"
4 
5 namespace oxygine
6 {
7  class ClipUV
8  {
9  public:
10  ClipUV() {}
11  ClipUV(const Vector2& a, const Vector2& b, const Vector2& c,
12  const Vector2& a_uv, const Vector2& b_uv, const Vector2& c_uv) : _uvA(a_uv)
13  {
14  _dAB = b - a;
15  _dAC = c - a;
16 
17  float v = 1.0f / (_dAB.x * _dAC.y - _dAB.y * _dAC.x);
18  _dAB *= v;
19  _dAC *= v;
20 
21  _dac.x = _dAC.x * a.y - _dAC.y * a.x;
22  _dac.y = -(_dAB.x * a.y - _dAB.y * a.x);
23 
24  _dAB *= -1;
25 
26  _dAB.x *= -1;
27  _dAC.x *= -1;
28 
29  _duvAB = b_uv - _uvA;
30  _duvAC = c_uv - _uvA;
31  }
32 
33  void get(Vector3* vec) const
34  {
35  vec[0] = Vector3(_dac.x, _dAC.y, _dAC.x);
36  vec[1] = Vector3(_dac.y, _dAB.y, _dAB.x);
37 
38  vec[2] = Vector3(_uvA.x, _duvAB.x, _duvAC.x);
39  vec[3] = Vector3(_uvA.y, _duvAB.y, _duvAC.y);
40  }
41 
42  Vector2 calc(const Vector2& pos) const
43  {
44  //float a = _dac.x + _dAC.y * pos.x - _dAC.x * pos.y;
45  //float b = _dac.y + _dAB.y * pos.x - _dAB.x * pos.y;
46 
47  //Vector3 q =
48 
49  float a = Vector3(_dac.x, _dAC.y, _dAC.x).dot(Vector3(1, pos.x, pos.y));
50  float b = Vector3(_dac.y, _dAB.y, _dAB.x).dot(Vector3(1, pos.x, pos.y));
51 
52  //float u = _uvA.x + _duvAB.x * a + _duvAC.x * b;
53  //float v = _uvA.y + _duvAB.y * a + _duvAC.y * b;
54  float u = Vector3(_uvA.x, _duvAB.x, _duvAC.x).dot(Vector3(1, a, b));
55  float v = Vector3(_uvA.y, _duvAB.y, _duvAC.y).dot(Vector3(1, a, b));
56 
57  //Matrix
58 
59  return Vector2(u, v);
60  }
61 
62  protected:
63  Vector2 _dac;
64  Vector2 _uvA;
65 
66  Vector2 _dAB;
67  Vector2 _dAC;
68  Vector2 _duvAB;
69  Vector2 _duvAC;
70  };
71 
72  class MaskedRenderer : public STDRenderer
73  {
74  public:
75  MaskedRenderer(spNativeTexture mask, const RectF& srcRect, const RectF& destRect, const Transform& t, bool channelR, IVideoDriver*);
76 
77  //void draw(const RState *rs, const RectF &destRect) OVERRIDE;
78 
79  protected:
80  void preDrawBatch();
81  //void addVertices(const void *data, unsigned int size, const VertexDeclaration *decl) OVERRIDE;
82 
83  spNativeTexture _mask;
84  RectF _clipMask;
85  ClipUV _clipUV;
86  };
87 }
Definition: STDRenderer.h:7
–oxgl-end–!
Definition: Actor.h:14
Definition: VideoDriver.h:12
Definition: MaskedRenderer.h:72
Definition: MaskedRenderer.h:7
Definition: Vector3.h:7