-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
implementation of p5.Camera.set() function #6243
implementation of p5.Camera.set() function #6243
Conversation
Implement the set() function of p5.Camera. This copies the camera view and projection information to the target camera. If the target is active, the renderer's view and projection matrices are updated accordingly.
Compare the matrix between the camera to which the set() function is applied and the camera of the argument. Since the applied camera is active, we also compare it with the renderer's matrix.
indent fix
I'm tired of worrying about how to write code, so I decided to write it the way I like it. I'm tired.
fix p5 to myp5
no need _curCamera
I wanted to create this function because I wanted to make it easier to write code for smooth camera switching. 2023-06-29.01-38-10.mp4In this demo, 4 cameras are prepared and can be switched by pressing a button. For that we need the first and last camera, and set() is used to populate that information. However, if only the attached camera is used, the assignment operation is actually sufficient and the set() is not necessary. This demo allows the camera to be manipulated with orbitControl() after switching cameras. Therefore, setCamera() cannot be used. This is because the information of the prepared camera will be rewritten. Also, if you use substitution when preparing the starting camera, the starting camera will change, so substitution cannot be used. So set() is used effectively. set() is very useful for treating the camera as a data-only object. If this kind of thing can be done without using set(), we don't need this function. I tried to explain the usefulness as much as possible, but I don't know if I did it well. If the implementation is allowed, please give me a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, great example too!
Thanks for review and merge! ('ω') |
Thanks @inaridarkfox4231 for working on it and @davepagurek for reviewing it! |
Implement the set() function of p5.Camera.
This function copies the argument camera information to the target camera, just like p5.Vector's set().
The information to be copied is the view matrix and its parameters, projection matrix and its parameters, and cameraType.
There is no particular meaning in transferring the cameraType, but since this information is determined in a way related to how the projection is set, I thought it would be appropriate to copy it.
If the target camera is active, the renderer's view and projection matrices are updated with the same matrices.
Resolves #6238
Example
p5.Camera.set()_DEMO
2023-06-27.22-23-39.mp4
When double-clicked, the camera whose initial state is registered is set as the active camera by set(), and the screen state is reset. As it stands now, this requires resetting the initial state somehow. setCamera() cannot be used because the active camera will change. With this function, you can restore only the settings without changing the active camera.
PR Checklist
npm run lint
passes