void GameBodyObject::render(float) 
	{
	#if (NX_UNSTABLE_USE_SCENE_ACTIVE_TRANSFORM == 1)

		NxMat34 nm = mActor->getGlobalPose();
		NxVec3 nv(nm.t);
		NxQuat nq(nm.M);
		if (mNode != NULL)
		{
			mNode->setPosition(nv.x, nv.y, nv.z);
			mNode->setOrientation(nq.w,nq.x,nq.y,nq.z);
		}
		shapeRender(0);
	#else
		if ((mActor != NULL) && (mNode != NULL))
		{
			mNode->setPosition(getGlobalPosition());
			mNode->setOrientation(getGlobalOrientation());
			shapeRender(dT);
		}	
	#endif

		// Update the prevGlobalTransform value
		if (mNode != NULL)
		{
			prevGlobalPosition = mNode->_getDerivedPosition();
			prevGlobalOrientation = mNode->_getDerivedOrientation();
		}
	}
Beispiel #2
0
//----------------------------------------
void ofLight::onOrientationChanged() {
	if(data->glIndex==-1) return;
	if(getIsDirectional()) {
		// if we are a directional light and not positional, update light position (direction)
		auto lookAtDir = glm::normalize(getGlobalOrientation() * glm::vec4(0,0,-1, 1)).xyz();
		data->position = {lookAtDir.x,lookAtDir.y,lookAtDir.z,0.f};
		ofGetGLRenderer()->setLightPosition(data->glIndex,data->position);
	}else if(getIsSpotlight() || getIsAreaLight()) {
		// determines the axis of the cone light
		auto lookAtDir = glm::normalize(getGlobalOrientation() * glm::vec4(0,0,-1, 1)).xyz();
		data->direction = lookAtDir;
		ofGetGLRenderer()->setLightSpotDirection(data->glIndex, glm::vec4(data->direction, 0.0f));
	}
	if(getIsAreaLight()){
		data->up = getUpDir();
		data->right = getXAxis();
	}
}
	void GameBodyObject::restoreCustom(NxOgre::StringPairList spl) 
	{

		mNode = mpScene->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode();

		for (NxOgre::StringPairList::StringPair sp = spl.begin();spl.hasNext();) 
		{
			sp = spl.next();
	/*
			std::stringstream ss;
			ss << sp.first;
			ss << " => ";
			ss << sp.second;
			ss << std::endl;

			NxDebug(ss.str());
	*/
			NxOgre::NxString key = sp.first;
			Ogre::StringUtil::toLowerCase(key);

			if (key == "entity" || key == "node") 
			{

				Ogre::Entity* entity = mpScene->getOgreSceneManager()->createEntity(
					mName + "-" + sp.second + "-" + Ogre::StringConverter::toString(mNode->numAttachedObjects()), 
					sp.second
				);

				mNode->attachObject(entity);

			}

			if (key == "node-scale") 
			{
				mNode->setScale(Ogre::StringConverter::parseVector3(sp.second));
			}

		}

		// Assign first Attached Object that is an entity to mEntity

		Ogre::SceneNode::ObjectIterator object_it = mNode->getAttachedObjectIterator();
		Ogre::MovableObject *m;
		while(object_it.hasMoreElements()) 
		{
			m = object_it.getNext();
			if (m->getMovableType() == "Entity")
			{
				mEntity = (Ogre::Entity*) m;
				break;
			}
		}

		mNode->setPosition(getGlobalPosition());
		mNode->setOrientation(getGlobalOrientation());

	}
