Ejemplo n.º 1
0
void Camera::rotateView(float x, float y)
{	
	float thetaX = -y*right.x + x*up.x;
	float thetaY = -y*right.y + x*up.y;
	float thetaZ = -y*right.z + x*up.z;

	if(cameraMode == FREEROAM_CAMERA)
	{
		vec3 newDir = vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY) * vec4(dir, 1));
		changeDir(newDir);
	}
	else if(cameraMode == MODELVIEWER_CAMERA)
	{
		pos =  vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY) * vec4(pos - viewCenter, 1)) + viewCenter;	//Rotate position around center

		float pos_length = length(pos-viewCenter);
		vec3 _dir = normalize(pos-viewCenter);

		/*if (abs(_dir.y) > maxY)
		{
			if (_dir.y < 0)
				_dir.y = -maxY;
			else
				_dir.y = maxY;

			float s = sqrt((1 - maxY*maxY) / (_dir.x*_dir.x + _dir.z*_dir.z));
			_dir.x *= s;
			_dir.z *= s;
			_dir = normalize(_dir);

			pos = viewCenter+_dir*pos_length;
		}*/

		if ((_dir.y > maxY) || (_dir.y < minY))
		{

			float s = 1.f;

			if (_dir.y > maxY)
			{
				_dir.y = maxY;
				s = sqrt((1 - maxY*maxY) / (_dir.x*_dir.x + _dir.z*_dir.z));
			}
			else if (_dir.y < minY)
			{
				_dir.y = minY;
				s = sqrt((1 - minY*minY) / (_dir.x*_dir.x + _dir.z*_dir.z));
			}

			dir.x *= s;
			_dir.z *= s;
			_dir = normalize(_dir);

			pos = viewCenter + _dir*pos_length;
		}

		changeDir(normalize(viewCenter-pos));
	}

}
Ejemplo n.º 2
0
void BenchmarkDemo::createTowerCircle(const btVector3& offsetPosition,int stackSize,int rotSize,const btVector3& boxSize)
{

	btBoxShape* blockShape = new btBoxShape(btVector3(boxSize[0]-COLLISION_RADIUS,boxSize[1]-COLLISION_RADIUS,boxSize[2]-COLLISION_RADIUS));

	btTransform trans;
	trans.setIdentity();

	float mass = 1.f;
	btVector3 localInertia(0,0,0);
	blockShape->calculateLocalInertia(mass,localInertia);


	float radius = 1.3f * rotSize * boxSize[0] / SIMD_PI;

	// create active boxes
	btQuaternion rotY(0,1,0,0);
	float posY = boxSize[1];

	for(int i=0;i<stackSize;i++) {
		for(int j=0;j<rotSize;j++) {
		

			trans.setOrigin(offsetPosition+  rotate(rotY,btVector3(0.0f , posY, radius)));
			trans.setRotation(rotY);
			localCreateRigidBody(mass,trans,blockShape);

			rotY *= btQuaternion(btVector3(0,1,0),SIMD_PI/(rotSize*btScalar(0.5)));
		}

		posY += boxSize[1] * 2.0f;
		rotY *= btQuaternion(btVector3(0,1,0),SIMD_PI/(float)rotSize);
	}
	
}
Ejemplo n.º 3
0
void OpekeTool::rotateY()
{
	int temp = sizeZ->value();
	sizeZ->setValue(sizeX->value());
	sizeX->setValue(temp);
	emit rotY();
}
Ejemplo n.º 4
0
void Camera::setYRotation(const float angle)
{
	float sourceRot[16], rotYMat[16];
	memcpy_s(sourceRot,sizeof(float) * 16,m_rotMatrix,sizeof(float) * 16);
	rotY( rad2deg(m_xMov),rotYMat);
	multMat(rotYMat, sourceRot, m_rotMatrix);
}
void PolymerizationProcess::initSphereDcm()
{
  double rot[9];
  double x(0);
  double y(0);
  double z(-theRadius);
  getSphereDcm(0, 0, theInitSphereDcm); //dcm is const because angle is const
  rotY(rot, -atan2(theMonomerLength*theInitSphereDcm[0],
                   theRadius-theMonomerLength*theInitSphereDcm[2]));
  rotate(rot,&x,&y,&z);
  double thetaY(-atan2(x,-z)+atan2((theMonomerLength-1)/2,theRadius));
  // makes dcm start at correct position (-5, 0, -79) so that the first
  // coord after that is (0, 0, -r) given x,y,z = (-5,0,-79)
  getOneDcm(rot);
  rotY(rot, thetaY);
  dcmXdcm(theInitSphereDcm, rot, theInitSphereDcm);
}
Ejemplo n.º 6
0
void Camera::rotateViewAround(float x, float y)
{
	float thetaX = -y*right.x + x*up.x;
	float thetaY = -y*right.y + x*up.y;
	float thetaZ = -y*right.z + x*up.z;

	pos =  vec3(rotZ(thetaZ)*rotX(thetaX)*rotY(thetaY)* vec4(pos - viewCenter, 1) )+ viewCenter;	//Rotate position around center

	changeDir(viewCenter-pos);
}
Ejemplo n.º 7
0
void OpekeTool::setupActions()
{
	connect (b_rotateX, SIGNAL(clicked()), this, SIGNAL(rotX()));
	connect (b_rotateY, SIGNAL(clicked()), this, SIGNAL(rotY()));
	connect (b_rotateZ, SIGNAL(clicked()), this, SIGNAL(rotZ()));
		
	connect ( color, SIGNAL ( highlighted ( QColor ) ), this, SIGNAL ( colorChanged( QColor ) ) );
	connect ( color, SIGNAL ( activated ( QColor ) ), this, SIGNAL ( colorViewed ( QColor ) ) );

	connect ( planeZ, SIGNAL ( valueChanged ( int ) ), this, SIGNAL ( planeChanged ( int ) ) );

	connect ( sizeX, SIGNAL ( valueChanged ( int ) ), this, SIGNAL ( sizeXChanged ( int ) ) );
	connect ( sizeY, SIGNAL ( valueChanged ( int ) ), this, SIGNAL ( sizeYChanged ( int ) ) );
	connect ( sizeZ, SIGNAL ( valueChanged ( int ) ), this, SIGNAL ( sizeZChanged ( int ) ) );
}
Ejemplo n.º 8
0
void SphereObject::transform()
{
	//Create transformation matrices
	Matrix scale(SCALE, xScale, yScale, zScale);

	Matrix rotX(ROT_X, xAngle * MATH_PI / 180.0f);

	Matrix rotY(ROT_Y, yAngle * MATH_PI / 180.0f);

	Matrix rotZ(ROT_Z, zAngle * MATH_PI / 180.0f);

	Matrix axisRot(IDENTITY);
	axisRot.set(ROT_AXIS_ANGLE, this -> rotAxis, this -> axisRotAngle * MATH_PI / 180.0f);

	Matrix orbitRot(IDENTITY);
	orbitRot.set(ROT_AXIS_ANGLE, this -> orbitAxis, this -> orbitAngle * MATH_PI / 180.0f);

	Matrix trans( TRANS, this -> startPos[x] + this -> xTrans, this -> startPos[y] + this -> yTrans, this -> startPos[z] + this -> zTrans );

	Matrix orbitTrans(TRANS, this -> xOrbitTrans, this -> yOrbitTrans, this -> zOrbitTrans );

	//Create the normal matrix
	this -> normal = rotX * rotY * rotZ * axisRot * (orbitTrans * orbitRot);

	//Create the local to world matrix (ie Model)
	this -> world = scale * rotX * rotY * rotZ * axisRot * (orbitTrans * orbitRot) * trans;

	// Create the ModelView ( LocalToWorld * View)
	// Some pipelines have the project concatenated, others don't
	// Best to keep the separated, you can always join them with a quick multiply
	CameraManager* cm = CameraManager::getInstance();

	this -> modelView = this -> world * cm -> getCam1() -> getViewMatrix();

	//Since we are using the supplied flat shader we need to send it the
	//combined modelView and Projection Matrices
	this -> modelViewProj = this -> modelView * cm -> getCam1() -> getProjMatrix();

	//Transform the lighting position
	this -> transformedLightPos = this -> lightPos;// * cm -> getCam1() -> getViewMatrix();  Looks like I do not need this for now
	
}
Ejemplo n.º 9
0
bool Skeleton::setBoneRotationsAngles(const unsigned int& idx, const vec3& angles)
{
	if(idx >= mBones.size())
	{
		return false;
	}
	
	// rotation around x
	anax rotX(angles.x(), vec3::UnitX());	// pitch
	anax rotY(angles.y(), vec3::UnitY());	// yaw
	anax rotZ(angles.z(), vec3::UnitZ());	// roll
	quat q = rotX * rotY * rotZ;
	mBones[idx].R = q.matrix();

	std::vector<REAL> len;
	getBoneLengths(len);
	fitToBoneLengths(len);
	
	return true;
}
Ejemplo n.º 10
0
void Camera::trackDirAroundY(vec3 _dir, float timeStep)
{
	vec3 flatDir = normalize(vec3(dir.x, 0.f, dir.z));
	vec3 flat_Dir = normalize(vec3(_dir.x, 0.f, _dir.z));


	float angleDiff = acos(dot(flatDir, flat_Dir));

	if (angleDiff < 0.01f)
		return;

	float sign = 1.f;

	if (dot(right, _dir) >= 0)
		sign = -1.f;

	float adjustedSpeed = trackingSpeed*timeStep*trackingSpeedFunc(angleDiff);

	pos = vec3(rotY(sign*min(angleDiff, adjustedSpeed))*vec4(pos - viewCenter, 1.f))+viewCenter;
	changeDir(viewCenter - pos);

}
Ejemplo n.º 11
0
    mat3<float> rotationMat3(float a, vec3<float> axis)
    {
        a *= DEGTORAD;
        double cosAx = cos(a * axis.x);
        double sinAx = sin(a * axis.x);
        double cosAy = cos(a * axis.y);
        double sinAy = sin(a * axis.y);
        double cosAz = cos(a * axis.z);
        double sinAz = sin(a * axis.z);

        mat3<float> rotX(1,     0,     0,
                         0, cosAx,-sinAx,
                         0, sinAx, cosAx);

        mat3<float> rotY(cosAy, 0, sinAy,
                         0,     1,     0,
                        -sinAy, 0, cosAy);

        mat3<float> rotZ(cosAz,-sinAz,  0,
                         sinAz, cosAz,  0,
                         0,     0,      1);

        return rotX * rotY * rotZ;
    }
