summaryrefslogtreecommitdiffstats
path: root/o3d/import/cross/camera_info.cc
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 06:06:34 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 06:06:34 +0000
commit9108d4c2b521e8e58bbc125787550772f585ef6c (patch)
tree2d7959d73c9545dfa19537abf04fc1e053e7c9cc /o3d/import/cross/camera_info.cc
parentac49d93303918e3eb99c030673432c7be876c87b (diff)
downloadchromium_src-9108d4c2b521e8e58bbc125787550772f585ef6c.zip
chromium_src-9108d4c2b521e8e58bbc125787550772f585ef6c.tar.gz
chromium_src-9108d4c2b521e8e58bbc125787550772f585ef6c.tar.bz2
Prep for moving Camera Info out of Params into JSON
I thought it was best to give you what I have so far for your input and code review instead of giving you everything all at once. This CL implements JSONObject which has a mechanism for adding stuff to be serialized as JSON to the serialization code. Since JSONObject is a serialization only object it seemed okay to put Serialize code inside. I opted to pre-declare JSONFloat and JSONOptionalFloat because I felt it made the code more error free. I had made it were you could just have JSONFloat and then with RegisterJSONValue you'd pass in optional or not but this way, declaring the field in a class makes it more explicit. CameraInfo is the first class that uses it. I'm not set on exactly how it is serialized. Whether it's as "object: { ... }" inside the "properties" section or whether it should have its own section. I think I won't know what until I actually write the deserialization code. That's not imporant for this CL This code, even if checked it, is not used yet as the import code, collada.cc, is not yet creating any of these objects. That's in another CL if you want to take a look http://codereview.chromium.org/160007 That CL will have to have lots of o3djs changes, corresponding sample changes and corresponding selenium test changes. Review URL: http://codereview.chromium.org/160008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21515 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/import/cross/camera_info.cc')
-rw-r--r--o3d/import/cross/camera_info.cc98
1 files changed, 98 insertions, 0 deletions
diff --git a/o3d/import/cross/camera_info.cc b/o3d/import/cross/camera_info.cc
new file mode 100644
index 0000000..905c337
--- /dev/null
+++ b/o3d/import/cross/camera_info.cc
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "import/cross/camera_info.h"
+
+namespace o3d {
+
+O3D_OBJECT_BASE_DEFN_CLASS(
+ "o3djs.CameraInfo", CameraInfo, JSONObject);
+O3D_OBJECT_BASE_DEFN_CLASS(
+ "o3djs.PerspectiveCameraInfo", PerspectiveCameraInfo, CameraInfo);
+O3D_OBJECT_BASE_DEFN_CLASS(
+ "o3djs.OrthographicCameraInfo", OrthographicCameraInfo, CameraInfo);
+
+const char* CameraInfo::kAspectRatioParamName = "aspectRatio";
+const char* CameraInfo::kNearZParamName = "nearZ";
+const char* CameraInfo::kFarZParamName = "farZ";
+const char* CameraInfo::kTransformValueName = "transform";
+const char* CameraInfo::kEyeValueName = "eye";
+const char* CameraInfo::kTargetValueName = "target";
+const char* CameraInfo::kUpValueName = "up";
+
+CameraInfo::CameraInfo(ServiceLocator* service_locator)
+ : JSONObject(service_locator) {
+ RegisterParamRef(kAspectRatioParamName, &aspect_ratio_param_);
+ RegisterParamRef(kNearZParamName, &near_z_param_);
+ RegisterParamRef(kFarZParamName, &far_z_param_);
+ RegisterJSONValue(kTransformValueName, &transform_value_);
+ RegisterJSONValue(kEyeValueName, &eye_value_);
+ RegisterJSONValue(kTargetValueName, &target_value_);
+ RegisterJSONValue(kUpValueName, &up_value_);
+
+ set_aspect_ratio(1.0f);
+ set_near_z(0.01f);
+ set_far_z(10000.0f);
+}
+
+const char* OrthographicCameraInfo::kMagXParamName = "magX";
+const char* OrthographicCameraInfo::kMagYParamName = "magY";
+
+OrthographicCameraInfo::OrthographicCameraInfo(ServiceLocator* service_locator)
+ : CameraInfo(service_locator) {
+ RegisterParamRef(kMagXParamName, &mag_x_param_);
+ RegisterParamRef(kMagYParamName, &mag_y_param_);
+
+ set_mag_x(1.0f);
+ set_mag_y(1.0f);
+}
+
+ObjectBase::Ref OrthographicCameraInfo::Create(
+ ServiceLocator* service_locator) {
+ return ObjectBase::Ref(new OrthographicCameraInfo(service_locator));
+}
+
+const char* PerspectiveCameraInfo::kFieldOfViewYParamName = "fieldOfViewY";
+
+PerspectiveCameraInfo::PerspectiveCameraInfo(ServiceLocator* service_locator)
+ : CameraInfo(service_locator) {
+ RegisterParamRef(kFieldOfViewYParamName, &field_of_view_y_param_);
+
+ set_field_of_view_y(30.0f * 3.14159f / 180.0f);
+}
+
+ObjectBase::Ref PerspectiveCameraInfo::Create(ServiceLocator* service_locator) {
+ return ObjectBase::Ref(new PerspectiveCameraInfo(service_locator));
+}
+
+} // namespace o3d
+
+