Beispiel #4
0
void ofxFBXCamera::updateLookAt(){
	float  length = (target - getGlobalPosition()).length();

	ofVec3f rotationVector(1.0,0,0);
	ofVec3f center = getGlobalOrientation() * rotationVector;
	center *= length;
	center += getPosition();


	rotationVector.set(0,1.0,0);
    ofVec3f up = getGlobalOrientation() * rotationVector;

    ofVec3f forward = center - getGlobalPosition();
    forward.normalize();
    ofVec3f right = up.cross(forward);
    right.normalize();
    up = forward.cross(right);
    up.normalize();

	lookAt(center,up);
}
void BasicInteractiveObject::addMultiTouch(mtRay ray, int touchId){
	MultiTouchPoint* mtp = new MultiTouchPoint();
	
	plane.pos	= getGlobalPosition();
	plane.norm	= ofVec3f(0,0,1)*getGlobalOrientation();
	
	float u		= plane.norm.dot(plane.pos-ray.pos)/plane.norm.dot(ray.dir);
	ofVec3f gintersection = ray.pos+ray.dir*u;
	
	mtp->screenpos.set(ray.screenpos);
	mtp->globalstartpos.set(gintersection);	
	mtp->localstartpos	= globalToLocal(mtp->globalstartpos);
	mtp->localpos		= mtp->localstartpos;
	mtp->localoffset	= mtp->localstartpos-getPosition();
	mtp->globalpos		= mtp->globalstartpos;
	mtp->globalmovedist	= 0;
	mtp->starttime		= ofGetElapsedTimeMillis();	
	
	activeMultiTouches[touchId] = mtp;
	mtcounter++;
    
    
    // Flipped order (was before)
    
	if(activeMultiTouches.size() == 1){
		// Start of Scope
		mtstarttime		= ofGetElapsedTimeMillis();
		mtscoperunning	= true;
		MultiTouchEvent params(this, mtp);
		ofNotifyEvent(firstTouchDownEvent,params,this);
	}
	
    
	if(activeMultiTouches.size()>=2){
		MultiTouchEvent params(this);
		ofNotifyEvent(startMultiTouchScopeEvent,params,this);
	}
    
    // Flipped order (was after)
    
    mttranslatedist	= 0;
	mtrotatedist	= 0;
	mtscaledist		= 0;
	
	mttranslatespeed.set(0,0,0);
	mtrotatespeed.set(0,0,0,1);
	mtscalespeed=0;
	
    resetMTStartValues();
}
Beispiel #6
0
void StickyNoteActor::onRender(uint flags)
{
	if (!isActorType(Invisible))
	{
		if (_stickyNoteTextureId == 0)
			syncStickyNoteWithFileContents();
		
		setTextureID("icon.custom.stickyNote");
		Actor::onRender(flags);
#ifdef DXRENDER
		dxr->device->SetRenderState(D3DRS_ZENABLE, false);
		dxr->renderSideLessBox(getGlobalPosition(), getGlobalOrientation(), getDims(), _stickyNoteTextureId);
		dxr->device->SetRenderState(D3DRS_ZENABLE, true);
#endif
	}
}
Beispiel #7
0
//----------------------------------------
void ofNode::clearParent(bool bMaintainGlobalTransform) {
	if(parent){
		parent->removeListener(*this);
	}
	if(bMaintainGlobalTransform && parent) {
		auto orientation = getGlobalOrientation();
		auto position = getGlobalPosition();
		auto scale = getGlobalScale();
		this->parent = nullptr;
		setOrientation(orientation);
		setPosition(position);
		setScale(scale);
	}else{
		this->parent = nullptr;
	}

}
void BasicInteractiveObject::updateMultiTouch(mtRay ray, int touchId){
	if(isMultiTouchActive(touchId)){
	
		plane.pos	= getGlobalPosition();
		plane.norm	= ofVec3f(0,0,1)*getGlobalOrientation();
		
		float u		= plane.norm.dot(plane.pos-ray.pos)/plane.norm.dot(ray.dir);
		ofVec3f gintersection = ray.pos+ray.dir*u;
		
		MultiTouchPoint* mtp = activeMultiTouches[touchId];

		mtp->screenpos.set(ray.screenpos);
		mtp->globalposbef.set(mtp->globalpos);
		mtp->globalpos.set(gintersection);
		mtp->globalspeed.set(mtp->globalpos-mtp->globalposbef);
		mtp->localposbef.set(mtp->localpos);
		mtp->localpos.set(globalToLocal(mtp->globalpos));
		mtp->localspeeddamped.set((mtp->localspeed + (mtp->localpos-mtp->localposbef))/2);
		mtp->localspeed.set(mtp->localpos-mtp->localposbef);		
		mtp->globalmovedist += mtp->globalspeed.length();
	}
}
Beispiel #9
0
//--------------------------------------------------------------
ofVec3f SurfaceNode::getGlobalPositionDevicePointSurface(Device* pDevice)
{
    return getGlobalOrientation() * (getPosition() + ofVec3f(pDevice->m_pointSurface.x*getWidth(),getHeight()-pDevice->m_pointSurface.y*getHeight(),0.0f));
}
Beispiel #10
0
void FileSystemActor::onRender(uint flags)
{
#ifdef TESTING_ALTERNATE_RENDERING
	
	if (isActorType(Invisible))
		return;

	// _isAnimatedTexture is always false right now since we don't robustly support animated gifs
	if (_isAnimatedTexture)
	{
		bool successful = true;
		
		// if this is an animated texture and we've never loaded the animation
		// then do so now

		if (!_animatedTextureSource.load())
			_isAnimatedTexture = false;

		if (_animatedTextureSource.numFrames() <= 1)
			successful = false;
		else
		{
			AnimatedTextureFrame * frame = _animatedTextureSource.getCurrentTextureFrame();
			Vec3 sz = getDims();

			glPushAttribToken token(GL_ENABLE_BIT);
			glEnable(GL_DEPTH_TEST);
			glEnable(GL_BLEND);
			glEnable(GL_TEXTURE_2D);

			// Conditionals
			if (isSelected() || isActorType(Temporary)) glDisable(GL_DEPTH_TEST);
			if (isActorType(Invisible)) return;

			//transform our unit cube:
			glPushMatrix();

				ShapeVis::setupGLMatrix(getGlobalPosition(), getGlobalOrientation());
				glScaled(sz.x, sz.y, sz.z);

				// render the current index
				glBindTexture(GL_TEXTURE_2D, _animatedTextureSource.GLId());			
				glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frame->width, frame->height, GL_BGRA, GL_UNSIGNED_BYTE, frame->pixelData);
				
				// Set the Texture
				glColor4f(1, 1, 1, getAlpha());

				// Scale the image
				uint squareSize = closestPowerOfTwo(NxMath::max(frame->width, frame->height));
				float w = (float) frame->width / squareSize;
				float h = (float) frame->height / squareSize;
				h = 1.0f - (h * w);

				glBegin(GL_QUADS);
					glNormal3f(0,0,1);
					glTexCoord2f(w,0); 	glVertex3f(1,1,1);
					glTexCoord2f(0,0); 	glVertex3f(-1,1,1);
					glTexCoord2f(0,h); 	glVertex3f(-1,-1,1);
					glTexCoord2f(w,h); 	glVertex3f(1,-1,1);

					glNormal3f(0,0,-1);
					glTexCoord2f(0,h); 	glVertex3f(1,-1,-1);
					glTexCoord2f(w,h); 	glVertex3f(-1,-1,-1);
					glTexCoord2f(w,0); 	glVertex3f(-1,1,-1);
					glTexCoord2f(0,0); 	glVertex3f(1,1,-1);
				glEnd();

			glPopMatrix();
		}

		// skip the normal rendering routine
		if (successful)
			return;
	}

	// Render the previous actor first
	Actor::onRender(flags);

	// Render an overlay
	bool isLinkOverlay = (isFileSystemType(Link) || isFileSystemType(DeadLink)) && GLOBAL(settings).manualArrowOverlay;
	bool isFileTypeOverlay = !getTextIcon().isEmpty();
	
	if (isLinkOverlay || isFileTypeOverlay)
	{
		glPushAttribToken token(GL_ENABLE_BIT);
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glEnable(GL_TEXTURE_2D);

		// Render the shortcut/file type icon Arrow
		QString renderTextureId = QT_NT("icon.linkOverlay");
		Vec3 renderPos = getGlobalPosition();
		Vec3 renderDims = getDims();
		bool shouldScaleIcon = false;
		if (isFileTypeOverlay)
		{
			renderTextureId = getTextIcon();
			shouldScaleIcon = true;
		}
		else if (isLinkOverlay)
		{
			// If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor
			// A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner
			Vec3 dimensions = texMgr->getTextureDims(renderTextureId);
			if (dimensions.x > 0 && dimensions.y > 0) 
			{
				if ((closestPowerOfTwo(dimensions.x) != 256) || (closestPowerOfTwo(dimensions.y) != 256))
				{
					shouldScaleIcon = true;
					
					// position the link icon to the corner of the actual actor (instead of scaling/stretching it)
					float maxSide = max(dimensions.x, dimensions.y);
					renderDims.x = renderDims.y = maxSide;
				}
			}
		}

		if (shouldScaleIcon)
		{
			Vec3 offset(getDims().x, -getDims().y, 0);
			
			// Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4)
			renderDims.x /= 3.4f;
			renderDims.y /= 3.4f;
			
			offset += Vec3(-renderDims.x - 0.25f, renderDims.y + 0.25f, 0);
			offset = getGlobalOrientation() * offset;
			renderPos += offset;
		}
		glBindTexture(GL_TEXTURE_2D, texMgr->getGLTextureId(renderTextureId));
		glColor4f(1, 1, 1, getAlpha());
		ShapeVis::renderSideLessBox(renderPos, getGlobalOrientation(), renderDims);
	}
