c ++ – A camera controller API for my game engine

As a hobby I work on a game engine to learn C ++ and graphics programming. Now I have completed my first iteration of my camera system with OpengGL and GLM. Since I'm mostly self-taught, I'm looking for feedback.

I'm mainly looking for feedback on the following:

  • Is the API easy for another user to understand / implement?
  • Are there obvious performance issues?
  • Are there any missing features that you suspect are in a camera controller?
  • Is the API consistent in terms of code style and practices?

But of course any other feedback is also very welcome!

Perspective camera
Low level, responsible for the projection matrix

// PerspectiveCamera.h
#ifndef CHEETAH_ENGINE_RENDERER_PERSPECTIVECAMERA_H_
#define CHEETAH_ENGINE_RENDERER_PERSPECTIVECAMERA_H_

#include "Core/Core.h"
#include "Events/ApplicationEvents.h"
#include "Camera.h"

#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"

namespace cheetah
{
    struct PerspectiveCameraParams
    {
        const float radians = 45.0f;
        const float zNear = -1.0f;
        const float zFar = 1.0f;
        const float aspectRatio;
        const float zoom;
        const glm::vec3 position = glm::vec3(0.0f);
        const glm::vec3 rotationAxis = glm::vec3(1.0f);
        const float rotationDegrees = 0.0f;
    };

    class CH_API PerspectiveCamera : public Camera
    {
    public:
        PerspectiveCamera(const PerspectiveCameraParams& params);


        inline glm::mat4 getViewProjectionMatrix() const override { return m_viewProjectionMatrix; };
        inline glm::mat4 getProjectionMatrix() const override { return m_projectionMatrix; };
        inline glm::mat4 getViewMatrix() const override { return m_viewMatrix; };
        inline float getZoom() const override { return m_zoom; };
        inline float getAspectRatio() const override { return m_aspectRatio; };

        void setZoom(const float& zoom) override;
        void setAspectRatio(const float& aspectRatio) override;
        void setViewMatrix(const glm::mat4& viewMatrix) override;

        void recalculateViewProjectionMatrix() override;

    private:
        float m_aspectRatio;
        float m_zoom;
        float m_zNear;
        float m_zFar;
        float m_radians;
        glm::mat4 m_projectionMatrix;
        glm::mat4 m_viewMatrix;
        glm::mat4 m_viewProjectionMatrix;
    };
}

#endif // !CHEETAH_ENGINE_RENDERER_PERSPECTIVECAMERA_H_
// PerspectiveCamera.cpp
#include "PerspectiveCamera.h"

namespace cheetah
{
    PerspectiveCamera::PerspectiveCamera(const PerspectiveCameraParams& params)
        :
        m_projectionMatrix(glm::perspective(glm::radians(params.radians), params.aspectRatio, params.zNear, params.zFar)),
        m_viewMatrix(glm::rotate(glm::translate(glm::mat4(1.0f), params.position), params.rotationDegrees, params.rotationAxis)),
        m_viewProjectionMatrix(m_projectionMatrix* m_viewMatrix),
        m_aspectRatio(params.aspectRatio),
        m_zoom(params.zoom),
        m_zNear(params.zNear),
        m_zFar(params.zFar),
        m_radians(params.radians)
    {
    }

    void PerspectiveCamera::setViewMatrix(const glm::mat4& viewMatrix)
    {
        m_viewMatrix = viewMatrix;
        recalculateViewProjectionMatrix();
    }

    void PerspectiveCamera::setZoom(const float& zoom)
    {
        m_zoom = zoom;
        m_projectionMatrix = glm::perspective(glm::radians(m_radians += m_zoom), m_aspectRatio, m_zNear, m_zFar);
        recalculateViewProjectionMatrix();
    }

    void PerspectiveCamera::setAspectRatio(const float& aspectRatio)
    {
        m_aspectRatio = aspectRatio;
        m_projectionMatrix = glm::perspective(glm::radians(m_radians), aspectRatio, m_zNear, m_zFar);
        recalculateViewProjectionMatrix();
    }

    void PerspectiveCamera::recalculateViewProjectionMatrix()
    {
        m_viewProjectionMatrix = m_projectionMatrix * m_viewMatrix;
    }
}

CameraController
Higher level, doesn't care about camera type (ortho or perspective)

// CameraController.h
#ifndef CHEETAH_ENGINE_RENDERER_CAMERACONTROLLER_H_
#define CHEETAH_ENGINE_RENDERER_CAMERACONTROLLER_H_

#include "Core/Core.h"
#include "Camera.h"
#include "OrthoGraphicCamera.h"
#include "PerspectiveCamera.h"

#include 
#include 

#include 

namespace cheetah
{
    class CH_API CameraController
    {
    public:
        CameraController(const OrthoGraphicCameraParams& params);
        CameraController(const PerspectiveCameraParams& params);

        // affect ProjectionMatrix
        void setZoom(const float& zoom);
        void setAspectRatio(const float& width, const float& height);

        // affect ViewMatrix
        void setPosition(const glm::vec3& position);
        void translate(const glm::vec3& position);
        void rotate(const float& degrees, const glm::vec3& axis);

        inline float getZoom() const { return m_camera->getZoom(); };
        inline float getAspectRatio() const { return m_camera->getAspectRatio(); };
        inline glm::vec3 getPosition() const { return m_position; };
        inline glm::vec3 getRotationAxis() const { return m_rotationAxis; };
        inline float getRotationDegrees() const { return m_rotationDegrees; };
        inline Camera& getCamera() const { return *m_camera; };
    private:
        float m_rotationDegrees;
        glm::vec3 m_rotationAxis;
        glm::vec3 m_position;
        std::unique_ptr m_camera;
    };
}

#endif // !CHEETAH_ENGINE_RENDERER_CAMERACONTROLLER_H_
// CameraController.cpp
#include "CameraController.h"

namespace cheetah
{
    CameraController::CameraController(const OrthoGraphicCameraParams& params)
        :
        m_camera(std::make_unique(params)),
        m_position(params.position),
        m_rotationAxis(params.rotationAxis),
        m_rotationDegrees(params.rotationDegrees)
    {
    }

    CameraController::CameraController(const PerspectiveCameraParams& params)
        :
        m_camera(std::make_unique(params)),
        m_position(params.position),
        m_rotationAxis(params.rotationAxis),
        m_rotationDegrees(params.rotationDegrees)
    {
    }

    void CameraController::setZoom(const float& zoom)
    {
        m_camera->setZoom(zoom);
    }

    void CameraController::setAspectRatio(const float& width, const float& height)
    {
        m_camera->setAspectRatio(width / height);
    }

    void CameraController::setPosition(const glm::vec3& position)
    {
        m_position = position;
        m_camera->setViewMatrix(glm::rotate(glm::translate(glm::mat4(1.0f), position), m_rotationDegrees, m_rotationAxis));
    }

    void CameraController::translate(const glm::vec3& position)
    {
        m_position = position;
        m_camera->setViewMatrix(glm::translate(m_camera->getViewMatrix(), m_position));
    }

    void CameraController::rotate(const float& degrees, const glm::vec3& axis)
    {
        m_rotationDegrees = degrees;
        m_rotationAxis = axis;
        m_camera->setViewMatrix(glm::rotate(m_camera->getViewMatrix(), degrees, axis));
    }
}

implementation
Here is a possible way to implement the CameraController

// MainCamera.h
#ifndef GAME_MAINCAMERA_H_
#define GAME_MAINCAMERA_H_

#include "Cheetah.h"

class MainCamera : public cheetah::CameraController
{
public:
    MainCamera(const cheetah::PerspectiveCameraParams& params);
    void onUpdate(const float& deltaTime);
    bool onWindowResize(const cheetah::WindowResizeEvent& event);
private:
    void handleKeyInput(const float& deltaTime);
};

#endif // !GAME_MAINCAMERA_H_

// MainCamera.cpp
#include "MainCamera.h"

using namespace cheetah;
using namespace math;
using namespace input;

MainCamera::MainCamera(const cheetah::PerspectiveCameraParams& params)
    : CameraController(params)
{
}

bool MainCamera::onWindowResize(const WindowResizeEvent& event)
{
    setAspectRatio((float)event.m_width, (float)event.m_height);
    return true;
}

void MainCamera::onUpdate(const float& deltaTime)
{
    handleKeyInput(deltaTime);
}

void MainCamera::handleKeyInput(const float& deltaTime)
{
    // reset
    if (Input::isKeyPressed(keys::R))
    {
        setPosition(vec3(0.0f, 0.0f, 0.0));
    }

    // moving
    if (Input::isKeyPressed(keys::W))
    {
        translate(vec3(0.0f, -(0.001f * deltaTime), 0.0f));
    }
    if (Input::isKeyPressed(keys::A))
    {
        translate(vec3(-(0.001f * deltaTime), 0.0f, 0.0f));
    }
    if (Input::isKeyPressed(keys::S))
    {
        translate(vec3(0.0f, 0.001f * deltaTime, 0.0f));
    }
    if (Input::isKeyPressed(keys::D))
    {
        translate(vec3(0.001f * deltaTime, 0.0f, 0.0f));
    }

    // rotating
    if (Input::isKeyPressed(keys::Q))
    {
        rotate(-(0.001f * deltaTime), vec3(0, 1, 0));
    }
    if (Input::isKeyPressed(keys::E))
    {
        rotate(0.001f * deltaTime, vec3(0, 1, 0));
    }
    if (Input::isKeyPressed(keys::Z))
    {
        translate(vec3(0.0f, 0.0f, 0.001f * deltaTime));
    }
    if (Input::isKeyPressed(keys::X))
    {
        translate(vec3(0.0f, 0.0f, -(0.001f * deltaTime)));
    }
}

What is the best way to create an engine sound loop?

Guys, I need a direction. I am new to game development. I am creating a 2D car game. It seems impossible for me to create a perfect engine sound loop. I can't find a constant tone on YouTube that I can edit in audio editing. Can someone please tell me what I can do? I have limited resources, so I cannot afford premium software and am an individual developer. I use the Unity game engine.

Javascript – 2D engine design / architecture: transformations

Hi there! I'm working on this little hobby 2D engine in JavaScript because I want to learn how all of these things are generally implemented and structured. The internet is full of resources, but most things are mathematical or theoretical. There is very little about implementation or architecture for small 2D engines like the one I work in. So that's my context and in the end are some questions I hope you can help me with:

I have a body Object with different properties like (pseudocode):

Body {
    angle: float
    scale: float
    acceleration: 2d vector
    velocity: 2d vector
    position: 2d vector
    update: function()
}

A body object also has one model Object that has (pseudocode):

Model {
    points: Array of (x, y) points
    fillColor: string (hex)
    transform: function(rotate, scale, translate)
}

The transform function receives Angle, Scale and Translate and returns a new transformed instance of the model.

I will update that on every frame body Current State Object: Add an accelerator vector to speed, speed to position (and some similar things to update the angle and scale if necessary):

Body {
    update() {
        this.velocity.add(this.acceleration)
        this.location.add(this.velocity)
        this.acceleration.reset() 
    }
}

Once the body object is updated, I need to a World transformation of the model so I can start doing physics-related things (such as collision detection / resolution, interaction forces between bodies, etc.).
Then I do one View transformationto transform the world objects into the "perspective" of another object.

At the moment this is my solution, which is to link three instances of the Model object to the Body object as follows:

Body {
    model: the original *Model* with no transformations
    model_world: result of *Model.transform(body.angle, body.scale, body.location)*
    model_view: the result of transforming **model_world** instance with viewport properties
}

Ask:

  • Do you think there is a better way to handle model transformations? Like maybe someone who doesn't require the body object to manage the three instances of the three transformations themselves, maybe.

  • Can you please give me some suggestions on how you can better organize this functionality for a simple 2D engine?

Thanks in advance!

1700 federal engineers took over Google. End of search engine optimization?

Donald Trump: We have 1,700 engineers working on Google.

It is the end of the Google censorship and possibly also the Google algorithm guideline

A technical report for the Edge browser says, "Browsers download malware."

Will SEO survive? There was mostly an illegal partnership between Google Adsense and SEO.

Rendering – Unreal Engine – Occlusion culling doesn't seem to be working properly

I play around with some environments bought from the market, one of which has a fairly intense map with lots of houses and lots of detailed interiors for houses. I got the impression that Unreal enables dynamic occlusion culling by default, but it seems that occluded meshes are still being rendered. See comparison of & # 39; stat initviews & # 39; below:

Concealed:
Enter the image description here

To open:
Enter the image description here

There is no big difference in the number of hidden (hopefully discarded) objects between these two camera views, and my performance is very similar in both. Am I wrong in understanding how occlusion culling works in UE or is it not working properly for me? How do I make sure that hidden objects are not rendered?

SEO services Kerala

SEO services Kerala

+ Reply to thread

  1. SEO services Kerala

    SEO is a powerful tool for your success in search engine marketing. The SEO service in Kerala is growing day by day. Many companies offer affordable and effective search engine optimization services in Kerala and beyond. They actively work with their partners and employees for SEO services in other cities in Kerala. While traffic is important, targeted queries relevant to user requests by creating authoritative content are equally important. A good website always puts a company in direct contact with customers, provides information and collects direct feedback. As a website, SEO can help with search engine submissions, meta tags, keyword optimization and search placement to get a website to the top with powerful techniques


Booking authorizations

  • You not allowed post new threads
  • You not allowed Post responses
  • You not allowed Post attachments
  • You not allowed Edit your posts

network
counter

Galaksion.com: Test our engine to efficiently monetize your web presence Proxies-free

Galaksion at the Affiliate Summit East 2017: special offers for visitors

Galaksion is a European network that works with publishers around the world. Our mission is to make your monetization efforts as seamless, transparent, and successful as possible. Join Galaksion to test our features and benefits in practice.

For W.Ebmasters
– high eCPM rates
– Detailed statistics in real time
– In our wide range of offers there are over 9,000 ongoing campaigns at any time
– a variety of formats that fit your website or blog, e.g. B. banners and ibanners, pushups, tabunder, pop-ups, pop-under and videos
– Daily, weekly and monthly payments as well as net 0, net 15 and net 30
– Numerous payment methods available such as Payoneer, Paxum, PayPal, Skrill, WebMoney and bank transfer

For advertisers:
– both CPA and CPM
– Advanced targeting to reach your target audience: cities and geos, devices and operating systems, WiFi and network operators, source categories and frequency limits
– Protection against fraud and bots
– Support with transparency and optimization

Finally, it should be mentioned that we work with all industries that are in high demand today: dating, gambling, games, app installations, mobile content, e-commerce and finance.

Visit our website or contact us for more information: info [at] galaksion.com

Galaksion is a European network that works with publishers around the world. Our mission is to make your monetization efforts as seamless, transparent, and successful as possible. Join Galaksion to test our features and benefits in practice.

For W.Ebmasters
– high eCPM rates
– Detailed statistics in real time
– In our wide range of offers there are over 9,000 ongoing campaigns at any time
– a variety of formats that fit your website or blog, e.g. B. banners and ibanners, pushups, tabunder, pop-ups, pop-under and videos
– Daily, weekly and monthly payments as well as net 0, net 15 and net 30
– Numerous payment methods available such as Payoneer, Paxum, PayPal, Skrill, WebMoney and bank transfer

For advertisers:
– both CPA and CPM
– Advanced targeting to reach your target audience: cities and geos, devices and operating systems, WiFi and network operators, source categories and frequency limits
– Protection against fraud and bots
– Support with transparency and optimization

Finally, it should be mentioned that we work with all industries that are in high demand today: dating, gambling, games, app installations, mobile content, e-commerce and finance.

Visit our website or contact us for more information: info [at] galaksion.com

__________________
Added after 3 minutes::

This post is for those who will attend the Affiliate Summit East 2017 conference and fair in New Your in a week.

We are pleased to announce that our team will be attending this event as professional visitors.

If you want to try Galaksion as your advertising engine, Kamran, our product owner, will be happy to meet you in person in New York to introduce our brand new solution, the Galaksion self-service platform for publishers, advertisers and partners. He will also be happy to offer some special terms and benefits that we will offer to the first users of our updated solution.

Please do not hesitate to contact him!

Kamran
Product Owner
kamran [at] galaksion.com
Skype: kamran_Galaksion

Correction of the fishbowl effect in raycasting engine proposals (pseudo 3D projection)

I am writing a simple raycaster in Golang and have some problems understanding perspective correction. The code is simple, the main rendering loop is as follows:

    curVector := playerVector.NewRotated(-curFov / 2)
    rotateStep := curFov / float64(screen.Width()) // Angles per screen row
    // Traverse each row of our screen, cast a ray and render it to screen buffer
    for i := 0; i <= screen.Width(); i++ {
        curVector.Rotate(rotateStep)

        hit, distance, tile, tileP := rayCast(curX, curY, curVector, viewDistance)

        if hit {
            // distToHeight is basically linear (screen.Height()/distance)
            drawTexturedWallColumn(screen, tile, i, distToHeight(distance, screen.Height()), tileP) // Project walls on screen
        }
        // drawSpritesColumn(screen, i, curVector, distance) // Project sprites on screen
    }

So I just throw rays with even angular intervals and get this fishbowl effect:
Enter the image description here

So I understand that the problem lies with angular intervals and projected beams of the same length. I found this question. How can I correct an unwanted fisheye effect when I'm drawing a scene with raycasting? and tried to implement the same logic:

leftVector := playerVector.NewRotated(90)
    // Traverse each row of our screen, cast a ray and render it to screen buffer
    for i := 0; i <= screen.Width(); i++ {
        progress := float64(i)/float64(screen.Width()) - 0.5 // -0.5 to 0.5
        stepX := (playerVector.X + progress*(leftVector.X*2)) // *2 to make 90 FOV
        stepY := (playerVector.Y + progress*(leftVector.Y*2))
        curVector := Vector{X: stepX, Y: stepY}

        hit, distance, tile, tileP := rayCast(curX, curY, curVector, viewDistance)

        if hit {
            // distToHeight is basically linear (screen.Height()/distance)
            drawTexturedWallColumn(screen, tile, i, distToHeight(distance, screen.Height()), tileP) // Project walls on screen
        }
        // drawSpritesColumn(screen, i, curVector, distance) // Project sprites on screen
    }

But the result is almost the same (FOV variable is not used here, but it is about 90, it is not important at the moment). The difference is that this has a "more linear" fishbowl effect due to evenly distributed intervals (progress variable):
Enter the image description here

So I don't know how to fix it. I also tried to use the vertical distance (distance * cos).

Local search engine optimization for software companies?

Hello everybody,

I am currently working with an SEO agency on my website and they would like to spend a lot of time creating a Yext account for my company. In my understanding, this is more for local SEO, and as a company without a location, it wouldn't make sense to create a Yelp / Googlemybusiness / Yellowpages page. Is it worth doing this? Maybe from a marketing / backlink perspective?

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123