TextureProjectorNode::TextureProjectorNode( Texture* texture, SceneManagerptr sceneManagerPtr, Nodeptr parent ) :Node(parent , sceneManagerPtr) { this->texture = texture; projectionPolicy = PROJECTION_POLICY_PROJECTOR; projectorPosition.x = 15.0f; projectorPosition.y = 16.0f; projectorPosition.z = -12.0f; projectorTarget.x = 0.0f; projectorTarget.y = 0.0f; projectorTarget.z = 0.0f; projectorUp.x = 0.0f; projectorUp.y =1.0f; projectorUp.z = 0.0f; textureProjector = new TextureProjector(sceneManager->getActiveCamera() , projectorPosition, projectorTarget, projectorUp); projectorUpdator = new ProjectorUpdater(textureProjector); addAnimator(projectorUpdator); projectorTexUnitState = new TextureUnitState(texture); projectorTexUnitState->getTextureAttributes()->texture_mode = ETEXM_MODULATE; projectorTexUnitState->getTexCoordGeneration()->bEnable = true; projectorTexUnitState->getTexCoordGeneration()->texGenMode = ETGM_EYE_LINEAR; projectorTexUnitState->getTexCoordGeneration()->texComponentFormat = ETCF_4; projectorUpdator->projectorTextureAttributes = projectorTexUnitState->getTextureAttributes(); Vector3 dir, right, upVector; dir.sub( projectorTarget, projectorPosition); dir.normalize(); CameraNode* camera = sceneManager->getActiveCamera(); float fov = camera->getFOV(); dir.scale( camera->getNearPlane() ); Matrix4f& view = textureProjector->getViewMatrix(); right.x = view.m00; right.y = view.m01;right.z = view.m02; upVector.x = view.m10; upVector.x = view.m11; upVector.x = view.m12; float height = 2.0f*camera->getNearPlane()*tan(fov/2.0f); float width = height* camera->getAspectRatio(); width = height = 1.0f; n1.x = projectorPosition.x + dir.x + 0.5f*width*right.x + 0.5f*height*upVector.x; n1.y = projectorPosition.y + dir.y + 0.5f*width*right.y + 0.5f*height*upVector.y; n1.z = projectorPosition.z + dir.z + 0.5f*width*right.z + 0.5f*height*upVector.z; n2.x = projectorPosition.x + dir.x + 0.5f*width*right.x - 0.5f*height*upVector.x; n2.y = projectorPosition.y + dir.y + 0.5f*width*right.y - 0.5f*height*upVector.y; n2.z = projectorPosition.z + dir.z + 0.5f*width*right.z - 0.5f*height*upVector.z; n3.x = projectorPosition.x + dir.x - 0.5f*width*right.x + 0.5f*height*upVector.x; n3.y = projectorPosition.y + dir.y - 0.5f*width*right.y + 0.5f*height*upVector.y; n3.z = projectorPosition.z + dir.z - 0.5f*width*right.z + 0.5f*height*upVector.z; n4.x = projectorPosition.x + dir.x - 0.5f*width*right.x - 0.5f*height*upVector.x; n4.y = projectorPosition.y + dir.y - 0.5f*width*right.y - 0.5f*height*upVector.y; n4.z = projectorPosition.z + dir.z - 0.5f*width*right.z - 0.5f*height*upVector.z; }