#elif !defined DXRENDER
	// _isAnimatedTexture is always false right now since we don't robustly support animated gifs
	if (_isAnimatedTexture)
	{
		bool successful = true;
		
		// if this is an animated texture and we've never loaded the animation
		// then do so now

		if (!_animatedTextureSource.load())
			_isAnimatedTexture = false;

		if (_animatedTextureSource.numFrames() <= 1)
			successful = false;
		else
		{
			AnimatedTextureFrame * frame = _animatedTextureSource.getCurrentTextureFrame();
			Vec3 sz = getDims();

			glPushAttribToken token(GL_ENABLE_BIT);
			glEnable(GL_DEPTH_TEST);
			glEnable(GL_BLEND);
			glEnable(GL_TEXTURE_2D);

			// Conditionals
			if (isSelected() || isActorType(Temporary)) glDisable(GL_DEPTH_TEST);
			if (isActorType(Invisible)) return;

			//transform our unit cube:
			glPushMatrix();

				ShapeVis::setupGLMatrix(getGlobalPosition(), getGlobalOrientation());
				glScaled(sz.x, sz.y, sz.z);

				// render the current index
				glBindTexture(GL_TEXTURE_2D, _animatedTextureSource.GLId());			
				glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frame->width, frame->height, GL_BGRA, GL_UNSIGNED_BYTE, frame->pixelData);
				
				// Set the Texture
				glColor4f(1, 1, 1, getAlpha());

				// Scale the image
				uint squareSize = closestPowerOfTwo(NxMath::max(frame->width, frame->height));
				float w = (float) frame->width / squareSize;
				float h = (float) frame->height / squareSize;
				h = 1.0f - (h * w);

				glBegin(GL_QUADS);
					glNormal3f(0,0,1);
					glTexCoord2f(w,0); 	glVertex3f(1,1,1);
					glTexCoord2f(0,0); 	glVertex3f(-1,1,1);
					glTexCoord2f(0,h); 	glVertex3f(-1,-1,1);
					glTexCoord2f(w,h); 	glVertex3f(1,-1,1);

					glNormal3f(0,0,-1);
					glTexCoord2f(0,h); 	glVertex3f(1,-1,-1);
					glTexCoord2f(w,h); 	glVertex3f(-1,-1,-1);
					glTexCoord2f(w,0); 	glVertex3f(-1,1,-1);
					glTexCoord2f(0,0); 	glVertex3f(1,1,-1);
				glEnd();

			glPopMatrix();
		}

		// skip the normal rendering routine
		if (successful)
			return;
	}

	// Render the previous actor first
	Actor::onRender(flags);

	// Render a link overlay arrow
	if ((isFileSystemType(Link) || isFileSystemType(DeadLink)) && !isActorType(Invisible))
	{
		glPushAttribToken token(GL_ENABLE_BIT);
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glEnable(GL_TEXTURE_2D);

		// Render the shortcut Arrow
		if (GLOBAL(settings).manualArrowOverlay)
		{
			glBindTexture(GL_TEXTURE_2D, texMgr->getGLTextureId("icon.linkOverlay"));

			bool scaleOverlayActor = false;

			//If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor
			Vec3 dimensions = texMgr->getTextureDims("icon.linkOverlay");

			//A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner
			if(dimensions.x > 0 && dimensions.y > 0) {
				if((closestPowerOfTwo(dimensions.x) != 256)||(closestPowerOfTwo(dimensions.y) != 256))
					scaleOverlayActor = true;
			}

			glColor4f(1, 1, 1, getAlpha());

			// Render Shape
			Vec3 pos = getGlobalPosition();
			Vec3 dims = getDims();
			Vec3 normalizedDims = dims;

			// position the link icon to the corner of the actual actor (instead of scaling/stretching it)
			float maxSide = max(dims.x, dims.y);
			normalizedDims.x = normalizedDims.y = maxSide;

			// Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4)
			if(scaleOverlayActor){
				normalizedDims.x /= 3.4f;
				normalizedDims.y /= 3.4f;
			}
			
			if(scaleOverlayActor) {
				Vec3 offset(dims.x, -dims.y, 0);
				offset = getGlobalOrientation() * offset;
				pos += offset;
			} else {
				pos.x -= normalizedDims.x - dims.x;
				pos.z += normalizedDims.y - dims.y;
			}

			ShapeVis::renderSideLessBox(pos, getGlobalOrientation(), normalizedDims);
		}
	}
