Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

I am want to attract the crimson rect on the primary vertex of grey platform.

To start with, I draw a grey platform with a perspective projection and set it utilizing gluPerspective:

float fov = 69;
float aspectRatio = 960.0f / 480.0f;
float zNear = 0.1;
float zFar = 1000.0;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, aspectRatio, zNear, zFar);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(
    0.0f, 0.0f, 5.0f,
    0.0f, 0.0f, 0.0f,
    0.0f, 1.0f, 0.0f
);

gray platform render

Then, I’ll set up an orthographic projection on the entire display screen. The rendering begins from the upper-left nook of the window. My activity is to attract a crimson sq. on the level the place the primary vertex of the grey platform begins to be drawn:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 960, 480, 0, 1, -1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

drawRedRect(Undertaking(glm::vec3(-1.0f, -1.0f, -1.0f), fov, aspectRatio, zNear, zFar));

Code for Undertaking perform:

float fov = tan(fovy / 2.0F);
glm::mat4x4 id = glm::mat4x4(
    1.0f, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    0, 0, 0, 1
);
glm::mat4x4 projectionMatrix = glm::mat4x4(
    fov / aspectRatio, 0.0f, 0.0f, 0.0f,
    0.0f, fov, 0.0f, 0.0f,
    0.0f, 0.0f, (zFar + zNear) / (zNear - zFar), (2.0f * zFar * zNear) / (zNear - zFar),
    0.0f, 0.0f, -1.0f, 0.0f
);

glm::mat4x4 lookAt = glm::lookAt(
    glm::vec3(0.0f, 0.0f, 5.0f),
    glm::vec3(0.0f, 0.0f, 0.0f),
    glm::vec3(0.0f, 1.0f, 0.0f)
);

glm::vec4 platformVector4 = glm::vec4(platformVector.x, platformVector.y, platformVector.z, 1.0f);
platformVector4 = projectionMatrix * lookAt * platformVector4;
//platformVector4 /= platformVector4.w;

float halfWidth = 960.0f / 2.0f;
float halfHeight = 480.0f / 2.0f;

glm::vec2 screenProjectedVector = glm::vec2(
    halfWidth + (platformVector4.x * 960.0f) * 0.5f,
    halfHeight - (platformVector4.y * 480.0f) * 0.5f
);

return screenProjectedVector;

I additionally tried to make use of float fov = tan(glm::radians(fovy / 2.0F));, nevertheless it did not get profitable consequence.

In response to the system utilized by gluPerspective, I calculated the fov and the angle projection matrix:

projection matrix formula

Results of my code:

result 2

However I want the sq. to be on the primary vertex, and it is unclear the place.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *