I'm writing my own game engine in C++ and I was wondering where should I initialize variables which I need every frame, for example, every time mouse pointer is getting moved, the coordinates of pointer position should be saved in a variable.
Should I initialize the variable for that globally or in the function where it always initializes the variable new? Where are the benefits and where are the disadvantages?
float offsetX
float offsetY
void mouse_callback(double posX, double posY) {
offsetX = posX - lastX;
offsetY = lastY - posY;
lastX = posX;
lastY = posY;
}
or
void mouse_callback(double posX, double posY) {
float offsetX = posX - lastX;
float offsetY = lastY - posY;
lastX = posX;
lastY = posY;
}