MCPcopy Create free account
hub / github.com/ad-si/LuaCAD / setIntersected

Method setIntersected

OpenCSG/src/scissorMemo.cpp:98–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96 }
97
98 void ScissorMemo::setIntersected(const std::vector<Primitive*>& primitives) {
99
100 float& minx = mIntersection.minx;
101 float& miny = mIntersection.miny;
102 float& minz = mIntersection.minz;
103 float& maxx = mIntersection.maxx;
104 float& maxy = mIntersection.maxy;
105 float& maxz = mIntersection.maxz;
106
107 // dont let intersected area exceed scissor region set by the application (outside OpenCSG)
108 const int dx = OpenGL::canvasPos[2] - OpenGL::canvasPos[0];
109 const int dy = OpenGL::canvasPos[3] - OpenGL::canvasPos[1];
110
111 const float sx = 2.0f * (static_cast<float>(OpenGL::scissorPos[0]) / static_cast<float>(dx)) - 1.0f;
112 const float sy = 2.0f * (static_cast<float>(OpenGL::scissorPos[1]) / static_cast<float>(dy)) - 1.0f;
113 const float swx = 2.0f * (static_cast<float>(OpenGL::scissorPos[2] + OpenGL::scissorPos[0]) / static_cast<float>(dx)) - 1.0f;
114 const float swy = 2.0f * (static_cast<float>(OpenGL::scissorPos[3] + OpenGL::scissorPos[1]) / static_cast<float>(dy)) - 1.0f;
115
116 minx = sx; maxx = swx;
117 miny = sy; maxy = swy;
118
119 minz = 0.0f; maxz = 1.0f; // might read current depth value, but usefulness is unclear
120
121 for (std::vector<Primitive*>::const_iterator itr = primitives.begin(); itr != primitives.end(); ++itr) {
122 if ((*itr)->getOperation() == Intersection) {
123 float tminx, tminy, tminz, tmaxx, tmaxy, tmaxz;
124 (*itr)->getBoundingBox(tminx, tminy, tminz, tmaxx, tmaxy, tmaxz);
125
126 minx = (std::max)(minx, tminx);
127 miny = (std::max)(miny, tminy);
128 minz = (std::max)(minz, tminz);
129 maxx = (std::min)(maxx, tmaxx);
130 maxy = (std::min)(maxy, tmaxy);
131 maxz = (std::min)(maxz, tmaxz);
132 }
133 }
134
135 minx = (std::max)(-1.0f, minx);
136 minx = (std::min)( 1.0f, minx);
137 miny = (std::max)(-1.0f, miny);
138 miny = (std::min)( 1.0f, miny);
139 minz = (std::max)( 0.0f, minz);
140 minz = (std::min)( 1.0f, minz);
141 maxx = (std::max)(-1.0f, maxx);
142 maxx = (std::min)( 1.0f, maxx);
143 maxy = (std::max)(-1.0f, maxy);
144 maxy = (std::min)( 1.0f, maxy);
145 maxz = (std::max)( 0.0f, maxz);
146 maxz = (std::min)( 1.0f, maxz);
147
148 calculateArea();
149 }
150
151 const NDCVolume& ScissorMemo::getIntersectedArea() const {
152 return mIntersection;

Callers 4

renderSCSFunction · 0.80
renderGoldfeatherFunction · 0.80

Calls 4

beginMethod · 0.80
endMethod · 0.80
getOperationMethod · 0.80
getBoundingBoxMethod · 0.80

Tested by

no test coverage detected