Ejemplo n.º 12
0
void CTwisterDialog::UpdateRotation(CString & strResult)
{
	bool error = FALSE;
	double x, y, z;
	x=y=z=0;
	x = atof(m_strX);
	y = atof(m_strY);
	z = atof(m_strZ);
	if(!m_bRadians) {
		x *= V_DEGTORAD;
		y *= V_DEGTORAD;
		z *= V_DEGTORAD;
	}
	CAxisRotation rotX(1, 0, 0, x);
	CAxisRotation rotY(0, 1, 0, y);
	CAxisRotation rotZ(0, 0, 1, z);
	CQuaternion quatX(rotX);
	CQuaternion quatY(rotY);
	CQuaternion quatZ(rotZ);
	CQuaternion quatResult = quatZ * quatY * quatX;
	CAxisRotation rotResult(quatResult);
	strResult = rotResult.ToString(2);
	return;
}
Ejemplo n.º 13
0
void Opeke::setupActions()
{
    KStandardAction::openNew ( this, SLOT ( fileNew() ), actionCollection() );
    KStandardAction::quit ( qApp, SLOT ( quit() ), actionCollection() );
    KStandardAction::save ( this, SLOT ( saveFile() ), actionCollection() );
    KStandardAction::open ( this, SLOT ( openFile() ), actionCollection() );
    KStandardAction::saveAs ( this, SLOT ( saveFileAs() ), actionCollection() );

    KStandardAction::preferences ( this, SLOT ( optionsPreferences() ), actionCollection() );
    undoAct = KStandardAction::undo (m_view, SLOT(undo()), actionCollection() );
    redoAct = KStandardAction::redo (m_view, SLOT(redo()), actionCollection() );

    removeAct = KStandardAction::cut (m_view, SLOT(delBrick()), actionCollection());
    removeAct->setShortcut(QKeySequence(Qt::Key_Delete));
    removeAct->setText( i18n ("Delete"));
    removeAct->setEnabled(false);

    // The action to start building Bricks in OGRE
    KAction *build = new KAction ( KIcon ( "build" ), i18n ( "Build" ), this );
    build->setShortcut(QKeySequence(Qt::Key_B));
    actionCollection()->addAction ( QLatin1String ( "build_action" ), build );
    connect ( build, SIGNAL ( triggered ( bool ) ), m_view, SLOT ( setBuildMode() ) );

    // Start select mode
    KAction *select = new KAction ( KIcon ( "select" ), i18n ( "S&elect" ), this );
    select->setShortcut(QKeySequence(Qt::Key_E));
    actionCollection()->addAction ( QLatin1String ( "select_action" ), select );
    connect ( select, SIGNAL ( triggered ( bool ) ), m_view, SLOT ( setSelectMode() ) );

    // Enable or disable grid
    KAction *grid = new KAction (KIcon ( "grid" ), i18n ("Toggle &Grid"), this);
    grid->setShortcut(QKeySequence(Qt::Key_G));
    actionCollection()->addAction(QLatin1String("grid_action"), grid);
    connect (grid, SIGNAL (triggered (bool)), m_view, SLOT (flipGridEnabled() ));

    // Actions to choose what kind of Brick to build
    KAction *block = new KAction (KIcon ( "block" ), i18n ("Build B&lock"), this);
    block->setShortcut(QKeySequence(Qt::Key_L));
    actionCollection()->addAction(QLatin1String("block_action"), block);
    connect (block, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeBlock() ));
    connect (block, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));

    KAction *roof = new KAction (KIcon ( "roof" ), i18n ("Build &Roof"), this);
    roof->setShortcut(QKeySequence(Qt::Key_R));
    actionCollection()->addAction(QLatin1String("roof_action"), roof);
    connect (roof, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeRoof()));
    connect (roof, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));


    KAction *cylinder = new KAction (KIcon ( "cylinder" ), i18n ("Build &Cylinder"), this);
    cylinder->setShortcut(QKeySequence(Qt::Key_C));
    actionCollection()->addAction(QLatin1String("cylinder_action"), cylinder);
    connect (cylinder, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeCylinder() ));
    connect (cylinder, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));

    KAction *invCyl = new KAction (KIcon ("invCyl"), i18n ("Build &Inverted Cylinder"), this);
    invCyl->setShortcut(QKeySequence(Qt::Key_I));
    actionCollection()->addAction(QLatin1String("invCyl_action"), invCyl);
    connect (invCyl, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeInvCyl() ));
    connect (invCyl, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));

    KAction *sphere = new KAction (KIcon ("sphere"), i18n ("Build &Sphere"), this);
    sphere->setShortcut(QKeySequence(Qt::Key_S));
    actionCollection()->addAction(QLatin1String("sphere_action"), sphere);
    connect (sphere, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeSphere() ));
    connect (sphere, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));

    KAction *cone = new KAction (KIcon ( "cone" ), i18n ("Build Co&ne"), this);
    cone->setShortcut(QKeySequence(Qt::Key_N));
    actionCollection()->addAction(QLatin1String("cone_action"), cone);
    connect (cone, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeCone() ));
    connect (cone, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));

    KAction *corner = new KAction (KIcon ( "corner" ), i18n ("Build Roof C&orner"), this);
    corner->setShortcut(QKeySequence(Qt::Key_O));
    actionCollection()->addAction(QLatin1String("corner_action"), corner);
    connect (corner, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeCorner() ));
    connect (corner, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));

    KAction *invrcor = new KAction (KIcon ( "invrcor" ), i18n ("Build In&verted Roof Corner"), this);
    invrcor->setShortcut(QKeySequence(Qt::Key_V));
    actionCollection()->addAction(QLatin1String("invrcor_action"), invrcor);
    connect (invrcor, SIGNAL (triggered (bool)), m_view, SLOT (changeTypeInvCorner() ));
    connect (invrcor, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));

    KAction *pyramid = new KAction (KIcon ( "pyramid" ), i18n ("Build &Pyramid"), this);
    pyramid->setShortcut(QKeySequence(Qt::Key_P));
    actionCollection()->addAction(QLatin1String("pyramid_action"), pyramid);
    connect (pyramid, SIGNAL (triggered (bool)), m_view, SLOT (changeTypePyramid() ));
    connect (pyramid, SIGNAL (triggered (bool)), m_view, SLOT (setBuildMode() ));

    KAction *snapshot = new KAction (KIcon ("ksnapshot"), i18n ("&Take Screenshot"), this);
    snapshot->setShortcut(QKeySequence("Ctrl+T"));
    actionCollection()->addAction(QLatin1String("snapshot_action"), snapshot);
    connect (snapshot, SIGNAL(triggered(bool)), this, SLOT (saveScreen()));

    // Reload the field after loading a new file
    connect ( this, SIGNAL ( reload() ), m_view, SLOT ( update() ) );
    connect ( this, SIGNAL ( clear() ), m_view, SLOT ( newScene() ) );

    connect ( m_tool, SIGNAL ( colorViewed ( QColor ) ), m_view, SLOT ( viewColor ( QColor ) ) );
    connect ( m_tool, SIGNAL ( colorChanged ( QColor ) ), m_view, SLOT ( setColor ( QColor ) ) );

    connect ( m_tool, SIGNAL ( planeChanged ( int ) ), m_view, SLOT ( setPlaneZ ( int ) ) );

    connect ( m_tool, SIGNAL ( sizeXChanged ( int ) ), m_view, SLOT ( setSizeX ( int ) ) );
    connect ( m_tool, SIGNAL ( sizeYChanged ( int ) ), m_view, SLOT ( setSizeY ( int ) ) );
    connect ( m_tool, SIGNAL ( sizeZChanged ( int ) ), m_view, SLOT ( setSizeZ ( int ) ) );
    connect ( m_view, SIGNAL(planeChanged(int)), m_tool, SLOT(changePlaneZ(int)));

    connect ( m_view, SIGNAL(undoEmpty(bool)), this, SLOT(undoEnable(bool)));
    connect ( m_view, SIGNAL(redoEmpty(bool)), this, SLOT(redoEnable(bool)));
    connect ( m_view, SIGNAL(delEnable(bool)), this, SLOT(removeEnable(bool)));
    connect ( m_view, SIGNAL(modified()), this, SLOT(fileModified()));

    connect (m_tool, SIGNAL(rotX()), m_view, SLOT(rotateX()));
    connect (m_tool, SIGNAL(rotY()), m_view, SLOT(rotateY()));
    connect (m_tool, SIGNAL(rotZ()), m_view, SLOT(rotateZ()));
}