예제 #1
0
//
// update - gets latest data from sensors if it is time to read them again
//
void Sensors::update() {
  
  // gps
  gps->update();

  // barometer
  float temp, pressure;
  if (barometer->readRawValues(&temp, &pressure)) {
    // calculate altitude
    sensorData.pressAltitude = 44330 * (1.0 - pow(pressure / PRESSURE_SEA_LEVEL, 0.1903));
  }
    
  // mag/accel/gyro
  float gyroValues[3], accelValues[3], magValues[3];
  if (mag->readRawValues(magValues) && accel->readRawValues(accelValues) && gyro->readRawValues(gyroValues)) {
    for (int i = 0; i++; i < 3) {
      sensorData.gyro_b[i] = gyroValues[i];  
    }
    
    updateRotationMatrix(gyroValues, accelValues, magValues);
    eulerAngles();
  }

  // airspeed
  float airspeedBody[3] = {singleWire->readAirspeed(), 0, 0};
  sensorData.airspeedRaw = airspeedBody[0];
  matrixRotate(airspeedBody, sensorData.airspeed_e); 
}
예제 #2
0
void
applyScreenTransform (CompScreen	      *screen,
		      const ScreenPaintAttrib *sAttrib,
		      CompOutput	      *output,
		      CompTransform	      *transform)
{
    matrixTranslate (transform,
		     sAttrib->xTranslate,
		     sAttrib->yTranslate,
		     sAttrib->zTranslate + sAttrib->zCamera);
    matrixRotate (transform,
		  sAttrib->xRotate, 0.0f, 1.0f, 0.0f);
    matrixRotate (transform,
		  sAttrib->vRotate,
		  cosf (sAttrib->xRotate * DEG2RAD),
		  0.0f,
		  sinf (sAttrib->xRotate * DEG2RAD));
    matrixRotate (transform,
		  sAttrib->yRotate, 0.0f, 1.0f, 0.0f);
}
예제 #3
0
파일: glide.c 프로젝트: Elive/ecomp
static void
applyGlideTransform(CompWindow *w, CompTransform *transform)
{
   ANIM_SCREEN(w->screen);
   ANIM_WINDOW(w);

   float finalDistFac;
   float finalRotAng;
   float thickness;

   fxGlideGetParams(as, aw, &finalDistFac, &finalRotAng, &thickness);

   float forwardProgress;
   if (fxGlideZoomToTaskBar(as, aw))
     {
        float dummy;
        fxZoomAnimProgress(as, aw, &forwardProgress, &dummy, TRUE);
     }
   else
     forwardProgress = fxGlideAnimProgress(aw);

   float finalz = finalDistFac * 0.8 * DEFAULT_Z_CAMERA *
     w->screen->width;

   Vector3d rotAxis = {1, 0, 0};
   Point3d rotAxisOffset =
   {WIN_X(w) + WIN_W(w) / 2.0f,
    WIN_Y(w) + WIN_H(w) / 2.0f,
    0};
   Point3d translation = {0, 0, finalz * forwardProgress};

   float rotAngle = finalRotAng * forwardProgress;
   aw->glideModRotAngle = fmodf(rotAngle + 720, 360.0f);

   // put back to window position
   matrixTranslate (transform, rotAxisOffset.x, rotAxisOffset.y, 0);

   resetAndPerspectiveDistortOnZ (transform, -1.0 / w->screen->width);

   // animation movement
   matrixTranslate (transform, translation.x, translation.y, translation.z);

   // animation rotation
   matrixRotate (transform, rotAngle, rotAxis.x, rotAxis.y, rotAxis.z);

   // intentional scaling of z by 0 to prevent weird opacity results and
   // flashing that happen when z coords are between 0 and 1 (bug in ecomp?)
   matrixScale (transform, 1.0f, 1.0f, 0.0f);

   // place window rotation axis at origin
   matrixTranslate (transform, -rotAxisOffset.x, -rotAxisOffset.y, 0);
}
예제 #4
0
void fist(float wristangle){
	matrixPush(ModelView);
	matrixRotate(ModelView, wristangle, 0, 0, 1);

	matrixPush(ModelView);
	matrixScale(ModelView, .5, .5, 1);
	joint();
	matrixPop(ModelView);
	
	hand();

	matrixPop(ModelView);
}
예제 #5
0
void display(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_POLYGON_OFFSET_FILL);
    glLineWidth(1.0);
    glPolygonMode(GL_FRONT, GL_LINE);
    matrixPush(ModelView);
    matrixRotate(ModelView,center,0,0,1);
    ellipsoidWireFrame();
    matrixPop(ModelView);
    glutSwapBuffers();
}
예제 #6
0
void feet(float footangle){
	matrixPush(ModelView);
	matrixRotate(ModelView, footangle, 0, 0, 1);
	
	matrixPush(ModelView);
	matrixScale(ModelView, .9, .9, 1);
	joint();
	matrixPop(ModelView);

	matrixPush(ModelView);
	matrixScale(ModelView, -1, 1, 1);
	foot();
	matrixPop(ModelView);

	matrixPop(ModelView);
}
예제 #7
0
void leg(float upperlegangle, float lowerlegangle, float footangle){
	matrixPush(ModelView);
	matrixRotate(ModelView, upperlegangle, 0, 0, 1);

	joint();

	matrixPush(ModelView);
	matrixScale(ModelView, 2, 1, 1);
	arm_segment();
	matrixPop(ModelView);


	matrixTranslate(ModelView, 0, -6, 0);
	lower_leg(lowerlegangle, footangle);	

	matrixPop(ModelView);
}
예제 #8
0
void lower_leg(float lowerlegangle, float footangle){
	matrixPush(ModelView);
	matrixRotate(ModelView, lowerlegangle, 0, 0, 1);

	matrixPush(ModelView);
	matrixScale(ModelView, .9, .9, 1);
	joint();
	matrixPop(ModelView);

	matrixPush(ModelView);
	matrixScale(ModelView, 1.8, .8 , 1);
	arm_segment();
	matrixPop(ModelView);

	matrixTranslate(ModelView, 0, -4.8, 0);
	feet(footangle);

	matrixPop(ModelView);
}
예제 #9
0
void arm(float upperarmangle, float lowerarmangle, float wristangle){
	matrixPush(ModelView);
	matrixRotate(ModelView, upperarmangle, 0, 0, 1);

	matrixPush(ModelView);
	matrixScale(ModelView, .625, .625, 1);
	joint();
	matrixPop(ModelView);

	matrixPush(ModelView);
	matrixScale(ModelView, 1.25, 1, 1);
	arm_segment();
	matrixPop(ModelView);

	matrixTranslate(ModelView, 0, -6, 0);
	forearm(lowerarmangle, wristangle);
	
	matrixPop(ModelView);
}
예제 #10
0
void forearm(float lowerarmangle, float wristangle){
	matrixPush(ModelView);
	matrixRotate(ModelView, lowerarmangle, 0, 0, 1);
	
	matrixPush(ModelView);
	matrixScale(ModelView, .5, .5, 1);
	joint();
	matrixPop(ModelView);

	arm_segment();

	matrixPush(ModelView);
	matrixTranslate(ModelView, 0, -6, 0);
	fist(wristangle);
	matrixPop(ModelView);
	

	matrixPop(ModelView);
}
예제 #11
0
void 
GltInterpolatorRotation::draw() const
{
	if (_active && _duration!=0.0 && _axis!=Vector0)
	{
		const double t = _timer.elapsed();

		_matrix *=
			matrixTranslate(_center) *
			matrixRotate(_axis,t/_duration*360.0) *
			matrixTranslate(-_center);

		((GltInterpolatorRotation *) this)->_timer.start();

		// Cast away the const to stop

		if (t>_duration && !_loop)
			((GltInterpolatorRotation *) this)->stop();
	}
}
예제 #12
0
void robot(){
	matrixPush(ModelView);
	matrixRotate(ModelView, torso_angle, 0, 0, 1);
	torso();

	matrixPush(ModelView);
	matrixTranslate(ModelView, 0, 10.2, 0);
	matrixRotate(ModelView, head_angle, 0, 0, 1);
	head();
	matrixPush(ModelView);
	matrixTranslate(ModelView, .5, 2.5, 0);
	eye();
	matrixPop(ModelView);
	matrixPop(ModelView);

	matrixPush(ModelView);
	matrixTranslate(ModelView, -4.5, 7, 0);
	matrixRotate(ModelView, -45, 0, 0, 1);
	arm(left_upper_arm_angle, left_lower_arm_angle, left_wrist_angle);
	matrixPop(ModelView);

	matrixPush(ModelView);
	matrixTranslate(ModelView, 4.5, 7, 0);
	matrixRotate(ModelView, 45, 0, 0, 1);
	arm(right_upper_arm_angle, right_lower_arm_angle, right_wrist_angle);
	matrixPop(ModelView);

	matrixPush(ModelView);
	lower_torso();
	matrixPop(ModelView);

	matrixPush(ModelView);
	matrixTranslate(ModelView, -2, -1.5, 0);
	matrixRotate(ModelView, -30, 0, 0, 1);
	leg(left_upper_leg_angle, left_lower_leg_angle, left_foot_angle);
	matrixPop(ModelView);

	matrixPush(ModelView);
	matrixTranslate(ModelView, 2, -1.5, 0);
	matrixRotate(ModelView, 30, 0, 0, 1);
	right_leg(right_upper_leg_angle, right_lower_leg_angle, right_foot_angle);
	matrixPop(ModelView);

	matrixPop(ModelView);
}
예제 #13
0
파일: point.cpp 프로젝트: play113/swer
void Point::zRotate(double theta) {
    matrixRotate(cos(theta), -sin(theta) , 0 ,
                 sin(theta), cos(theta), 0,
                 0, 0, 1  );
}
/* window painting function, draws animation */
static Bool
tilePaintWindow(CompWindow              *w,
		const WindowPaintAttrib *attrib,
		const CompTransform     *transform,
		Region                  region,
		unsigned int            mask)
{
    CompScreen *s = w->screen;
    Bool status;
    Bool dontDraw = FALSE;

    TILE_WINDOW (w);
    TILE_SCREEN (s);

    if (tw->animationType != NoAnimation)
    {
	WindowPaintAttrib wAttrib = *attrib;
	CompTransform     wTransform = *transform;
	float             progress;

	progress = (float)ts->msResizing /
	           (float)tileGetAnimationDuration (s->display);

	switch (tileGetAnimateType (s->display))
	{
	    /*
	       Drop animation
	       */
	    case AnimateTypeDropFromTop:
		matrixRotate (&wTransform,
			      (progress * 100.0f) - 100.0f,
			      0.0f, 0.0f, 1.0f);
		mask |= PAINT_WINDOW_TRANSFORMED_MASK;
		break;

	    /*
	       Zoom animation
	       */
	    case AnimateTypeZoom:
		matrixTranslate (&wTransform, 0, 0, progress - 1.0f);
		mask |= PAINT_WINDOW_TRANSFORMED_MASK;
		break;

	    /*
	       Slide animation
	       */
	    case AnimateTypeSlide:
		if (progress < 0.75f)
		    wAttrib.opacity /= 2;
		else
		    wAttrib.opacity *= (0.5f + 2 * (progress - 0.75f));

		if (ts->msResizing > tw->animationNum * ts->oneDuration)
		{
		    /* animation finished */
		    tw->animationType = AnimationDone;
		}
		else if (ts->msResizing > (tw->animationNum - 1) *
			 ts->oneDuration)
		{
		    int thisDur; /* ms spent animating this window */
		    thisDur = ts->msResizing % ts->oneDuration;

		    if (tw->animationNum % 2)
			matrixTranslate (&wTransform,
					 s->width - s->width *
					 (float)thisDur / ts->oneDuration,
					 0, 0);
		    else
			matrixTranslate (&wTransform,
					 -s->width + s->width *
					 (float)thisDur / ts->oneDuration,
					 0, 0);

		    mask |= PAINT_WINDOW_TRANSFORMED_MASK;
		}
		else
		    dontDraw = TRUE;
		break;
	    /*
	       Outline animation
	       */
	    case AnimateTypeFilledOutline:
		dontDraw = TRUE;
		break;

	    /*
	       Fade animation
	       */
	    case AnimateTypeFade:
		// first half of the animation, fade out
		if (progress < 0.4f)
		    wAttrib.opacity -= wAttrib.opacity * progress / 0.4f;
		else
		{
		    if (progress > 0.6f && tw->alreadyResized)
		    {
			// second half of animation, fade in
			wAttrib.opacity *= (progress - 0.6f) / 0.4f;
		    }
		    else
		    {
			if (tw->needConfigure)
			    tileSetNewWindowSize (w);
			dontDraw = TRUE;
		    }
		}
		break;

	    default:
		break;
	}

	if (dontDraw)
	    mask |= PAINT_WINDOW_NO_CORE_INSTANCE_MASK;

	UNWRAP (ts, s, paintWindow);
	status = (*s->paintWindow) (w, &wAttrib, &wTransform, region, mask);
	WRAP (ts, s, paintWindow, tilePaintWindow);
    }
    else // paint window as always
    {
	UNWRAP (ts, s, paintWindow);
	status = (*s->paintWindow) (w, attrib, transform, region, mask);
	WRAP (ts, s, paintWindow, tilePaintWindow);
    }

    return status;
}
예제 #15
0
파일: point.cpp 프로젝트: play113/swer
void Point::yRotate(double theta) {
    matrixRotate(cos(theta) , 0 , sin(theta) ,
                          0 , 1 , 0          ,
                 -sin(theta), 0 , cos(theta)  );
}
void
applyZoomTransform (CompWindow * w)
{
    ANIM_WINDOW(w);

    CompTransform *transform = &aw->com.transform;
    
    Point curCenter;
    Point curScale;
    Point winCenter;
    Point iconCenter;
    float rotateProgress;

    getZoomCenterScaleFull (w, &curCenter, &curScale,
			    &winCenter, &iconCenter, &rotateProgress);

    if (fxZoomGetSpringiness (w) == 0.0f &&
	(aw->com.curAnimEffect == AnimEffectZoom ||
	 aw->com.curAnimEffect == AnimEffectSidekick) &&
	(aw->com.curWindowEvent == WindowEventOpen ||
	 aw->com.curWindowEvent == WindowEventClose))
    {
	matrixTranslate (transform,
			 iconCenter.x, iconCenter.y, 0);
	matrixScale (transform, curScale.x, curScale.y, curScale.y);
	matrixTranslate (transform,
			 -iconCenter.x, -iconCenter.y, 0);

	if (aw->com.curAnimEffect == AnimEffectSidekick)
	{
	    matrixTranslate (transform, winCenter.x, winCenter.y, 0);
	    matrixRotate (transform, rotateProgress * 360 * aw->numZoomRotations,
			  0.0f, 0.0f, 1.0f);
	    matrixTranslate (transform, -winCenter.x, -winCenter.y, 0);
	}
    }
    else
    {
	matrixTranslate (transform, winCenter.x, winCenter.y, 0);
	float tx, ty;
	if (aw->com.curAnimEffect != AnimEffectZoom)
	{
	    // avoid parallelogram look
	    float maxScale = MAX(curScale.x, curScale.y);
	    matrixScale (transform, maxScale, maxScale, maxScale);
	    tx = (curCenter.x - winCenter.x) / maxScale;
	    ty = (curCenter.y - winCenter.y) / maxScale;
	}
	else
	{
	    matrixScale (transform, curScale.x, curScale.y, curScale.y);
	    tx = (curCenter.x - winCenter.x) / curScale.x;
	    ty = (curCenter.y - winCenter.y) / curScale.y;
	}
	matrixTranslate (transform, tx, ty, 0);
	if (aw->com.curAnimEffect == AnimEffectSidekick)
	{
	    matrixRotate (transform, rotateProgress * 360 * aw->numZoomRotations,
			  0.0f, 0.0f, 1.0f);
	}
	matrixTranslate (transform, -winCenter.x, -winCenter.y, 0);
    }
}
예제 #17
0
int main(int index)
{
    float mat1[16];

    float trans = Pos->translate;
    float rot = Pos->rotate;

    matrixLoadScale(mat1, 2.f, 2.f, 2.f);
    matrixTranslate(mat1, 0.f, 0.f, trans);
    matrixRotate(mat1, 90.f, 0.f, 0.f, 1.f);
    matrixRotate(mat1, rot, 1.f, 0.f, 0.f);
    vpLoadModelMatrix(mat1);

    // Draw the lighting effect in the strip and fill the Z buffer.
    drawSimpleMesh(NAMED_mesh);

    // Start of images.
    bindProgramStore(NAMED_PSImages);
    bindProgramFragment(NAMED_PFImages);
    bindProgramVertex(NAMED_PVImages);

    float focusPos = Pos->focus;
    int focusID = 0;
    int lastFocusID = loadI32(2, STATE_LAST_FOCUS);
    int imgCount = 13;

    if (trans > (-.3f)) {
        focusID = -1.0f - focusPos;
        if (focusID >= imgCount) {
            focusID = -1;
        }
    } else {
        focusID = -1;
    }

    /*
    if (focusID != lastFocusID) {
        if (lastFocusID >= 0) {
            uploadToTexture(con, env->tex[lastFocusID], 1);
        }
        if (focusID >= 0) {
            uploadToTexture(con, env->tex[focusID], 0);
        }
    }
    */
    lastFocus = focusID;

    int triangleOffsetsCount = Pos->triangleOffsetCount;

    int imgId = 0;
    for (imgId=1; imgId <= imgCount; imgId++) {
        float pos = focusPos + imgId + 0.4f;
        int offset = (int)floorf(pos * 2.f);
        pos = pos - 0.75f;

        offset = offset + triangleOffsetsCount / 2;
        if (!((offset < 0) || (offset >= triangleOffsetsCount))) {
            int start = offset -2;
            int end = offset + 2;

            if (start < 0) {
                start = 0;
            }
            if (end >= triangleOffsetsCount) {
                end = triangleOffsetsCount-1;
            }

            bindTexture(NAMED_PFImages, 0, loadI32(0, imgId - 1));
            matrixLoadTranslate(mat1, -pos - loadF(5, triangleOffsetsCount / 2), 0, 0);
            vpLoadTextureMatrix(mat1);
            drawSimpleMeshRange(NAMED_mesh, loadI32(4, start), (loadI32(4, end) - loadI32(4, start)));
        }
    }
    return 0;
}
예제 #18
0
파일: z64viewer.c 프로젝트: wareya/gzrt
int _main(int argc, char *argv[])
{
  SDL_Surface *screen;
  int done;
  Uint8 *keys;
  int mousebutton,mouseX,mouseY;
  int grabbed=false;
  SDL_Init(SDL_INIT_VIDEO);

  screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL|SDL_RESIZABLE);
  if ( ! screen ) {
    fprintf(stderr, "Couldn't set 300x300 GL video mode: %s\n", SDL_GetError());
    SDL_Quit();
    exit(2);
  }
  SDL_WM_SetCaption("Z64Viewer", "z64viewer");
  SDL_ShowCursor(SDL_DISABLE);
  SDL_WM_GrabInput(SDL_GRAB_ON);
  grabbed=true;
  
  init(argc, argv);
  reshape(screen->w, screen->h);
  done = 0;
  while ( ! done ) {
    SDL_Event event;

    idle();
    while ( SDL_PollEvent(&event) ) {
      switch(event.type) {
        case SDL_VIDEORESIZE:
          screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 16,
                                    SDL_OPENGL|SDL_RESIZABLE);
          if ( screen ) {
            reshape(screen->w, screen->h);
          } else {
            printf("Problem...\n");
          }
          break;

        case SDL_QUIT:
          done = 1;
          break;
      }
    }
    keys = SDL_GetKeyState(NULL);

    if ( keys[SDLK_ESCAPE] ) {
      if(grabbed)
      {
          SDL_WM_GrabInput(SDL_GRAB_OFF);
          SDL_ShowCursor(SDL_ENABLE);
          grabbed=false;          
          waitTime(200); // Wait a bit so we don't exit by mistake
      }
      else
      {      
      done = 1;
      }
    }

    mousebutton=SDL_GetRelativeMouseState(&mouseX,&mouseY);
    
    GLfloat viewMatrix[16] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
    
    if(grabbed)
    {
        if((mousebutton&1) && (mousebutton&4))
        {
            matrixRotate(viewMatrix, mouseX/600.0f*360.0f, camera[0*4+0],camera[0*4+1],camera[0*4+2]);
            
            multM4Vect(&camera[0*4], viewMatrix, &camera[0*4]);
            multM4Vect(&camera[1*4], viewMatrix, &camera[1*4]);
            multM4Vect(&camera[2*4], viewMatrix, &camera[2*4]);
        }
        else
        {
            matrixRotate(viewMatrix, -mouseX/600.0f*360.0f, camera[2*4+0], camera[2*4+1],camera[2*4+2]);
            matrixRotate(viewMatrix, -mouseY/600.0f*360.0f, camera[1*4+0], camera[1*4+1],camera[1*4+2]);
            
            multM4Vect(&camera[0*4], viewMatrix, &camera[0*4]);
            multM4Vect(&camera[1*4], viewMatrix, &camera[1*4]);
        
            if(mousebutton&1)
            {
                camera[3*4+0]+=camera[0*4+0]*20;
                camera[3*4+1]+=camera[0*4+1]*20;
                camera[3*4+2]+=camera[0*4+2]*20;
                camera[3*4+3]+=camera[0*4+3]*20;
            }
    
          
            if(mousebutton&4)
            {
                camera[3*4+0]-=camera[0*4+0]*20;
                camera[3*4+1]-=camera[0*4+1]*20;
                camera[3*4+2]-=camera[0*4+2]*20;
                camera[3*4+3]-=camera[0*4+3]*20;
            }


            
            if(keys[SDLK_d])
            {
                camera[3*4+0]+=camera[1*4+0]*20;
                camera[3*4+1]+=camera[1*4+1]*20;
                camera[3*4+2]+=camera[1*4+2]*20;
                camera[3*4+3]+=camera[1*4+3]*20;
            }
            if(keys[SDLK_a])
            {
                camera[3*4+0]-=camera[1*4+0]*20;
                camera[3*4+1]-=camera[1*4+1]*20;
                camera[3*4+2]-=camera[1*4+2]*20;
                camera[3*4+3]-=camera[1*4+3]*20;
            }
            if(keys[SDLK_w])
            {
                camera[3*4+0]+=camera[2*4+0]*20;
                camera[3*4+1]+=camera[2*4+1]*20;
                camera[3*4+2]+=camera[2*4+2]*20;
                camera[3*4+3]+=camera[2*4+3]*20;
            }
            if(keys[SDLK_s])
            {
                camera[3*4+0]-=camera[2*4+0]*20;
                camera[3*4+1]-=camera[2*4+1]*20;
                camera[3*4+2]-=camera[2*4+2]*20;
                camera[3*4+3]-=camera[2*4+3]*20;
            }

//FASTER
            if(mousebutton&4 && mousebutton&2)
            {
                camera[3*4+0]-=camera[0*4+0]*200;
                camera[3*4+1]-=camera[0*4+1]*200;
                camera[3*4+2]-=camera[0*4+2]*200;
                camera[3*4+3]-=camera[0*4+3]*200;
            }
        if(mousebutton&1 && mousebutton&2)
            {
                camera[3*4+0]+=camera[0*4+0]*200;
                camera[3*4+1]+=camera[0*4+1]*200;
                camera[3*4+2]+=camera[0*4+2]*200;
                camera[3*4+3]+=camera[0*4+3]*200;
            }

            if(keys[SDLK_i])
            {
                camera[3*4+0]+=camera[2*4+0]*200;
                camera[3*4+1]+=camera[2*4+1]*200;
                camera[3*4+2]+=camera[2*4+2]*200;
                camera[3*4+3]+=camera[2*4+3]*200;
            }
        if(keys[SDLK_k])
            {
                camera[3*4+0]-=camera[2*4+0]*200;
                camera[3*4+1]-=camera[2*4+1]*200;
                camera[3*4+2]-=camera[2*4+2]*200;
                camera[3*4+3]-=camera[2*4+3]*200;
            }
        
            if(keys[SDLK_j])
            {
                camera[3*4+0]-=camera[1*4+0]*200;
                camera[3*4+1]-=camera[1*4+1]*200;
                camera[3*4+2]-=camera[1*4+2]*200;
                camera[3*4+3]-=camera[1*4+3]*200;
            }

            if(keys[SDLK_l])
            {
                camera[3*4+0]+=camera[1*4+0]*200;
                camera[3*4+1]+=camera[1*4+1]*200;
                camera[3*4+2]+=camera[1*4+2]*200;
                camera[3*4+3]+=camera[1*4+3]*200;
            }
//FASTER END 

        }            
    }
    else
    {
        if(mousebutton)
        {
            SDL_ShowCursor(SDL_DISABLE);
            SDL_WM_GrabInput(SDL_GRAB_ON);
            grabbed=true;
        }
    }    
    draw();
  }
  SDL_Quit();
  return 0;             /* ANSI C requires main to return int. */
}
예제 #19
0
파일: z64viewer.c 프로젝트: wareya/gzrt
void draw_from_data ( struct Data * k )
{
  SDL_Surface *screen;
  int done;
  Uint8 *keys;
  int mousebutton,mouseX,mouseY;
  int grabbed=false;
  SDL_Init(SDL_INIT_VIDEO);

  screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL|SDL_RESIZABLE);
  if ( ! screen ) {
    fprintf(stderr, "Couldn't set 300x300 GL video mode: %s\n", SDL_GetError());
    SDL_Quit();
    exit(2);
  }
  SDL_WM_SetCaption("Z64Viewer", "z64viewer");
  SDL_ShowCursor(SDL_DISABLE);
  SDL_WM_GrabInput(SDL_GRAB_ON);
  grabbed=true;
  
  
  GLenum err = glewInit();
  
  memset(databuffer,0, 8*1024*1024);
      
  entrypoint = k->ep;

  LoadResourceZ_bin(k->data, k->size, 0, 0);
  LoadResourceZ(
      "resources/gameplay_keep.zdata"
      
      , 1024*1024, 4);
  

    camera[0] = 1; camera[1]=0; camera[2]=0; camera[3]=0; // Forward
    camera[4] = 0; camera[5]=0; camera[6]=1; camera[7]=0; // Right
    camera[8] = 0; camera[9]=1; camera[10]=0; camera[11]=0; // Up
    camera[12] = -1000; camera[13]=0; camera[14]=0; camera[15]=0; // Position
  reshape(screen->w, screen->h);
  done = 0;
  while ( ! done ) {
    SDL_Event event;

    idle();
    while ( SDL_PollEvent(&event) ) {
      switch(event.type) {
        case SDL_VIDEORESIZE:
          screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 16,
                                    SDL_OPENGL|SDL_RESIZABLE);
          if ( screen ) {
            reshape(screen->w, screen->h);
          } else {
            printf("Problem...\n");
          }
          break;
      }
    }

    keys = SDL_GetKeyState(NULL);

    if ( keys[SDLK_ESCAPE] ) {
      if(grabbed)
      {
          SDL_WM_GrabInput(SDL_GRAB_OFF);
          SDL_ShowCursor(SDL_ENABLE);
          grabbed=false;          
          waitTime(200); // Wait a bit so we don't exit by mistake
      }
      else
      {      
      done = 1;
      }
    }

    mousebutton=SDL_GetRelativeMouseState(&mouseX,&mouseY);
    
    GLfloat viewMatrix[16] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
    
    if(grabbed)
    {
        if((mousebutton&1) && (mousebutton&4))
        {
            matrixRotate(viewMatrix, mouseX/600.0f*360.0f, camera[0*4+0],camera[0*4+1],camera[0*4+2]);
            
            multM4Vect(&camera[0*4], viewMatrix, &camera[0*4]);
            multM4Vect(&camera[1*4], viewMatrix, &camera[1*4]);
            multM4Vect(&camera[2*4], viewMatrix, &camera[2*4]);
        }
        else
        {
            matrixRotate(viewMatrix, -mouseX/600.0f*360.0f, camera[2*4+0], camera[2*4+1],camera[2*4+2]);
            matrixRotate(viewMatrix, -mouseY/600.0f*360.0f, camera[1*4+0], camera[1*4+1],camera[1*4+2]);
            
            multM4Vect(&camera[0*4], viewMatrix, &camera[0*4]);
            multM4Vect(&camera[1*4], viewMatrix, &camera[1*4]);
        
            if(mousebutton&1)
            {
                camera[3*4+0]+=camera[0*4+0]*20;
                camera[3*4+1]+=camera[0*4+1]*20;
                camera[3*4+2]+=camera[0*4+2]*20;
                camera[3*4+3]+=camera[0*4+3]*20;
            }
    
          
            if(mousebutton&4)
            {
                camera[3*4+0]-=camera[0*4+0]*20;
                camera[3*4+1]-=camera[0*4+1]*20;
                camera[3*4+2]-=camera[0*4+2]*20;
                camera[3*4+3]-=camera[0*4+3]*20;
            }


            
            if(keys[SDLK_d])
            {
                camera[3*4+0]+=camera[1*4+0]*20;
                camera[3*4+1]+=camera[1*4+1]*20;
                camera[3*4+2]+=camera[1*4+2]*20;
                camera[3*4+3]+=camera[1*4+3]*20;
            }
            if(keys[SDLK_a])
            {
                camera[3*4+0]-=camera[1*4+0]*20;
                camera[3*4+1]-=camera[1*4+1]*20;
                camera[3*4+2]-=camera[1*4+2]*20;
                camera[3*4+3]-=camera[1*4+3]*20;
            }
            if(keys[SDLK_w])
            {
                camera[3*4+0]+=camera[2*4+0]*20;
                camera[3*4+1]+=camera[2*4+1]*20;
                camera[3*4+2]+=camera[2*4+2]*20;
                camera[3*4+3]+=camera[2*4+3]*20;
            }
            if(keys[SDLK_s])
            {
                camera[3*4+0]-=camera[2*4+0]*20;
                camera[3*4+1]-=camera[2*4+1]*20;
                camera[3*4+2]-=camera[2*4+2]*20;
                camera[3*4+3]-=camera[2*4+3]*20;
            }

//FASTER
            if(mousebutton&4 && mousebutton&2)
            {
                camera[3*4+0]-=camera[0*4+0]*200;
                camera[3*4+1]-=camera[0*4+1]*200;
                camera[3*4+2]-=camera[0*4+2]*200;
                camera[3*4+3]-=camera[0*4+3]*200;
            }
        if(mousebutton&1 && mousebutton&2)
            {
                camera[3*4+0]+=camera[0*4+0]*200;
                camera[3*4+1]+=camera[0*4+1]*200;
                camera[3*4+2]+=camera[0*4+2]*200;
                camera[3*4+3]+=camera[0*4+3]*200;
            }

            if(keys[SDLK_i])
            {
                camera[3*4+0]+=camera[2*4+0]*200;
                camera[3*4+1]+=camera[2*4+1]*200;
                camera[3*4+2]+=camera[2*4+2]*200;
                camera[3*4+3]+=camera[2*4+3]*200;
            }
        if(keys[SDLK_k])
            {
                camera[3*4+0]-=camera[2*4+0]*200;
                camera[3*4+1]-=camera[2*4+1]*200;
                camera[3*4+2]-=camera[2*4+2]*200;
                camera[3*4+3]-=camera[2*4+3]*200;
            }
        
            if(keys[SDLK_j])
            {
                camera[3*4+0]-=camera[1*4+0]*200;
                camera[3*4+1]-=camera[1*4+1]*200;
                camera[3*4+2]-=camera[1*4+2]*200;
                camera[3*4+3]-=camera[1*4+3]*200;
            }

            if(keys[SDLK_l])
            {
                camera[3*4+0]+=camera[1*4+0]*200;
                camera[3*4+1]+=camera[1*4+1]*200;
                camera[3*4+2]+=camera[1*4+2]*200;
                camera[3*4+3]+=camera[1*4+3]*200;
            }
//FASTER END 

        }            
    }
    else
    {
        if(mousebutton)
        {
            SDL_ShowCursor(SDL_DISABLE);
            SDL_WM_GrabInput(SDL_GRAB_ON);
            grabbed=true;
        }
    }    
    draw();
    
    if(__quit)
        break;
  }
  SDL_Quit();
  __quited=1;
  return;             /* ANSI C requires main to return int. */
}
예제 #20
0
/*
 * groupPaintWindow
 *
 */
