Panda3D

physxSegment.cxx

00001 // Filename: physxSegment.cxx
00002 // Created by:  enn0x (31Oct09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "physxSegment.h"
00016 #include "physxManager.h"
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //     Function: PhysxSegment::Constructor
00020 //       Access: Published
00021 //  Description:
00022 ////////////////////////////////////////////////////////////////////
00023 PhysxSegment::
00024 PhysxSegment(const LPoint3f &p0, const LPoint3f &p1) {
00025 
00026   _segment.p0 = PhysxManager::point3_to_nxVec3(p0);
00027   _segment.p1 = PhysxManager::point3_to_nxVec3(p1);
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: PhysxSegment::get_p0
00032 //       Access: Published
00033 //  Description: Returns the start point of the segment.
00034 ////////////////////////////////////////////////////////////////////
00035 LPoint3f PhysxSegment::
00036 get_p0() const {
00037 
00038   return PhysxManager::nxVec3_to_vec3(_segment.p0);
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: PhysxSegment::set_p0
00043 //       Access: Published
00044 //  Description: Sets the start point of the segment.
00045 ////////////////////////////////////////////////////////////////////
00046 void PhysxSegment::
00047 set_p0(LPoint3f p) {
00048 
00049   nassertv_always(!p.is_nan());
00050 
00051   _segment.p0 = PhysxManager::vec3_to_nxVec3(p);
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: PhysxSegment::get_p1
00056 //       Access: Published
00057 //  Description: Returns the end point of the segment.
00058 ////////////////////////////////////////////////////////////////////
00059 LPoint3f PhysxSegment::
00060 get_p1() const {
00061 
00062   return PhysxManager::nxVec3_to_vec3(_segment.p1);
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: PhysxSegment::set_p1
00067 //       Access: Published
00068 //  Description: Sets the end point of the segment.
00069 ////////////////////////////////////////////////////////////////////
00070 void PhysxSegment::
00071 set_p1(LPoint3f p) {
00072 
00073   nassertv_always(!p.is_nan());
00074 
00075   _segment.p1 = PhysxManager::vec3_to_nxVec3(p);
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: PhysxSegment::get_origin
00080 //       Access: Published
00081 //  Description: Returns the start point of the segment.
00082 ////////////////////////////////////////////////////////////////////
00083 LPoint3f PhysxSegment::
00084 get_origin() const {
00085 
00086   return PhysxManager::nxVec3_to_point3(_segment.getOrigin());
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: PhysxSegment::compute_direction
00091 //       Access: Published
00092 //  Description: Returns the direction vector from the segment's
00093 //               start point to it's end point.
00094 ////////////////////////////////////////////////////////////////////
00095 void PhysxSegment::
00096 compute_direction(LPoint3f &dir) const {
00097 
00098   nassertv(!dir.is_nan());
00099 
00100   NxVec3 nDir = PhysxManager::point3_to_nxVec3(dir);
00101   _segment.computeDirection(nDir);
00102   PhysxManager::update_point3_from_nxVec3(dir, nDir);
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: PhysxSegment::compute_length
00107 //       Access: Published
00108 //  Description: Returns the distance from the segment's start point
00109 //               to it's end point.
00110 ////////////////////////////////////////////////////////////////////
00111 float PhysxSegment::
00112 compute_length() const {
00113 
00114   return _segment.computeLength();
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: PhysxSegment::compute_point
00119 //       Access: Published
00120 //  Description: Computes a point on the segment.
00121 ////////////////////////////////////////////////////////////////////
00122 void PhysxSegment::
00123 compute_point(LPoint3f &p, float t) const {
00124 
00125   nassertv(!p.is_nan());
00126 
00127   NxVec3 nP = PhysxManager::point3_to_nxVec3(p);
00128   _segment.computePoint(nP, t);
00129   PhysxManager::update_point3_from_nxVec3(p, nP);
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: PhysxSegment::compute_square_length
00134 //       Access: Published
00135 //  Description: Returns the square distance from the segment's
00136 //               start point to it's end point.
00137 ////////////////////////////////////////////////////////////////////
00138 float PhysxSegment::
00139 compute_square_length() const {
00140 
00141   return _segment.computeSquareLength();
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: PhysxSegment::set_origin_direction
00146 //       Access: Published
00147 //  Description: Setup this segment from origin (start point) and
00148 //               direction vector.
00149 ////////////////////////////////////////////////////////////////////
00150 void PhysxSegment::
00151 set_origin_direction(const LPoint3f &origin, const LVector3f &direction) {
00152 
00153   nassertv_always(!origin.is_nan());
00154   nassertv_always(!direction.is_nan());
00155 
00156   _segment.setOriginDirection(PhysxManager::point3_to_nxVec3(origin),
00157                               PhysxManager::vec3_to_nxVec3(direction));
00158 }
00159 
 All Classes Functions Variables Enumerations