|
楼主 |
发表于 2014-4-22 10:55:57
|
显示全部楼层
多谢,再麻烦你一下:
我在查找Cylinder的源代码,发现Shape中Cylinder的定义如下,并没有有具体实现
- class OSG_EXPORT Cylinder : public Shape
- {
- public:
- Cylinder():
- _center(0.0f,0.0f,0.0f),
- _radius(1.0f),
- _height(1.0f) {}
- Cylinder(const osg::Vec3& center,float radius,float height):
- _center(center),
- _radius(radius),
- _height(height) {}
- Cylinder(const Cylinder& cylinder,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
- Shape(cylinder,copyop),
- _center(cylinder._center),
- _radius(cylinder._radius),
- _height(cylinder._height),
- _rotation(cylinder._rotation) {}
- META_Shape(osg, Cylinder);
- inline bool valid() const { return _radius>=0.0f; }
- inline void set(const Vec3& center,float radius, float height)
- {
- _center = center;
- _radius = radius;
- _height = height;
- }
- inline void setCenter(const Vec3& center) { _center = center; }
- inline const Vec3& getCenter() const { return _center; }
- inline void setRadius(float radius) { _radius = radius; }
- inline float getRadius() const { return _radius; }
- inline void setHeight(float height) { _height = height; }
- inline float getHeight() const { return _height; }
- inline void setRotation(const Quat& quat) { _rotation = quat; }
- inline const Quat& getRotation() const { return _rotation; }
- inline Matrix computeRotationMatrix() const { return Matrix(_rotation); }
- bool zeroRotation() const { return _rotation.zeroRotation(); }
- protected:
-
- virtual ~Cylinder();
- Vec3 _center;
- float _radius;
- float _height;
- Quat _rotation;
- };
复制代码
后来在:ShapeDrawable文件中发现如下代码,这应该才是Cylinder的实现吧??:
- void DrawShapeVisitor::drawCylinderBody(unsigned int numSegments, float radius, float height)
- {
- const float angleDelta = 2.0f*osg::PI/(float)numSegments;
- const float texCoordDelta = 1.0f/(float)numSegments;
- const float r = radius;
- const float h = height;
- float basez = -h*0.5f;
- float topz = h*0.5f;
- float angle = 0.0f;
- float texCoord = 0.0f;
- bool drawFrontFace = _hints ? _hints->getCreateFrontFace() : true;
- bool drawBackFace = _hints ? _hints->getCreateBackFace() : false;
- // The only difference between the font & back face loops is that the
- // normals are inverted and the order of the vertex pairs is reversed.
- // The code is mostly duplicated in order to hoist the back/front face
- // test out of the loop for efficiency
- GLBeginEndAdapter& gl = _state.getGLBeginEndAdapter();
- gl.Begin(GL_QUAD_STRIP);
- if (drawFrontFace) {
- for(unsigned int bodyi=0;
- bodyi<numSegments;
- ++bodyi,angle+=angleDelta,texCoord+=texCoordDelta)
- {
- float c = cosf(angle);
- float s = sinf(angle);
- gl.Normal3f(c,s,0.0f);
- gl.TexCoord2f(texCoord,1.0f);
- gl.Vertex3f(c*r,s*r,topz);
- gl.TexCoord2f(texCoord,0.0f);
- gl.Vertex3f(c*r,s*r,basez);
- }
- // do last point by hand to ensure no round off errors.
- gl.Normal3f(1.0f,0.0f,0.0f);
- gl.TexCoord2f(1.0f,1.0f);
- gl.Vertex3f(r,0.0f,topz);
- gl.TexCoord2f(1.0f,0.0f);
- gl.Vertex3f(r,0.0f,basez);
- }
- if (drawBackFace) {
- for(unsigned int bodyi=0;
- bodyi<numSegments;
- ++bodyi,angle+=angleDelta,texCoord+=texCoordDelta)
- {
- float c = cosf(angle);
- float s = sinf(angle);
- gl.Normal3f(-c,-s,0.0f);
- gl.TexCoord2f(texCoord,0.0f);
- gl.Vertex3f(c*r,s*r,basez);
- gl.TexCoord2f(texCoord,1.0f);
- gl.Vertex3f(c*r,s*r,topz);
- }
- // do last point by hand to ensure no round off errors.
- gl.Normal3f(-1.0f,0.0f,0.0f);
- gl.TexCoord2f(1.0f,0.0f);
- gl.Vertex3f(r,0.0f,basez);
- gl.TexCoord2f(1.0f,1.0f);
- gl.Vertex3f(r,0.0f,topz);
- }
- gl.End();
- }
复制代码
thanks~ |
|