Bool
groupPaintWindow (CompWindow              *w,
                  const WindowPaintAttrib *attrib,
                  const CompTransform     *transform,
                  Region                  region,
                  unsigned int            mask)
{
	Bool status;
	Bool doRotate, doTabbing, showTabbar;
	CompScreen *s = w->screen;

	GROUP_SCREEN (s);
	GROUP_WINDOW (w);

	if (gw->group)
	{
		GroupSelection *group = gw->group;

		doRotate = (group->changeState != NoTabChange) &&
		           HAS_TOP_WIN (group) && HAS_PREV_TOP_WIN (group) &&
		           (IS_TOP_TAB (w, group) || IS_PREV_TOP_TAB (w, group));

		doTabbing = (gw->animateState & (IS_ANIMATED | FINISHED_ANIMATION)) &&
		            !(IS_TOP_TAB (w, group) &&
		              (group->tabbingState == Tabbing));

		showTabbar = group->tabBar && (group->tabBar->state != PaintOff) &&
		             (((IS_TOP_TAB (w, group)) &&
		               ((group->changeState == NoTabChange) ||
		                (group->changeState == TabChangeNewIn))) ||
		              (IS_PREV_TOP_TAB (w, group) &&
		               (group->changeState == TabChangeOldOut)));
	}
	else
	{
		doRotate   = FALSE;
		doTabbing  = FALSE;
		showTabbar = FALSE;
	}

	if (gw->windowHideInfo)
		mask |= PAINT_WINDOW_NO_CORE_INSTANCE_MASK;

	if (gw->inSelection || gw->resizeGeometry || doRotate ||
	    doTabbing || showTabbar)
	{
		WindowPaintAttrib wAttrib = *attrib;
		CompTransform wTransform = *transform;
		float animProgress = 0.0f;
		int drawnPosX = 0, drawnPosY = 0;

		if (gw->inSelection)
		{
			const BananaValue *
			option_select_opacity = bananaGetOption (bananaIndex,
			                                         "select_opacity",
			                                         s->screenNum);

			const BananaValue *
			option_select_saturation = bananaGetOption (bananaIndex,
			                                            "select_saturation",
			                                            s->screenNum);

			const BananaValue *
			option_select_brightness = bananaGetOption (bananaIndex,
			                                            "select_brightness",
			                                            s->screenNum);

			wAttrib.opacity    = OPAQUE * option_select_opacity->i / 100;
			wAttrib.saturation = COLOR * option_select_saturation->i / 100;
			wAttrib.brightness = BRIGHT * option_select_brightness->i / 100;
		}

		if (doTabbing)
		{
			/* fade the window out */
			float progress;
			int distanceX, distanceY;
			float origDistance, distance;

			if (gw->animateState & FINISHED_ANIMATION)
			{
				drawnPosX = gw->destination.x;
				drawnPosY = gw->destination.y;
			}
			else
			{
				drawnPosX = gw->orgPos.x + gw->tx;
				drawnPosY = gw->orgPos.y + gw->ty;
			}

			distanceX = drawnPosX - gw->destination.x;
			distanceY = drawnPosY - gw->destination.y;
			distance = sqrt (pow (distanceX, 2) + pow (distanceY, 2));

			distanceX = (gw->orgPos.x - gw->destination.x);
			distanceY = (gw->orgPos.y - gw->destination.y);
			origDistance = sqrt (pow (distanceX, 2) + pow (distanceY, 2));

			if (!distanceX && !distanceY)
				progress = 1.0f;
			else
				progress = 1.0f - (distance / origDistance);

			animProgress = progress;

			progress = MAX (progress, 0.0f);
			if (gw->group->tabbingState == Tabbing)
				progress = 1.0f - progress;

			wAttrib.opacity = (float)wAttrib.opacity * progress;
		}

		if (doRotate)
		{
			const BananaValue *
			option_change_animation_time = bananaGetOption (bananaIndex,
			                                          "change_animation_time",
			                                          s->screenNum);

			float timeLeft = gw->group->changeAnimationTime;
			int animTime = option_change_animation_time->f * 500;

			if (gw->group->changeState == TabChangeOldOut)
				timeLeft += animTime;

			/* 0 at the beginning, 1 at the end */
			animProgress = 1 - (timeLeft / (2 * animTime));
		}

		if (gw->resizeGeometry)
		{
			int xOrigin, yOrigin;
			float xScale, yScale;
			BoxRec box;

			groupGetStretchRectangle (w, &box, &xScale, &yScale);

			xOrigin = w->attrib.x - w->input.left;
			yOrigin = w->attrib.y - w->input.top;

			matrixTranslate (&wTransform, xOrigin, yOrigin, 0.0f);
			matrixScale (&wTransform, xScale, yScale, 1.0f);
			matrixTranslate (&wTransform,
			                 (gw->resizeGeometry->x - w->attrib.x) /
			                 xScale - xOrigin,
			                 (gw->resizeGeometry->y - w->attrib.y) /
			                 yScale - yOrigin,
			                 0.0f);

			mask |= PAINT_WINDOW_TRANSFORMED_MASK;
		}
		else if (doRotate || doTabbing)
		{
			float animWidth, animHeight;
			float animScaleX, animScaleY;
			CompWindow *morphBase, *morphTarget;

			if (doTabbing)
			{
				if (gw->group->tabbingState == Tabbing)
				{
					morphBase   = w;
					morphTarget = TOP_TAB (gw->group);
				}
				else
				{
					morphTarget = w;
					if (HAS_TOP_WIN (gw->group))
						morphBase = TOP_TAB (gw->group);
					else
						morphBase = gw->group->lastTopTab;
				}
			}
			else
			{
				morphBase   = PREV_TOP_TAB (gw->group);
				morphTarget = TOP_TAB (gw->group);
			}

			animWidth = (1 - animProgress) * WIN_REAL_WIDTH (morphBase) +
			            animProgress * WIN_REAL_WIDTH (morphTarget);
			animHeight = (1 - animProgress) * WIN_REAL_HEIGHT (morphBase) +
			             animProgress * WIN_REAL_HEIGHT (morphTarget);

			animWidth = MAX (1.0f, animWidth);
			animHeight = MAX (1.0f, animHeight);
			animScaleX = animWidth / WIN_REAL_WIDTH (w);
			animScaleY = animHeight / WIN_REAL_HEIGHT (w);

			if (doRotate)
				matrixScale (&wTransform, 1.0f, 1.0f, 1.0f / s->width);

			matrixTranslate (&wTransform,
			                 WIN_REAL_X (w) + WIN_REAL_WIDTH (w) / 2.0f,
			                 WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) / 2.0f,
			                 0.0f);

			if (doRotate)
			{
				float rotateAngle = animProgress * 180.0f;
				if (IS_TOP_TAB (w, gw->group))
					rotateAngle += 180.0f;

				if (gw->group->changeAnimationDirection < 0)
					rotateAngle *= -1.0f;

				matrixRotate (&wTransform, rotateAngle, 0.0f, 1.0f, 0.0f);
			}

			if (doTabbing)
				matrixTranslate (&wTransform,
				                 drawnPosX - WIN_X (w),
				                 drawnPosY - WIN_Y (w), 0.0f);

			matrixScale (&wTransform, animScaleX, animScaleY, 1.0f);

			matrixTranslate (&wTransform,
			                 -(WIN_REAL_X (w) + WIN_REAL_WIDTH (w) / 2.0f),
			                 -(WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) / 2.0f),
			                 0.0f);

			mask |= PAINT_WINDOW_TRANSFORMED_MASK;
		}

		UNWRAP (gs, s, paintWindow);
		status = (*s->paintWindow)(w, &wAttrib, &wTransform, region, mask);

		if (showTabbar)
			groupPaintTabBar (gw->group, &wAttrib, &wTransform, mask, region);

		WRAP (gs, s, paintWindow, groupPaintWindow);
	}
	else
	{
		UNWRAP (gs, s, paintWindow);
		status = (*s->paintWindow)(w, attrib, transform, region, mask);
		WRAP (gs, s, paintWindow, groupPaintWindow);
	}

	return status;
}
예제 #21
0
파일: point.cpp 프로젝트: play113/swer
void Point::xRotate(double theta) {
    matrixRotate(1, 0         , 0          ,
                 0, cos(theta), -sin(theta),
                 0, sin(theta), cos(theta)  );
}