public void visit(GL10 gl) { // quick return if not visible if (!visible_) return; gl.glPushMatrix(); if (grid_ != null && grid_.isActive()) { grid_.beforeDraw(gl); transformAncestors(gl); } transform(gl); if (children_ != null) { for (int i = 0; i < children_.size(); ++i) { child = children_.get(i); if (child.zOrder_ < 0) { child.visit(gl); } else break; } } draw(gl); if (children_ != null) { for (int i = 0; i < children_.size(); ++i) { child = children_.get(i); if (child.zOrder_ >= 0) { child.visit(gl); } } } if (grid_ != null && grid_.isActive()) { grid_.afterDraw(gl, this); } gl.glPopMatrix(); }
/** * performs OpenGL view-matrix transformation based on position, scale, rotation and other * attributes. */ public void transform(GL10 gl) { // transformations if (ccConfig.CC_NODE_TRANSFORM_USING_AFFINE_MATRIX) { // BEGIN alternative -- using cached transform // if (isTransformGLDirty_) { CGAffineTransform t = nodeToParentTransform(); CGAffineTransform.CGAffineToGL(t, transformGL_); isTransformGLDirty_ = false; } // gl.glMultMatrixf(transformGL_, transformGL_.length); gl.glMultMatrixf(transformGL_, 0); if (vertexZ_ != 0) gl.glTranslatef(0, 0, vertexZ_); // XXX: Expensive calls. Camera should be integrated into the cached affine matrix if (camera_ != null && !(grid_ != null && grid_.isActive())) { boolean translate = (anchorPointInPixels_.x != 0.0f || anchorPointInPixels_.y != 0.0f); if (translate) gl.glTranslatef( RENDER_IN_SUBPIXEL(anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(anchorPointInPixels_.y), 0); camera_.locate(gl); if (translate) gl.glTranslatef( RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0); } // END alternative } else { // BEGIN original implementation // // translate if (isRelativeAnchorPoint_ && (anchorPointInPixels_.x != 0 || anchorPointInPixels_.y != 0)) gl.glTranslatef( RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0); if (anchorPointInPixels_.x != 0 || anchorPointInPixels_.y != 0) gl.glTranslatef( RENDER_IN_SUBPIXEL(position_.x + anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(position_.y + anchorPointInPixels_.y), vertexZ_); else if (position_.x != 0 || position_.y != 0 || vertexZ_ != 0) gl.glTranslatef(RENDER_IN_SUBPIXEL(position_.x), RENDER_IN_SUBPIXEL(position_.y), vertexZ_); // rotate if (rotation_ != 0.0f) gl.glRotatef(-rotation_, 0.0f, 0.0f, 1.0f); // scale if (scaleX_ != 1.0f || scaleY_ != 1.0f) gl.glScalef(scaleX_, scaleY_, 1.0f); if (camera_ != null && !(grid_ != null && grid_.isActive())) camera_.locate(gl); // restore and re-position point if (anchorPointInPixels_.x != 0.0f || anchorPointInPixels_.y != 0.0f) gl.glTranslatef( RENDER_IN_SUBPIXEL(-anchorPointInPixels_.x), RENDER_IN_SUBPIXEL(-anchorPointInPixels_.y), 0); // // END original implementation } }