2

Using Visual Studio 2017 and OpenFrameworks

I've drawn a triangle as follows:

ofDrawTriangle(ofPoint(0, -fHigh / 2, 0), 
               ofPoint(fWide / 2, fHigh / 2, 0), 
               ofPoint(-fWide / 2, fHigh / 2, 0));

it is drawn, translated and rotated within:

ofPushMatrix();
ofTranslate(ofVec3f(fPT.x, fPT.y, 0));
ofRotateDeg(fRotate);
ofScale(fScale);

ofDrawTriangle(ofPoint(0, -fHigh/2, 0), 
               ofPoint(fWide/2, fHigh/2, 0),
               ofPoint(-fWide/2, fHigh/2, 0));

ofPopMatrix();

Then I want to determine if the mouse is inside this triangle. I tried this:

ofPoint pt = ofPoint(ix, iy, 0);
res = insideTriangleArea(pt, ofPoint(0,-fHigh/2, 0),
                             ofPoint(fWide/2, fHigh/2, 0),
                             ofPoint(-fWide/2, fHigh/2, 0));

[the insideTriangleArea function applies the formula for pt being within the area defined by the 3 points supplied and works for a static triangle (where the corner points are known and do not change dynamically).]

..... both within the ofPushMatrix/ofPopMatrix scope and without it which works, except, the sensitive area is in the upper left corner rather than centered at the fPT point and it does not rotate according to the value of the fRotate variable.

What have I missed?

1 Answer 1

0

I think it can be easier if you use an ofPolyline object to draw your triangle, apply your transformation in ofPolyline object (rotation, translation) https://openframeworks.cc/documentation/graphics/ofPolyline/#show_rotateDeg https://openframeworks.cc/documentation/graphics/ofPolyline/#show_translate and then use https://openframeworks.cc/documentation/graphics/ofPolyline/#show_inside to test your mouse coordinates and see if it is inside

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.