Esempio n. 1
0
void ObjectMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine) {
    if (flags & EntityItem::DIRTY_POSITION) {
        btTransform worldTrans;
        if (flags & EntityItem::DIRTY_ROTATION) {
            worldTrans.setRotation(glmToBullet(getObjectRotation()));
        } else {
            worldTrans = _body->getWorldTransform();
        }
        worldTrans.setOrigin(glmToBullet(getObjectPosition()));
        _body->setWorldTransform(worldTrans);
    } else if (flags & EntityItem::DIRTY_ROTATION) {
        btTransform worldTrans = _body->getWorldTransform();
        worldTrans.setRotation(glmToBullet(getObjectRotation()));
        _body->setWorldTransform(worldTrans);
    }

    if (flags & EntityItem::DIRTY_LINEAR_VELOCITY) {
        _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
        _body->setGravity(glmToBullet(getObjectGravity()));
    }
    if (flags & EntityItem::DIRTY_ANGULAR_VELOCITY) {
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
    }

    if (flags & EntityItem::DIRTY_MATERIAL) {
        updateBodyMaterialProperties();
    }

    if (flags & EntityItem::DIRTY_MASS) {
        updateBodyMassProperties();
    }
}
/*
 * input:  grayscale frame
 * output: Point2i with detected position
 */
