void reorderList(ListNode *head) { if(head == NULL) return ; ListNode * oneStep = head, * twoStep = head; while(twoStep->next && twoStep->next->next) { oneStep = oneStep->next; twoStep=twoStep->next->next; } ListNode * firstHalf = head; ListNode * lastHalf = oneStep->next; oneStep->next = NULL; lastHalf = reverse(lastHalf,NULL); ListNode dummyNode(INT_MAX); ListNode * pre = & dummyNode; while(firstHalf) { pre->next = firstHalf; ListNode * tmp = firstHalf->next; firstHalf->next = lastHalf; pre = lastHalf; firstHalf = tmp; if(lastHalf!=NULL) lastHalf = lastHalf->next; } }
//----------------------------------------------------------------------------- const Matrix4& AutoParamDataSource::getSpotlightViewProjMatrix(size_t index) const { if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS) { const Light& l = getLight(index); if (&l != &mBlankLight && l.getType() == Light::LT_SPOTLIGHT && mSpotlightViewProjMatrixDirty[index]) { Frustum frust; SceneNode dummyNode(0); dummyNode.attachObject(&frust); frust.setProjectionType(PT_PERSPECTIVE); frust.setFOVy(l.getSpotlightOuterAngle()); frust.setAspectRatio(1.0f); // set near clip the same as main camera, since they are likely // to both reflect the nature of the scene frust.setNearClipDistance(mCurrentCamera->getNearClipDistance()); // Calculate position, which same as spotlight position, in camera-relative coords if required dummyNode.setPosition(l.getDerivedPosition(true)); // Calculate direction, which same as spotlight direction Vector3 dir = - l.getDerivedDirection(); // backwards since point down -z dir.normalise(); Vector3 up = Vector3::UNIT_Y; // Check it's not coincident with dir if (Math::Abs(up.dotProduct(dir)) >= 1.0f) { // Use camera up up = Vector3::UNIT_Z; } // cross twice to rederive, only direction is unaltered Vector3 left = dir.crossProduct(up); left.normalise(); up = dir.crossProduct(left); up.normalise(); // Derive quaternion from axes Quaternion q; q.FromAxes(left, up, dir); dummyNode.setOrientation(q); // The view matrix here already includes camera-relative changes if necessary // since they are built into the frustum position mSpotlightViewProjMatrix[index] = PROJECTIONCLIPSPACE2DTOIMAGESPACE_PERSPECTIVE * frust.getProjectionMatrixWithRSDepth() * frust.getViewMatrix(); mSpotlightViewProjMatrixDirty[index] = false; } return mSpotlightViewProjMatrix[index]; } else return Matrix4::IDENTITY; }
ListNode *removeNthFromEnd(ListNode *head, int n) { if( n == 0 ) return head; ListNode dummyNode(0); dummyNode.next = head; ListNode * last = &dummyNode; ListNode * before = &dummyNode; for(int i = 0 ;i < n ;i++) { last = last->next; } while(last->next) { last = last->next; before = before->next; } before->next = before->next->next; return dummyNode.next; }