Пример #1
0
void
display(void) {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();
#define RAD(x) (((x)*M_PI)/180.)
    gluLookAt(-sinf(RAD(rotx))*5.5,transy,cosf(RAD(rotx))*5.5, 0.,0.,0., 0.,1.,0.);

    glTranslatef(0.f, 0.f, transx*10.f);

    /* floor */
    glColor4f(0.f,.2f,0.f,1.f);
    glBegin(GL_POLYGON);
	glVertex3f(-4.0, -1.0, -4.0);
	glVertex3f( 4.0, -1.0, -4.0);
	glVertex3f( 4.0, -1.0,  4.0);
	glVertex3f(-4.0, -1.0,  4.0);
    glEnd();

    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);
    glColor3f(.1f,.1f,.1f);
    glPushMatrix();
    glTranslatef(-1.f, -1.+.2f, -1.5f);
    glScalef(.2f,.2f, .2f);
    logs();
    glDisable(GL_LIGHTING);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-1.f, -1.f+.2f, -1.5f);
    calcMatrix();
    draw_smoke(smoke);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-1.f, -.25f, -1.5f);
    calcMatrix();
    glScalef(1.f,1.f,1.);
    if (texture) {
	glBindTexture(GL_TEXTURE_2D, the_texture+1);
	glEnable(GL_TEXTURE_2D);
    }
    glColor4f(intensity, intensity, intensity, opacity);
    glRotatef(rot, 0., 0., 1.);
    glDepthMask(0);
    glBegin(GL_POLYGON);
	glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0);
	glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0);
	glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
	glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0);
    glEnd();
    glDepthMask(1);
    glPopMatrix();
    glDisable(GL_TEXTURE_2D);

    glutSwapBuffers();
}
Пример #2
0
void 
exploder(float x, float y, float z, float size, float intensity, float opacity, float delay, float scale)
{
    if (size - delay <= 0.f)
	return;

    /*
     * explosion 
     */
    glPushMatrix();
    calcMatrix();
    glTranslatef(x, y, z);
    glScalef((size - delay) * scale, (size - delay) * scale, 1.);
    if (texture)
	glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texnames[0]);
    glColor4f(intensity, intensity, intensity, opacity);
    glBegin(GL_POLYGON);
    glTexCoord2f(0.0, 0.0);
    glVertex2f(-1.0, -1.0);
    glTexCoord2f(1.0, 0.0);
    glVertex2f(1.0, -1.0);
    glTexCoord2f(1.0, 1.0);
    glVertex2f(1.0, 1.0);
    glTexCoord2f(0.0, 1.0);
    glVertex2f(-1.0, 1.0);
    glEnd();
    glPopMatrix();
}
Пример #3
0
Camera::Camera(float r, float theta, float phi, glm::vec3 cTarget, glm::vec3 cUP)
{
	//vMat = glm::lookAt(cPos, cTarget, cUP);
	R = r;
	Theta = theta;
	Phi = phi;
	target = cTarget;
	up = cUP;
	isOrbital = true;
	calcMatrix();
}
Пример #4
0
ActionBase::ResultE ReplicateTransform::renderEnter(Action *action)
{
    RenderAction *pAction = 
        dynamic_cast<RenderAction *>(action);

    calcMatrix(pAction->topMatrix());

    pAction->pushVisibility();

    pAction->pushMatrix(_invWorld);

    return Action::Continue;
}
Action::ResultE ScreenGroup::renderEnter(Action *action)
{
    RenderAction *pAction = dynamic_cast<RenderAction *>(action);

    Matrix mMat;

#if 0
    if(!pAction->getEffectsPass())
		calcMatrix(pAction, pAction->top_matrix(), mMat);
	else
		mMat = _camTransform;
#else
    calcMatrix(pAction, pAction->topMatrix(), mMat);
#endif

    pAction->pushMatrix(mMat);

// !!! can't use visibles, as ToWorld gives garbage leading to wrong culling
//    pAction->selectVisibles();

    return Action::Continue;
}
Action::ResultE InverseTransform::renderEnter(Action *action)
{
    RenderAction *pAction = 
        dynamic_cast<RenderAction *>(action);

    Matrix mMat;    // will be set to World^-1

    calcMatrix(pAction->topMatrix(), mMat);

    pAction->pushVisibility();

    pAction->pushMatrix(mMat);

    return Action::Continue;
}
bool AnalyzerObservableFermionMatrixSingleMFullRanSpectrumNoPreconditioning::analyze(AnalyzerPhiFieldConfiguration* phiFieldConf, Complex** auxVectors) {
  double* phiField = phiFieldConf->getPhiFieldCopy(); 
  ComplexMatrix calcMatrix(1);
  double Parameter_MassSplit = fermiOps->getMassSplitRatio();
  
  if (randomPhiField) {
    if (LogLevel > 1) printf("WARNING: Random Phi-Field!!!\n");
    phiFieldConf->randomizeGaussHiggsField(phiField); 
  }
  
  fermiOps->constructNeubergerWithXiFermionMatrix(calcMatrix, (vector4D*)phiField, Parameter_MassSplit);
  bool b = calcMatrix.calcEigenvalues();

  for (int I=0; I<calcMatrix.matrixSize; I++) {
    analyzerResults[2*I+0] = calcMatrix.eigenvalues[I].x;
    analyzerResults[2*I+1] = calcMatrix.eigenvalues[I].y;
  }
  
  return b;
}
Action::ResultE SkeletonBlendedGeometry::renderEnter(Action *action)
{
    RenderAction *pAction = 
        dynamic_cast<RenderAction *>(action);

    Matrix mMat;    // will be set to World^-1

    calcMatrix(pAction->topMatrix(), mMat);

    pAction->pushVisibility();

    pAction->pushMatrix(mMat);

    Action::ResultE Result(Inherited::renderEnter(action));
    if(Result != Action::Continue)
    {
        pAction->popVisibility();
        pAction->popMatrix();
    }
    return Result;
}
Пример #9
0
void CAnimation::updateMatrix() {
	if (jam == -1 || pBoneRoot == NULL) return;
	CXAnimationSet* a;
	float frame;
	if (pAnimData) {
		a = (*pAnimation)[0];
		frame = time + pAnimData[jam].start;
	}
	else {
		a = (*pAnimation)[jam];
		frame = time;
	}
	for (unsigned int i = 0; i < a->animations.size(); i++) {
		CFrameBone *b = (CFrameBone*)CXFrame::getFrameByName(a->animations[i]->boneName, pBoneRoot);
		if (b) {
			b->setMatrix(calcMatrix(*a->animations[i]->animationkey, frame));
			if (blend < 1.0f) b->calcBlendMatrix(blend);
		}

	}

	//	CXFrame::printMatrix(pBoneRoot);
}
Пример #10
0
 virtual void addRotZ(double val) {end.z += val/100;calcMatrix();};