#elif defined DXRENDER
	// Render the previous actor first
	Actor::onRender(flags);

	// Render a link overlay arrow
	if ((isFileSystemType(Link) || isFileSystemType(DeadLink)) && !isActorType(Invisible))
	{
		// Render the shortcut Arrow
		if (GLOBAL(settings).manualArrowOverlay)
		{
			bool scaleOverlayActor = false;

			//If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor
			Vec3 dimensions = texMgr->getTextureDims("icon.linkOverlay");

			//A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner
			if(dimensions.x > 0 && dimensions.y > 0) {
				if((closestPowerOfTwo(dimensions.x) != 256)||(closestPowerOfTwo(dimensions.y) != 256))
					scaleOverlayActor = true;
			}

			// Render Shape
			Vec3 pos = getGlobalPosition();
			Vec3 dims = getDims();
			Vec3 normalizedDims = dims;

			// position the link icon to the corner of the actual actor (instead of scaling/stretching it)
			float maxSide = max(dims.x, dims.y);
			normalizedDims.x = normalizedDims.y = maxSide;

			// Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4)
			if(scaleOverlayActor){
				normalizedDims.x /= 3.4f;
				normalizedDims.y /= 3.4f;
			}
			
			if(scaleOverlayActor) {
				Vec3 offset(dims.x, -dims.y, 0);
				offset = getGlobalOrientation() * offset;
				pos += offset;
			} else {
				pos.x -= normalizedDims.x - dims.x;
				pos.z += normalizedDims.y - dims.y;
			}
			
			dxr->device->SetRenderState(D3DRS_ZENABLE, false);
			dxr->renderSideLessBox(pos, getGlobalOrientation(), normalizedDims, texMgr->getGLTextureId("icon.linkOverlay"));
			dxr->device->SetRenderState(D3DRS_ZENABLE, true);
		}
	}
#endif
}