Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[camera] Improvements on camera module #1143

Closed
raysan5 opened this issue Mar 23, 2020 · 6 comments
Closed

[camera] Improvements on camera module #1143

raysan5 opened this issue Mar 23, 2020 · 6 comments
Labels
enhancement This is an improvement of some feature

Comments

@raysan5
Copy link
Owner

raysan5 commented Mar 23, 2020

camera module consist basically of two functions:

  • SetCameraMode(): It setups internal variables for the passed camera and also sets the mode how UpdateCamera() function behaves.
  • UpdateCamera(): It updates camera parameters depending on mode and some configurable inputs. Modes are predefined to some standard ones, like CAMERA_FREE or CAMERA_FIRST_PERSON.

As previously reported, there are some undesired side effects when user deals with multiple cameras. The expected usage mode is calling SetCameraMode() to initialize parameters for a new camera and update mode. Later call UpdateCamera() on that camera for expected update.

There are two possible lines of improvement on the module:

  1. TODO points on the code defining some possible issues (it should be retested to confirm...)
  2. Just wondering if current usage mechanism could be improved in some way.
@chriscamacho
Copy link
Contributor

It would be nice to see right from the bottom up rlgl -> camera etc, raylib using some kind of matrix stack (like the old fixed function GL versions (you're probably too young to remember ;) :p ))
or if not a stack, then there should a standard set of Model, View, projection etc matrices, that way, the camera and other functionality could be manipulated via RayMath's matrix functions... In my own code not using raylib in the past I have used different approaches like quats and vectors or even euler angles, as well as matrices for cameras, I seemed to get the best results from a matrix camera in general.

@las3rlars
Copy link
Contributor

las3rlars commented Mar 23, 2020

Following snippet will highlight the issue with the current camera implementation:

while (!WindowShouldClose()) 
{
	SetCameraMode(camera, CAMERA_ORBITAL);
	UpdateCamera(&camera);

	UpdateModelAnimation(character, anims[0], animFrameCounter++);
	if (animFrameCounter >= anims[0].frameCount) animFrameCounter = 0;

	float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
	SetShaderValue(lighShader, lighShader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3);

	BeginDrawing();
		ClearBackground(RAYWHITE);

		BeginTextureMode(shadowMap);

			ClearBackground(WHITE);
			/*
			SetCameraMode(shadowCamera, CAMERA_CUSTOM);
			UpdateCamera(&shadowCamera);
			*/
			character.materials[0].shader = shadowShader;

			BeginMode3D(shadowCamera);

				DrawModel(character, Vector3{ 0.0f, 0.0f, 0.0f }, 1.0, GRAY);

			EndMode3D();

		EndTextureMode();

		BeginMode3D(camera);

			DrawPlane(Vector3{ 0.0f, 0.0f, 0.0f }, Vector2{ 10.0f, 10.0f }, DARKGREEN);
			DrawGrid(10.0f, 1.0f);
			character.materials[0].shader = lighShader;
			DrawModel(character, Vector3{ 0.0f, 0.0f, 0.0f }, 1.0, GRAY);

		EndMode3D();

		//DrawTextureRec(shadowMap.texture, Rectangle{ 0.0f, 0.0f, (float)shadowMap.texture.width, (float)shadowMap.texture.height }, Vector2{ 0.0f, 0.0f }, WHITE);
		DrawText("Congrats! blah", 190, 200, 20, LIGHTGRAY);
		DrawFPS(700, 15);
	EndDrawing();
}

@raysan5
Copy link
Owner Author

raysan5 commented Mar 23, 2020

@chriscamacho I'm old enough to remember very well OpenGL 1.1... :P

Actually, BeginMode3D() just converts Camera to view matrix and combines it with internal modelview. Users can skip all this goodies just using rlgl module as standalone.

@las3rlars I see the issue, why not you just SetCameraMode()/UpdateCamera() right before BeginMode3D() calls?

@raysan5 raysan5 added the enhancement This is an improvement of some feature label Jul 5, 2020
@HeartofPhos
Copy link

@raysan5 This may not be the correct issue but I agree with the suggestion to have BeginMode3D() and Camera3D to be matrix based and instead rework the Camera module to transform the data currently stored in Camera3D into a view matrix.

Something along the lines of void UpdateCamera(Camera *camera, CameraData *cameraData)
Reasoning being that when not using the Camera module the current data structure feels too specialized to write simple camera functions for example how CAMERA_FIRST_PERSON builds up a matrix only to convert it to Camera.target which is eventually converted back to a matrix

I'm happy to make a proof of concept pull request if you feel this is a potentially viable solution

@raysan5
Copy link
Owner Author

raysan5 commented Sep 15, 2020

@HeartofPhos I prefer keeping the Camera3D as it is, it's easier for the final user to understand the concepts, despite being more complex to deal with internally.

@raysan5
Copy link
Owner Author

raysan5 commented Jun 13, 2021

I'm closing this issue, an alternative and better Camera implementation is provided here.

@raysan5 raysan5 closed this as completed Jun 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an improvement of some feature
Projects
None yet
Development

No branches or pull requests

4 participants