Пример #11
0
 virtual void setRotZ(double val) {end.z = val/100;calcMatrix();};
Пример #12
0
 virtual void addPosZ(double val) {Camera::addPosZ(val);calcMatrix();};
Пример #13
0
 virtual void setPosZ(double val) {Camera::setPosZ(val);calcMatrix();};
Пример #14
0
void
display(void) 
{

    /*
     * save the viewing transform by saving a copy of the
     * modelview matrix at the right place, then undo the
     * rotation by calling calcMatrix() at the right time to
     * billboard the tree. Billboarding should only happen
     * if the billboard variable is not zero.
     */

    float mat[16];
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();
    gluLookAt(-sinf(RAD(rotx))*5.5,
	      transy,
	      cosf(RAD(rotx))*5.5,
	      0. ,0. ,0., 
	      0. ,1. ,0.);

    /* save the viewing tranform */
    glGetFloatv(GL_MODELVIEW_MATRIX, mat);

    /* change the brightness of the flame light */
    glLightfv(GL_LIGHT0, GL_DIFFUSE, &firelight[flames * 4]);

    /* ground */
    glDisable(GL_TEXTURE_2D);
    glCallList(GROUND);

    glPushMatrix();

    glTranslatef(0.f, 0.f, -transx);

    /* base of flame */
    glCallList(FLAME_BASE);

    /* undo the rotation in the viewing transform */
    if (billboard) 
	calcMatrix();

    /* flame polygon */
    
    /* 
     * position the flame light in the center of the flame polygon
     * turn off lighting, turn on texturing, bind the proper flame
     * texture, and draw the flame polygon.
     */

    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
    glDisable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, flames);
    glColor4f(1.f, 1.f, 1.f, 1.f);
    glBegin(GL_POLYGON);
	glTexCoord2f(0.0, 0.0);
	glVertex2f(-1.0, -1.0);
	glTexCoord2f(1.0, 0.0);
	glVertex2f(1.0, -1.0);
	glTexCoord2f(1.0, 1.0);
	glVertex2f(1.0, 1.0);
	glTexCoord2f(0.0, 1.0);
	glVertex2f(-1.0, 1.0);
    glEnd();
    glPopMatrix();

    /* turn lighting back on */
    glEnable(GL_LIGHTING);

    glutSwapBuffers();
}
Пример #15
0
void BoneActor::doIK(Vector3f loc, bool bAbsolute){

    /*********************************************************************************

        3 part process:

        1. gather all necessary numbers
        2. rotate the system into target plane (plane between target point and shoulder)
        3. do 2D IK

    *********************************************************************************/


    //leave if we don't have two parents
    if (!base || !base->base ){
        cout << "no double-base!!! Cannot do IK" << endl;
        Actor::setLocation(loc);
        return;
    }

    //for debug stuff
    f+=0.01;

    ///clear transform Matrices!

    Matrix4d initialTransform;

    initialTransform=base->base->transformMatrix;

    base->base->transformMatrix.identity();
    base->transformMatrix.identity();
    transformMatrix.identity();
    base->base->baseMatrix=calcMatrix(base->base);
    base->baseMatrix=calcMatrix(base);
    baseMatrix=calcMatrix(this);

    ///gathering numbers

    Vector3f currentUpperVec, currentLowerVec, initialUpperVec, initialLowerVec;

    MeshData* myMesh=renderer->vboList[parent->vboMeshID];
    //find original angles for non-aligned bones - from mesh data!
    for (int i=0;i<(int)myMesh->bones.size();i++){
        if (myMesh->bones[i]->name==base->name)
            initialUpperVec=myMesh->bones[i]->boneMatrix->getTranslation();
        if (myMesh->bones[i]->name==name)
            initialLowerVec=myMesh->bones[i]->boneMatrix->getTranslation();
    }

    float upperLength = initialUpperVec.length();
    float lowerLength = initialLowerVec.length();

    //initial Full - without any transformations
    //this is for the relative positions of the bones to each other
    Vector3f initialFull= initialUpperVec + initialLowerVec;
    //project upper on full vector to get upper Angle

    initialUpperVec.normalize();
    initialLowerVec.normalize();
    initialFull.normalize();

    Vector3f currentFull=base->base->baseMatrix.getTranslation() - baseMatrix.getTranslation();
    Vector3f targetFull=base->base->baseMatrix.getTranslation() - loc;

    float targetFullLength = targetFull.length();


    ///out of bounds!!!
    if (targetFullLength>=upperLength+lowerLength){
        cout << "IK on " << name << " is out of bounds!" << endl;
        cout << targetFullLength << endl;
        return;
    }

    currentFull.normalize();
    targetFull.normalize();

    ///rotating into IK plane
    Matrix4f parentMatrix=parent->baseMatrix;
    parentMatrix.setTranslation(Vector3f(0,0,0));

    Vector3f rotAxis = currentFull.crossProduct(targetFull);
    rotAxis=parentMatrix.inverse() * rotAxis;
    rotAxis.normalize();

    float rot= acos(currentFull.dotProduct(targetFull));

    //check if they're on each other!
    if (rot!=rot){
        cout << "already in plane!" << endl;
        rot=0.0;    //no rotation in that case!
    }
    Vector3f xA,yA,zA;
    yA=rotAxis;
    xA=currentFull;
    zA=yA.crossProduct(xA);

    zA.normalize();

    Matrix4f rotMatrix,angleMatrix;

    rotMatrix[0]=xA.x;
    rotMatrix[1]=xA.y;
    rotMatrix[2]=xA.z;

    rotMatrix[4]=yA.x;
    rotMatrix[5]=yA.y;
    rotMatrix[6]=yA.z;

    rotMatrix[8]=zA.x;
    rotMatrix[9]=zA.y;
    rotMatrix[10]=zA.z;


    angleMatrix=angleMatrix.createRotationAroundAxis(0,rot,0);

    rotMatrix=rotMatrix * angleMatrix * rotMatrix.inverse();

    //now rotate into IK plane
    base->base->transformMatrix=  base->base->transformMatrix * rotMatrix; //note: we can add the transformMatrix here, since rot should be 0 anyway after this!
    base->base->baseMatrix=calcMatrix(base->base);
    base->baseMatrix=calcMatrix(base);
    baseMatrix=calcMatrix(this);    //update all our matrices after transform!

    ///Math for 2D IK

    float upperAngle=0.0, middleAngle=0.0, lowerAngle=0.0;

    //using the following 2D stuff:

    //sine rule:
    // a/sinA = b/sinB = c/sinC

    //cosine rule:
    //c*c = b*b + a*a + 2ba*cosC

    //find biggest angle first
    if (upperLength>lowerLength){
        if (upperLength>targetFullLength){
            //upperLength = longest!
            lowerAngle=acos( (lowerLength*lowerLength + targetFullLength*targetFullLength - upperLength*upperLength) / (2* lowerLength * targetFullLength) );
            middleAngle=asin( targetFullLength  * sin(lowerAngle) / upperLength);
            upperAngle=asin( lowerLength  * sin(lowerAngle)/ upperLength);

        }else{
            //fullLength = longest!
            middleAngle=acos( (lowerLength*lowerLength + upperLength*upperLength - targetFullLength*targetFullLength) / (2* lowerLength * upperLength) );
            lowerAngle=asin( upperLength  * sin(middleAngle) / targetFullLength);
            upperAngle=asin( lowerLength  * sin(middleAngle) / targetFullLength);
        }
    }else if (lowerLength > targetFullLength){
            //lowerLength = longest!
            upperAngle=acos( ( targetFullLength*targetFullLength + upperLength*upperLength - lowerLength*lowerLength) / (2* upperLength * targetFullLength) );
            middleAngle=asin( targetFullLength  * sin(lowerAngle) / lowerLength);
            lowerAngle=asin( upperLength  * sin(lowerAngle) / lowerLength);
        }
    else{
        //fullLength = longest!
        middleAngle=acos( (lowerLength*lowerLength + upperLength*upperLength - targetFullLength*targetFullLength)/(2* lowerLength * upperLength) );
        lowerAngle=asin( upperLength  * sin(middleAngle) / targetFullLength);
        upperAngle=asin( lowerLength  * sin(middleAngle) / targetFullLength);
    }

    //phew!!!
    //middle rotation
    //NaN test!
    if (middleAngle!=middleAngle)
        middleAngle=0.0;

    //test NaN
    if (upperAngle!=upperAngle)
        upperAngle=0.0;

    ///gather current Info
    currentUpperVec=base->base->baseMatrix.getTranslation() - base->baseMatrix.getTranslation();
    currentUpperVec.normalize();

    currentLowerVec=base->baseMatrix.getTranslation() - baseMatrix.getTranslation();
    currentLowerVec.normalize();

    //origUpperAngle is the current 2D rotation!
    float currentUpperAngle=acos(targetFull.dotProduct(currentUpperVec));
    //check for NaN
    if (currentUpperAngle!=currentUpperAngle)
        currentUpperAngle=0.0;

    //project upper on lower Vector to get middle Angle
    float currentMiddleAngle=acos(currentLowerVec.dotProduct(currentUpperVec));
    //check for NaN
    if (currentMiddleAngle!=currentMiddleAngle)
        currentMiddleAngle=0.0;


    //add original values!
    upperAngle= upperAngle - currentUpperAngle;
    middleAngle= M_PI + middleAngle + currentMiddleAngle;// -;


    ///rotate 2D IK
    Vector3f initialRotYAxis,initialRotZAxis, initialRotXAxis;

    //now find our rotation Axis for 2D IK!
    if (currentUpperAngle==0.0){
        initialRotYAxis=Vector3f(0,1,0);
        initialRotZAxis=Vector3f(0,0,1);
        initialRotXAxis=Vector3f(1,0,0);
    }else{
        initialRotYAxis=initialFull.crossProduct(initialUpperVec);
        initialRotYAxis=initialUpperVec.crossProduct(initialFull);
        initialRotYAxis.normalize();
        initialRotXAxis=initialUpperVec;
        initialRotZAxis=initialRotXAxis.crossProduct(initialRotYAxis);
        initialRotZAxis.normalize();
    }

    xA=initialRotXAxis;
    yA=initialRotYAxis;
    zA=initialRotZAxis;

    Matrix4d initialRotMatrix;
    initialRotMatrix[0]=xA.x;
    initialRotMatrix[1]=xA.y;
    initialRotMatrix[2]=xA.z;

    initialRotMatrix[4]=yA.x;
    initialRotMatrix[5]=yA.y;
    initialRotMatrix[6]=yA.z;

    initialRotMatrix[8]=zA.x;
    initialRotMatrix[9]=zA.y;
    initialRotMatrix[10]=zA.z;


    //create a rotation matrix that applies the rotations to the x-Axis
    Matrix4f midMatrix,upMatrix;

    midMatrix=midMatrix.createRotationAroundAxis(0,middleAngle,0);
    upMatrix=upMatrix.createRotationAroundAxis(0,upperAngle,0);


    //rotate around arbitrary axis by rotating to the axis, then rotating your desired rotation, then rotating back
    midMatrix=  initialRotMatrix * midMatrix * initialRotMatrix.inverse();
    upMatrix=   initialRotMatrix * upMatrix  * initialRotMatrix.inverse();

    //rotate around first angle first
    base->base->transformMatrix=  base->base->transformMatrix * upMatrix;
    base->transformMatrix= base->transformMatrix * midMatrix;

    ///update matrices
    base->base->baseMatrix=calcMatrix(base->base);
    base->baseMatrix=calcMatrix(base);
    baseMatrix=calcMatrix(this);

}