how convert position class to 'const POINT*'?

see my position class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class position
{
public:
	float X;
	float Y;
	float Z;
	float perespective;
	float foco;
	position(float posx = 0, float posy = 0, float posz = 0, float FocalDistance = 300) {
		X = posx;
		Y = posy;
		Z = posz;
		foco = FocalDistance;
	}

	operator POINT()
	{
         RECT WindowSize;
		GetClientRect(GetConsoleWindow(), &WindowSize);
		const auto perespective { foco / (Z + foco) };

        POINT pt = {(LONG)std::trunc(X * perespective)+WindowSize.right/2,(LONG)std::trunc(Y * perespective) + WindowSize.bottom/2};

		return pt;
	}
};

i used 'operator POINT()' for test and no success :(
heres how i use it:
1
2
std::vector<position> DrawPlane { {-100, 50,0}, {-100, 50,1000}, {100, 50,1000},{100, 50,0} };
Polygon(HDCConsole,(POINT*)DrawPlane.data(), DrawPlane.size());

but no results :(
what i'm doing wrong?
to be honest, i was trying getting another opinion.. but seems that i must use the 2kaud suggestion. thanks.
The operation you're specifying is on the collection, not the contents. You'll likely have to create a separate conversion function like:
1
2
3
4
5
6
7
std::vector<POINT> toPoints(const std::vector<position> &in) {
    std::vector<POINT> points;
    points.reserve(in.size());
    for (const auto &pos : in)
        points.push_back(static_cast<POINT>(pos));
    return points;
}

Then your code becomes:
1
2
3
std::vector<position> DrawPlane{{-100, 50, 0}, {-100, 50, 1000}, {100, 50,1000}, {100, 50, 0}};
auto planePoints{toPoints{DrawPlane};
Polygon(HDCConsole, &planePoints.front(), planePoints.size());


It doesn't sit well, but if you don't modify you positions values, you can create the second array directly and forgo the first.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class position {
public:
    float x, y, z, fd;

    position(float x = 0.0f, float y = 0.0f, float z = 0f, float fd = 300.0f)
      : x(x), y(x), z(z), fd(fd) {
    }
    operator POINT () const {
        RECT WindowSize;
        GetClientRect(GetConsoleWindow(), &WindowSize);

        auto perespective = fd / z + foco;
        return {(LONG)std::trunc(x*perespective) + WindowSize.right/2,
                (LONG)std::trunc(y*perespective) + WindowSize.bottom/2};
    }
};

std::vector<POINT> planePoints{
    static_cast<POINT>(position{-100, 50, 0}),
    static_cast<POINT>(position{-100, 50, 1000}),
    static_cast<POINT>(position{100, 50,1000}),
    static_cast<POINT>(position{100, 50, 0})};
Polygon(HDCConsole, &planePoints.front(), planePoints.size());
Last edited on
Topic archived. No new replies allowed.