int ObjectDetection::detectObject(Mat frame, Point2i& pixelPosition) {
  Mat diffImage, thresholdImage;
  Rect objectBounding = Rect(0, 0, 0, 0);

  // subtract background and create binary mask
  absdiff(refereceFrame, frame, diffImage); // output: grayscale
  threshold(diffImage, thresholdImage, SENSITIVITY_VALUE, 255, THRESH_BINARY); // output: binary
#ifdef SHOW_THESHOLD
  if (cam->get_cameraID() == 1) {
    imshow("cam2 threshold 1", thresholdImage);
  } else {
    imshow("cam1 threshold 1", thresholdImage);
  }
#endif

  // blur and threshold again to get rid of noise
  blur(thresholdImage, thresholdImage, cv::Size(BLUR_SIZE, BLUR_SIZE)); // output: grayscale
  threshold(thresholdImage, thresholdImage, SENSITIVITY_VALUE, 255, THRESH_BINARY); // output: binary
#ifdef SHOW_THESHOLD
  if (cam->get_cameraID() == 1) {
    imshow("cam2 threshold 2", thresholdImage);
  } else {
    imshow("cam1 threshold 2", thresholdImage);
  }
#endif

  int error = getObjectPosition(thresholdImage, pixelPosition, &objectBounding);

  if (0 == error) {
    return OK;
  } else {
    return ERR;
  }

}
Esempio n. 3
0
// This callback is invoked by the physics simulation in two cases:
// (1) when the RigidBody is first added to the world
//     (irregardless of PhysicsMotionType: STATIC, DYNAMIC, or KINEMATIC)
// (2) at the beginning of each simulation step for KINEMATIC RigidBody's --
//     it is an opportunity for outside code to update the object's simulation position
void EntityMotionState::getWorldTransform(btTransform& worldTrans) const {
    BT_PROFILE("getWorldTransform");
    if (!_entity) {
        return;
    }
    assert(entityTreeIsLocked());
    if (_motionType == MOTION_TYPE_KINEMATIC) {
        BT_PROFILE("kinematicIntegration");
        // This is physical kinematic motion which steps strictly by the subframe count
        // of the physics simulation and uses full gravity for acceleration.
        _entity->setAcceleration(_entity->getGravity());
        uint32_t thisStep = ObjectMotionState::getWorldSimulationStep();
        float dt = (thisStep - _lastKinematicStep) * PHYSICS_ENGINE_FIXED_SUBSTEP;
        _entity->stepKinematicMotion(dt);

        // bypass const-ness so we can remember the step
        const_cast<EntityMotionState*>(this)->_lastKinematicStep = thisStep;

        // and set the acceleration-matches-gravity count high so that if we send an update
        // it will use the correct acceleration for remote simulations
        _accelerationNearlyGravityCount = (uint8_t)(-1);
    }
    worldTrans.setOrigin(glmToBullet(getObjectPosition()));
    worldTrans.setRotation(glmToBullet(_entity->getRotation()));
}
Esempio n. 4
0
Command *Command::opItemLookAt(Script *script, const ResourceReference &itemRef, const ResourceReference &objRef, bool suspend, int32 unknown) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();
	Math::Vector3d currentPosition = item->getPosition3D();

	Math::Vector3d targetPosition = getObjectPosition(objRef);
	Math::Vector3d targetDirection = targetPosition - currentPosition;

	if (targetDirection == Math::Vector3d()) {
		// Can't look at a target if we are sitting on top of it
		return nextCommand();
	}

	Turn *movement = new Turn(item);
	movement->setTargetDirection(targetDirection);
	movement->start();

	item->setMovement(movement);

	if (suspend) {
		script->suspend(item);
		item->setMovementSuspendedScript(script);
		return this; // Stay on the same command while suspended
	} else {
		return nextCommand();
	}
}
Esempio n. 5
0
/*****************************************************
**
**   GenericTableWriter   ---   writeObjectNameAndLongitude
**
******************************************************/
void GenericTableWriter::writeObjectNameAndLongitude( const uint &colid, const TcColumnSet &set )
{
	assert( table->getNbCols() >= colid + 2 );
	assert( table->getNbRows() > obs.size());
	SheetFormatter fmt;

	ObjectPosition pos;
	wxString s;

	switch( set.listcontext )
	{
		case TAB_LC_PLANETS:
			s = _( "Planet" );
		break;
		case TAB_LC_HOUSE_CUSPS:
			s = _( "House Cusp" );
		break;
		case TAB_LC_URANIAN:
			s = _( "Uranian" );
		break;
		default:
			s = wxT( "ERROR" );
		break;
	}
	table->setHeader( colid,  s );

	for ( uint p = 0; p < obs.size(); p++ )
	{
		table->setEntry( colid, p + 1, getObjectName( obs[p], set ));
		pos = getObjectPosition( obs[p], set );
		table->setEntry( colid + 1, p + 1, fmt.getPosFormatted( pos.longitude, pos.direction, DEG_PRECISION_SECOND ));
		if ( h->getTropicalLongitude( obs[p] ) == 0 ) table->errorcount++;
	}
}
Esempio n. 6
0
// This callback is invoked by the physics simulation in two cases:
// (1) when the RigidBody is first added to the world
//     (irregardless of PhysicsMotionType: STATIC, DYNAMIC, or KINEMATIC)
// (2) at the beginning of each simulation step for KINEMATIC RigidBody's --
//     it is an opportunity for outside code to update the object's simulation position
void EntityMotionState::getWorldTransform(btTransform& worldTrans) const {
    BT_PROFILE("getWorldTransform");
    if (!_entity) {
        return;
    }
    assert(entityTreeIsLocked());
    if (_motionType == MOTION_TYPE_KINEMATIC) {
        BT_PROFILE("kinematicIntegration");
        uint32_t thisStep = ObjectMotionState::getWorldSimulationStep();
        if (hasInternalKinematicChanges()) {
            // ACTION_CAN_CONTROL_KINEMATIC_OBJECT_HACK: This kinematic body was moved by an Action
            // and doesn't require transform update because the body is authoritative and its transform
            // has already been copied out --> do no kinematic integration.
            clearInternalKinematicChanges();
            _lastKinematicStep = thisStep;
            return;
        }
        // This is physical kinematic motion which steps strictly by the subframe count
        // of the physics simulation and uses full gravity for acceleration.
        _entity->setAcceleration(_entity->getGravity());

        float dt = (thisStep - _lastKinematicStep) * PHYSICS_ENGINE_FIXED_SUBSTEP;
        _lastKinematicStep = thisStep;
        _entity->stepKinematicMotion(dt);

        // and set the acceleration-matches-gravity count high so that if we send an update
        // it will use the correct acceleration for remote simulations
        _accelerationNearlyGravityCount = (uint8_t)(-1);
    }
    worldTrans.setOrigin(glmToBullet(getObjectPosition()));
    worldTrans.setRotation(glmToBullet(_entity->getWorldOrientation()));
}
Esempio n. 7
0
// virtual
void AvatarMotionState::setWorldTransform(const btTransform& worldTrans) {
    const float SPRING_TIMESCALE = 0.5f;
    float tau = PHYSICS_ENGINE_FIXED_SUBSTEP / SPRING_TIMESCALE;
    btVector3 currentPosition = worldTrans.getOrigin();
    btVector3 offsetToTarget = glmToBullet(getObjectPosition()) - currentPosition;
    float distance = offsetToTarget.length();
    if ((1.0f - tau) * distance > _diameter) {
        // the avatar body is far from its target --> slam position
        btTransform newTransform;
        newTransform.setOrigin(currentPosition + offsetToTarget);
        newTransform.setRotation(glmToBullet(getObjectRotation()));
        _body->setWorldTransform(newTransform);
        _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
    } else {
        // the avatar body is near its target --> slam velocity
        btVector3 velocity = glmToBullet(getObjectLinearVelocity()) + (1.0f / SPRING_TIMESCALE) * offsetToTarget;
        _body->setLinearVelocity(velocity);
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
        // slam its rotation
        btTransform newTransform = worldTrans;
        newTransform.setRotation(glmToBullet(getObjectRotation()));
        _body->setWorldTransform(newTransform);
    }
}
Esempio n. 8
0
/*****************************************************
**
**   GenericTableWriter   ---   writeShastiamsaLords
**
******************************************************/
void GenericTableWriter::writeShastiamsaLords( const uint &i0, const TcColumnSet &set )
{
	int shast;
	Lang lang;
	ObjectPosition pos;

	const static bool k_shastiamsa_benefic[60] = {
		false, false, true, true, true, true, false, false, false, false,
		false, false, true, true, false, false, true, true, true, true,
		true, true, true, true, true, true, true, true, true, false,
		false, false, false, false, false, false, true, true, true, false,
		false, false, false, false, true, true, true, false, true, true,
		false, false, true, true, false, true, true, true, false, true,
	};

// Dignities

  table->setHeader( i0,  _( "D-60 Lords" ));
	for ( uint p = 0; p < obs.size(); p++ )
	{
		pos = getObjectPosition( obs[p], set );
		shast = (int)( a_red( pos.longitude, 30 ) * 2 );
		if ( isEvenRasi( pos.longitude )) shast = 59 - shast;
		assert( shast >= 0 && shast < 60 );
		table->setEntry( i0, p + 1, wxString::Format( wxT( "%s (%c)" ), lang.getShastiamsaName( shast ).c_str(),
			( k_shastiamsa_benefic[(int)shast] ? 'B' : 'M' )));
	}
}
Esempio n. 9
0
Command *Command::opIsItemNearPlace(const ResourceReference &itemRef, const ResourceReference &positionRef, int32 testDistance) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();

	Math::Vector3d itemPostion = item->getPosition3D();
	Math::Vector3d testPosition = getObjectPosition(positionRef);

	return nextCommandIf(itemPostion.getDistanceTo(testPosition) < testDistance);
}
Esempio n. 10
0
Command *Command::opIsItemOnPlace(const ResourceReference &itemRef, const ResourceReference &positionRef) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();

	Math::Vector3d itemPostion = item->getPosition3D();
	Math::Vector3d testPosition = getObjectPosition(positionRef);

	return nextCommandIf(itemPostion == testPosition);
}
Esempio n. 11
0
// virtual
void AvatarMotionState::getWorldTransform(btTransform& worldTrans) const {
    worldTrans.setOrigin(glmToBullet(getObjectPosition()));
    worldTrans.setRotation(glmToBullet(getObjectRotation()));
    if (_body) {
        _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
    }
}
Esempio n. 12
0
/*****************************************************
**
**   GenericTableWriter   ---   writeNakshatraPadas
**
******************************************************/
void GenericTableWriter::writeNakshatraPadas( const uint &i0, const TcColumnSet &set )
{
  table->setHeader( i0,  _( "Pada" ));
	ObjectPosition pos;
	for ( uint p = 0; p < obs.size(); p++ )
	{
		pos = getObjectPosition( obs[p], set );
		table->setEntry( i0, p + 1, wxString::Format( wxT( "%d" ), (int)(getNakshatraLongitude27( pos.longitude ) / 3.3333333333 ) + 1 ));
	}
}
Esempio n. 13
0
/*****************************************************
**
**   GenericTableWriter   ---   writeSignQualities
**
******************************************************/
void GenericTableWriter::writeSignQualities( const uint &i0, const TcColumnSet &set )
{
	Lang lang;
  table->setHeader( i0,  _( "Quality" ));
	ObjectPosition pos;
	for ( uint p = 0; p < obs.size(); p++ )
	{
		pos = getObjectPosition( obs[p], set );
		table->setEntry( i0, p + 1, lang.getSignQualityName( getRasi( pos.longitude )));
	}
}
Esempio n. 14
0
Command *Command::opItem3DPlaceOn(const ResourceReference &itemRef, const ResourceReference &targetRef) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();

	int32 targetFace = -1;
	Math::Vector3d targetPosition = getObjectPosition(targetRef, &targetFace);

	item->setPosition3D(targetPosition);
	item->setFloorFaceIndex(targetFace);

	return nextCommand();
}
Esempio n. 15
0
void RobotVREP::addObject( Object * object)
{
	int * handler = new int(getObjectHandle(object->getName(), simx_opmode_oneshot_wait));
	VrepHandlerVector.push_back( handler );
	objectVector.push_back( object );
	objectIdToVrepHandler_map.insert( std::pair<int,int> ( object->getUniqueObjectId() , VrepHandlerVector.size() -1 ) );

	getObjectPosition(object, -1, simx_opmode_streaming);
	getObjectOrientation(object, -1, simx_opmode_streaming);
	getObjectVelocity(object, simx_opmode_streaming);
}
Esempio n. 16
0
/*****************************************************
**
**   GenericTableWriter   ---   writeObjectLatitude
**
******************************************************/
void GenericTableWriter::writeObjectLatitude( const uint &i0, const TcColumnSet &set )
{
  table->setHeader( i0,  _( "Declination" ));
	Formatter *f = Formatter::get();
	ObjectPosition pos;
	for ( uint p = 0; p < obs.size(); p++ )
	{
		pos = getObjectPosition( obs[p], set );
		table->setEntry( i0, p + 1, f->getLatitudeFormatted( pos.latitude, DEG_PRECISION_SECOND ));
	}
}
Esempio n. 17
0
/*****************************************************
**
**   GenericTableWriter   ---   writeSignLords
**
******************************************************/
void GenericTableWriter::writeSignLords( const uint &i0, const TcColumnSet &set )
{
	ObjectPosition pos;
	SheetFormatter fmt;

  table->setHeader( i0,  _( "Lord" ));
	for ( uint p = 0; p < obs.size(); p++ )
	{
		pos = getObjectPosition( obs[p], set );
		table->setEntry( i0, p + 1, fmt.getObjectName( getLord( getRasi( pos.longitude ), set.vedic ), format, set.vedic ));
	}
}
Esempio n. 18
0
/*****************************************************
**
**   GenericTableWriter   ---   writeNavamsa
**
******************************************************/
void GenericTableWriter::writeNavamsa( const uint &i0, const TcColumnSet &set )
{
	ObjectPosition pos;
	SheetFormatter fmt;

  table->setHeader( i0,  _( "D-9" ));
	for ( uint p = 0; p < obs.size(); p++ )
	{
		pos = getObjectPosition( obs[p], set );
		table->setEntry( i0, p + 1, fmt.getSignName( getRasi( pos.longitude * 9 ), format ));
	}
}
Esempio n. 19
0
/*****************************************************
**
**   GenericTableWriter   ---   write45DegreeLongitude
**
******************************************************/
void GenericTableWriter::write45DegreeLongitude( const uint &colid, const TcColumnSet &set )
{
	assert( table->getNbCols() >= colid + 1 );
	assert( table->getNbRows() > obs.size());
	Formatter *formatter = Formatter::get();

	table->setHeader( colid,  _( "45 Degree" ));
	for ( uint p = 0; p < obs.size(); p++ )
	{
		table->setEntry( colid, p + 1, formatter->getLenFormatted( a_red( getObjectPosition( obs[p], set ).longitude, 45.0 )));
		if ( IS_EPHEM_OBJECT( obs[p] ) && h->getTropicalLongitude( obs[p] ) == 0 ) table->errorcount++;
	}
}
Esempio n. 20
0
/*****************************************************
**
**   GenericTableWriter   ---   writeNakshatras
**
******************************************************/
void GenericTableWriter::writeNakshatras( const uint &i0, const TcColumnSet &set )
{
	Lang lang;
  //table->setHeader( i0, _( "Nakshatra" ));
  wxString header = _( "Nakshatra" );
	if ( format == TF_SHORT ) header = header.Left( 3 );
  table->setHeader( i0, header );
	assert( table->getNbRows() > obs.size() );

	for ( uint p = 0; p < obs.size(); p++ )
	{
		table->setEntry( i0, p + 1,
			lang.getNakshatra27Name( ::getNakshatra27( getObjectPosition( obs[p], set ).longitude ), format ));
	}
}
Esempio n. 21
0
/*****************************************************
**
**   GenericTableWriter   ---   writeAntiscia
**
******************************************************/
void GenericTableWriter::writeAntiscia( const uint &colid, const TcColumnSet &set )
{
	assert( table->getNbCols() >= colid + 1 );
	assert( table->getNbRows() > obs.size());

	ObjectPosition pos;
	SheetFormatter fmt;

	table->setHeader( colid,  _( "Antiscium" ));
	for ( uint p = 0; p < obs.size(); p++ )
	{
		pos = getObjectPosition( obs[p], set );
		table->setEntry( colid, p + 1, fmt.getPosFormatted( getAntiscium( pos.longitude ),
			pos.direction, DEG_PRECISION_SECOND, TF_SHORT ));
		if ( IS_EPHEM_OBJECT( obs[p] ) && h->getTropicalLongitude( obs[p] ) == 0 ) table->errorcount++;
	}
}
Esempio n. 22
0
Command *Command::opItem3DSetWalkTarget(const ResourceReference &itemRef, const ResourceReference &targetRef) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();
	Math::Vector3d targetPosition = getObjectPosition(targetRef);

	Walk *walk = dynamic_cast<Walk *>(item->getMovement());
	if (walk) {
		walk->changeDestination(targetPosition);
	} else {
		walk = new Walk(item);
		walk->setDestination(targetPosition);
		walk->start();

		item->setMovement(walk);
	}

	return nextCommand();
}
Esempio n. 23
0
Command *Command::opItem3DWalkTo(Script *script, const ResourceReference &itemRef, const ResourceReference &targetRef, bool suspend) {
	FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>();
	Math::Vector3d targetPosition = getObjectPosition(targetRef);

	Walk *walk = new Walk(item);
	walk->setDestination(targetPosition);
	walk->start();

	item->setMovement(walk);

	if (suspend) {
		script->suspend(item);
		item->setMovementSuspendedScript(script);
		return this; // Stay on the same command while suspended
	} else {
		return nextCommand();
	}
}
Esempio n. 24
0
// This callback is invoked by the physics simulation in two cases:
// (1) when the RigidBody is first added to the world
//     (irregardless of MotionType: STATIC, DYNAMIC, or KINEMATIC)
// (2) at the beginning of each simulation step for KINEMATIC RigidBody's --
//     it is an opportunity for outside code to update the object's simulation position
void EntityMotionState::getWorldTransform(btTransform& worldTrans) const {
    if (!_entity) {
        return;
    }
    assert(entityTreeIsLocked());
    if (_motionType == MOTION_TYPE_KINEMATIC) {
        // This is physical kinematic motion which steps strictly by the subframe count
        // of the physics simulation.
        uint32_t thisStep = ObjectMotionState::getWorldSimulationStep();
        float dt = (thisStep - _lastKinematicStep) * PHYSICS_ENGINE_FIXED_SUBSTEP;
        _entity->simulateKinematicMotion(dt);

        // bypass const-ness so we can remember the step
        const_cast<EntityMotionState*>(this)->_lastKinematicStep = thisStep;
    }
    worldTrans.setOrigin(glmToBullet(getObjectPosition()));
    worldTrans.setRotation(glmToBullet(_entity->getRotation()));
}
Esempio n. 25
0
Command *Command::opWalkTo(Script *script, const ResourceReference &objectRef, int32 suspend) {
	Resources::ModelItem *april = StarkGlobal->getCurrent()->getInteractive();

	Math::Vector3d destinationPosition = getObjectPosition(objectRef);
	Math::Vector3d currentPosition = april->getPosition3D();

	if (destinationPosition == currentPosition) {
		return nextCommand();
	}

	Walk *walk = new Walk(april);
	walk->setDestination(destinationPosition);
	walk->start();

	april->setMovement(walk);

	if (suspend) {
		script->suspend(april);
		april->setMovementSuspendedScript(script);
		return this; // Stay on the same command while suspended
	} else {
		return nextCommand();
	}
}
Esempio n. 26
0
void ObjectMotionState::handleEasyChanges(uint32_t flags) {
    if (flags & EntityItem::DIRTY_POSITION) {
        btTransform worldTrans;
        if (flags & EntityItem::DIRTY_ROTATION) {
            worldTrans.setRotation(glmToBullet(getObjectRotation()));
        } else {
            worldTrans = _body->getWorldTransform();
        }
        worldTrans.setOrigin(glmToBullet(getObjectPosition()));
        _body->setWorldTransform(worldTrans);
    } else if (flags & EntityItem::DIRTY_ROTATION) {
        btTransform worldTrans = _body->getWorldTransform();
        worldTrans.setRotation(glmToBullet(getObjectRotation()));
        _body->setWorldTransform(worldTrans);
    }

    if (flags & EntityItem::DIRTY_LINEAR_VELOCITY) {
        _body->setLinearVelocity(glmToBullet(getObjectLinearVelocity()));
        _body->setGravity(glmToBullet(getObjectGravity()));
    }
    if (flags & EntityItem::DIRTY_ANGULAR_VELOCITY) {
        _body->setAngularVelocity(glmToBullet(getObjectAngularVelocity()));
    }

    if (flags & EntityItem::DIRTY_MATERIAL) {
        updateBodyMaterialProperties();
    }

    if (flags & EntityItem::DIRTY_MASS) {
        float mass = getMass();
        btVector3 inertia(0.0f, 0.0f, 0.0f);
        _body->getCollisionShape()->calculateLocalInertia(mass, inertia);
        _body->setMassProps(mass, inertia);
        _body->updateInertiaTensor();
    }
}
Esempio n. 27
0
// virtual
void DetailedMotionState::getWorldTransform(btTransform& worldTrans) const {
    worldTrans.setOrigin(glmToBullet(getObjectPosition()));
    worldTrans.setRotation(glmToBullet(getObjectRotation()));
}
Esempio n. 28
0
void Assignment6::idle()
{
	// idle is called each time through the event loop when there is no
	// pending render call, or interaction event to process.
	// That makes it ideal for animation, and similar actions

	double currTime = UI::getTime(); // current time

	if (m_isRayTracing)
	{
		RayTracing::Ray_t *rays;
		RayTracing::HitInfo_t *hitinfos;

		m_isProcessingRayTracing = true;


		clock_t start, finish;
		start = clock();
 

		for(int pass = 0; pass < MAX_RT_PASSES; pass++)
		{

			rays = m_camera.genViewRayInParallel(m_windowWidth,m_windowHeight);
			hitinfos = m_scene.rayIntersectsInParallel(rays, 0.0001, 300.0, m_windowWidth, m_windowHeight, NULL);

			gml::vec3_t *tempClrs = m_scene.shadeRaysInParallel(rays,hitinfos,MAX_RAY_DEPTH,m_windowWidth,m_windowHeight);

			memcpy(m_rtImage, tempClrs, m_windowWidth * m_windowHeight * sizeof(gml::vec3_t));

			delete[] tempClrs;

			// Copy the new image data to the texture for blitting to the screen.
			glBindTexture(GL_TEXTURE_2D, m_rtTex);
			glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_windowWidth, m_windowHeight, GL_RGB, GL_FLOAT, m_rtImage);
			if (isGLError()) return;

			m_cameraChanged = false;
			//fprintf(stdout, "Pass %d Complete\n", pass);

		}

		finish = clock();
 
		double exeTime = ( (finish - start)/1000.0 );
		printf("Took %lf to render a frame\n", exeTime);

		m_isProcessingRayTracing = false;


	}

	if (m_cameraMovement) // Is a camera movement key pressed?
	{
		// time since the last time we updated the camera
		double deltaT = currTime - m_lastCamMoveTime;
		if (deltaT > 0)
		{
			// Time has elapsed since the last time idle() was called
			// so, move the camera according to which key(s) are pressed.
			if (m_cameraMovement & CAMERA_FORWARD)
				m_camera.moveForward( m_movementSpeed * deltaT );
			if (m_cameraMovement & CAMERA_BACKWARD)
				m_camera.moveForward( -m_movementSpeed * deltaT );

			if (m_cameraMovement & CAMERA_STRAFE_RIGHT)
				m_camera.strafeRight( m_movementSpeed * deltaT );
			if (m_cameraMovement & CAMERA_STRAFE_LEFT)
				m_camera.strafeRight( -m_movementSpeed * deltaT );

			if (m_cameraMovement & CAMERA_UP)
				m_camera.moveUp( m_movementSpeed * deltaT);
			if (m_cameraMovement & CAMERA_DOWN)
				m_camera.moveUp( -m_movementSpeed * deltaT);

			if (m_cameraMovement & CAMERA_ROTATE_UP)
				m_camera.rotateUp( m_rotationSpeed * deltaT );
			if (m_cameraMovement & CAMERA_ROTATE_DOWN)
				m_camera.rotateUp( -m_rotationSpeed * deltaT );

			if (m_cameraMovement & CAMERA_ROTATE_LEFT)
				m_camera.rotateRight( m_rotationSpeed * deltaT );
			if (m_cameraMovement & CAMERA_ROTATE_RIGHT)
				m_camera.rotateRight( -m_rotationSpeed * deltaT );

			if (m_cameraMovement & CAMERA_SPIN_LEFT)
				m_camera.spinCamera( m_rotationSpeed * deltaT );
			if (m_cameraMovement & CAMERA_SPIN_RIGHT)
				m_camera.spinCamera( -m_rotationSpeed * deltaT );

			m_cameraChanged = true;
			m_lastCamMoveTime = currTime;
		}


	}
	gml::mat3x3_t rotateMat = gml::rotateAxis(0.01f, gml::vec3_t(0.0,1.0,0.0));
	m_scene.setLightPos(gml::mul(rotateMat,gml::extract3(m_scene.getLightPos())));
	Object::Object **o = m_scene.getObjects();
/*	gml::mat4x4_t b;	
	gml::vec4_t t = gml::mul(o[1]->getObjectToWorld(),gml::vec4_t(0.0,0.0,0.0,1.0));
	if(flag)
	{
		b = gml::mul(gml::translate(gml::vec3_t(0.0,0.01,0.0)),o[1]->getObjectToWorld());
		if(t.y > 2.0)
			flag = false;
	}else
	{
		b = gml::mul(gml::translate(gml::vec3_t(0.0,-0.01,0.0)),o[1]->getObjectToWorld());
		if(t.y < 0.5)
			flag = true;
	}
	o[1]->setTransform(b);
*/

	for(int i=4; i<m_nGeometry;i++)
	{
		o[i]->setTransform(getObjectPosition(o[i]));
	}
	
	m_lastIdleTime = currTime;
}
Esempio n. 29
0
	VC3 UnifiedHandleManager::getObjectCenterPosition(UnifiedHandle uh) const
	{
		// TODO
		//assert(!"UnifiedHandleManager::getObjectCenterPosition - TODO.");
		return getObjectPosition(uh);
	}