Home › Forums › Programming › Using the API to Drive the Camera
- This topic has 2 replies, 2 voices, and was last updated 8 years ago by
Yuri Kovelenov.
-
AuthorPosts
-
2018-05-23 at 5:03 pm #4307
jem
CustomerHi Soft8soft team,
Is it possible to use the Vege3D API to set the camera? I tried a simple test, but I did not get the results that I expected.I would like to be able to set the camera’s position and rotation from the JavaScript code. I could successfully set the position but the rotation of the camera would not update. Here is a sample of my code:
app.ExternalInterface.setCameraView = function(posName){ var cameraPositions = { "FRONT_VIEW" : { "x" : 0.0, "y" : -5.0 , "z" : 5.0, "rotX" : 90, "rotY" : 0.0, "rotZ" : 0.0}, "RIGHT_VIEW" : { "x" : 5.0, "y" : 0.0 , "z" : 0.0, "rotX" : 90, "rotY" : 0.0, "rotZ" : 90} } var cam = v3dApp.scene.getObjectByName("Camera"); var camPos = cameraPositions[posName]; cam.position.set(camPos.x, 1 * camPos.z, -1 * camPos.y); cam.rotation.set(camPos.rotX, camPos.rotY, camPos.rotZ); }The v3dApp var is a reference to the application. I set that elsewhere in my code.
Is there another way of doing this? A better way?
Thank you,
JemJeremy Wernick
2018-05-23 at 9:14 pm #4308jem
CustomerRather than try to make my technique work, I think that I will use the tween() function that the puzzle logic uses. Rather than hard-coding coordinates into the JavaScript, I use empties in the Blender scene as the sources of position data. Here is my new code:
var cameraPositions = { "FRONT_VIEW" : { "cameraPositionObjName" : "FRONT_CAMERA_POSITION", "cameraTargetObjName" : "OTHER_CAMERA_TARGET"}, "RIGHT_VIEW" : { "cameraPositionObjName" : "RIGHT_CAMERA_POSITION", "cameraTargetObjName" : "OTHER_CAMERA_TARGET" } } var cameraPos = v3dApp.scene.getObjectByName(cameraPositions[view].cameraPositionObjName).position; var targetPos = v3dApp.scene.getObjectByName(cameraPositions[view].cameraTargetObjName).position; v3dApp.controls.tween(cameraPos, targetPos, 0.0) }Thanks again,
JemJeremy Wernick
2018-05-24 at 8:09 am #4314
Yuri KovelenovStaffI will use the tween() function that the puzzle logic uses
Yes, that’s what I’d suggest too. Thanks for sharing your solution!
-
AuthorPosts
- You must be logged in to reply to this topic.
