コード例 #1
0
	void FringeTileEditor::UpdateScale()
	{
		if (Input::IsKeyPressed(KEY_X))
		{
			if (moveAxisLock == 1)
				moveAxisLock = 0;
			else
				moveAxisLock = 1;
		}
		else if (Input::IsKeyPressed(KEY_Y))
		{
			if (moveAxisLock == 2)
				moveAxisLock = 0;
			else
				moveAxisLock = 2;
		}

		Vector2 dir = (Input::GetWorldMousePosition() - moveStartPosition);
		float mag = fabs(dir.y);
		if (fabs(dir.x) > fabs(dir.y))
			mag = fabs(dir.x);

		Vector2 add = Vector2(SIGNOF(selectedEntity->scale.x), SIGNOF(selectedEntity->scale.y)) * mag;

		selectedEntity->scale = startScale + add * 0.01f;

		switch(moveAxisLock)
		{
		case 1:
			selectedEntity->scale.y = startScale.y;
			break;
		case 2:
			selectedEntity->scale.x = startScale.x;
			break;
		}
		
		if (Input::IsKeyPressed(KEY_0))
		{
			selectedEntity->scale = Vector2::one;
			SetState(FTES_NONE);
			return;
		}

		// cancel out of move by hitting escape or rmb
		if (Input::IsKeyPressed(KEY_ESCAPE) || Input::IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
		{
			selectedEntity->scale = startScale;
			SetState(FTES_NONE);
			return;
		}

		// if let go, return to none state
		if (Input::IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || Input::IsKeyPressed(keyScale) || Input::IsKeyPressed(keySelect))
		{
			SetState(FTES_NONE);
			return;
		}
	}
コード例 #2
0
ファイル: n_degree_solvers.c プロジェクト: Antonito/Raytracer
double		calc_root(double *coeff, int deg, double l, double r)
{
  t_dicho	d;
  double	tmp;

  d.l = l;
  d.r = r;
  tmp = calc_poly(coeff, deg, l);
  d.sl = SIGNOF(tmp);
  tmp = calc_poly(coeff, deg, r);
  d.sr = SIGNOF(tmp);
  if (d.sl * d.sr > 0)
    return (MAX_ROOT + 1);
  return (loop_dicho(coeff, deg, &d));
}
コード例 #3
0
rad_t AngleDiffRad(rad_t r1, rad_t r2) {
	//make both positive
	while (SIGNOF(r1) < 0) r1 += 2 * M_PI_F;
	while (SIGNOF(r2) < 0) r2 += 2 * M_PI_F;
	//both are now between 0 and 2pi

	//calc angle, then check for other direction
	rad_t offset = r2 - r1;

	if (offset > M_PI_F)
		//negative direction instead
		offset -= 2 * M_PI_F;

	return offset;
}
コード例 #4
0
ファイル: n_degree_solvers.c プロジェクト: Antonito/Raytracer
static double	loop_dicho(double *coeff, int deg, t_dicho *d)
{
  int		i;
  double	tmp;

  i = -1;
  while (++i < 1000000)
    {
      if (d->sl == 0 || d->sr == 0)
	return ((d->sl == 0) ? d->l : d->r);
      d->mid = d->l / 2.0 + d->r / 2.0;
      tmp = calc_poly(coeff, deg, d->mid);
      d->smid = SIGNOF(tmp);
      if (fabs(d->l - d->r) < 0.0001 || !d->smid)
	return (d->mid);
      else if (d->sl * d->smid > 0)
	{
	  d->l = d->mid;
	  d->sl = d->smid;
	}
      else
	{
	  d->r = d->mid;
	  d->sr = d->smid;
	}
    }
  return ((d->l + d->r) / 2.0);
}
コード例 #5
0
ファイル: Auto3DCamera.cpp プロジェクト: Zhun-John/paradox4d
void CAuto3DCamera::Look( int left, int up )
{
    double lx, ly, lz;
    GetLeft( lx,ly,lz);
    orix += lx *turnSpeed *left;
    oriy += ly *turnSpeed *left;
    oriz += lz *turnSpeed *left;
    Normalize( orix, oriy, oriz );

    orix += upx *turnSpeed * up;
    oriy += upy *turnSpeed * up;
    oriz += upz *turnSpeed * up;
    Normalize( orix, oriy, oriz );

    //当ori过于靠近或过于远离up时,为up向量匹配新的坐标轴
    double angle = Angle(orix,oriy,oriz, upx,upy,upz);
    if ( angle<M_PI/4 || angle>M_PI*3/4 )
    {
        gx=0; gy=0; gz=0;
        double ox, oy, oz;
        if (angle>M_PI*3/4)  // 若ori过于远离up,即为低头,新的上方向应靠近当前视线方向
        {
            ox=orix; oy=oriy; oz=oriz;
        }
        else   // 若ori过于靠近up,即为抬头,新的上方向应靠近当前视线的负方向
        {
            ox=-orix; oy=-oriy; oz=-oriz;
        }

        // 将ori投影到垂直up的平面内,新的上方向即为投影后的ori向量最靠近(绝对值最大)的坐标轴
        Verticalize(upx,upy,upz, ox,oy,oz);
        abs(ox)>abs(oz) ? 
            ( abs(ox)>abs(oy) ? gx=SIGNOF(ox) : gy=SIGNOF(oy) ) 
            : ( abs(oz)>abs(oy) ? gz=SIGNOF(oz) : gy=SIGNOF(oy) );
    }
}
コード例 #6
0
/************************************************************************************
* Does the vector math in the XY plane to decide where a world location is relative
* to the player's view angles. Returned results are from the unit circle, such
* that a result of 0 is to the right of the player. pi/2 is forward, pi is left,
* 3pi/2 is behind, etc.
************************************************************************************/
rad_t VectorAngleFromPlayerRelative(CBasePlayer* pPlayer, const Vector& vOffset) {
	Vector eyesright; {
		AngleVectors(pPlayer->EyeAngles(), nullptr, &eyesright, nullptr);
		eyesright.z = 0;
		eyesright.NormalizeInPlace();
	}
	Vector offset = vOffset;
	offset.z = 0;
	offset.NormalizeInPlace();
	
	//because the vectors are unit vectors, the results of these are equivelant to sin and cos
	float cos = DotProduct(eyesright, offset);
	Vector cross = CrossProduct(eyesright, offset);
	float sin = cross.Length() * SIGNOF(cross.z); //this should work with the right-hand rule, try it yourself at home

	return AngleFromSinCos(sin, cos);
}
コード例 #7
0
ファイル: newclip.c プロジェクト: dreamsxin/X3D-68k
static inline void clip_edge(X3D_ClipData* clip, X3D_IndexedEdge* edge, X3D_ClippedEdge* edge_out) {
  uint16 vex;
  
  if((clip->outside_mask[edge->v[0]] & clip->outside_mask[edge->v[1]]) != 0) {
    goto invisible;
  }
    
  for(vex = 0; vex < 2; ++vex) {
    
    if(!vertex_visible(clip, edge->v[vex])) {
      uint16 min_scale_line;
      int16 scale = min_clip_scale(clip, edge->v[vex ^ 1], edge->v[vex], &min_scale_line);
      
      if(scale != 0) {
        scale_edge(&edge_out->v[vex].v, &clip->v[edge->v[vex ^ 1]], &clip->v[edge->v[vex]], scale);
        edge_out->v[vex].clip_line = min_scale_line;
        edge_out->v[vex].clip_status = CLIP_CLIPPED;
      }
      else {
invisible:
        edge_out->v[0].clip_status = CLIP_INVISIBLE;
        edge_out->v[1].clip_status = CLIP_INVISIBLE;
        
        edge_out->v[0].v = clip->v[edge->v[0]];
        edge_out->v[1].v = clip->v[edge->v[1]];
        
        return;
      }
    }
    else {
      edge_out->v[vex].clip_status = CLIP_VISIBLE;
      edge_out->v[vex].v = clip->v[edge->v[vex]];
    }
  }
  
  if(!vertex_visible(clip, edge->v[0]) && !vertex_visible(clip, edge->v[1])) {
    // Check to make sure the domain wasn't flipped
    int16 old_dx = clip->v[edge->v[0]].x - clip->v[edge->v[1]].x;
    int16 old_dy = clip->v[edge->v[0]].y - clip->v[edge->v[1]].y;
    
    int16 new_dx = edge_out->v[0].v.x - edge_out->v[1].v.x;
    int16 new_dy = edge_out->v[0].v.y - edge_out->v[1].v.y;
    
    if(new_dx == 0)
      new_dx = SIGNOF(old_dx);
    
    if(new_dy == 0)
      new_dy = SIGNOF(old_dy);
    
    if(SIGNOF(new_dx) != SIGNOF(old_dx) || SIGNOF(new_dy) != SIGNOF(old_dy)) {
      edge_out->v[0].clip_status = CLIP_INVISIBLE;
      edge_out->v[1].clip_status = CLIP_INVISIBLE;
      edge_out->v[0].v = clip->v[edge->v[0]];
      edge_out->v[1].v = clip->v[edge->v[1]];
      return;
    }
  }
  
  #if 0
  if(!vertex_visible(clip, edge->v[0]) && !vertex_visible(clip, edge->v[1])) {
    // Check to make sure the midpoint is in the bounding region to disambiguate
    // the cases where an egde fails by two separate bounding lines, and interesecs
    // the bounding region and when it doesn't.
    Vex2D mid = { (edge_out->v[0].v.x + edge_out->v[1].v.x) / 2, (edge_out->v[0].v.y + edge_out->v[1].v.y) / 2 };
    uint16 line;
    
    for(line = 0; line < clip->region->total_bl; ++line) {
      if(x3d_dist_to_line(clip->region->line + line, &mid) < 0) {
        edge_out->v[0].clip_status = CLIP_INVISIBLE;
        edge_out->v[1].clip_status = CLIP_INVISIBLE;
        //printf("CASE\n");
        
        printf("FAIL FAIL FAIL\n");
        while(1) ;
        
        return;
}
}
}
#endif
}
コード例 #8
0
	void FringeTileEditor::UpdateOpportunity()
	{
		if (waitForLMBRelease && Input::IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
		{
			waitForLMBRelease = false;
		}

		if (Input::IsKeyPressed(KEY_ESCAPE))
		{
			Select(NULL);
			return;
		}

		if (Input::IsKeyPressed(KEY_1))
		{
			ApplyGrid(selectedEntity, 32);
		}
		if (Input::IsKeyPressed(KEY_2))
		{
			ApplyGrid(selectedEntity, 64);
		}
		if (Input::IsKeyPressed(KEY_3))
		{
			ApplyGrid(selectedEntity, 128);
		}
		if (Input::IsKeyPressed(KEY_4))
		{
			ApplyGrid(selectedEntity, 256);
		}
		if (Input::IsKeyPressed(KEY_5))
		{
			ApplyGrid(selectedEntity, 512);
		}

		if (Input::IsKeyPressed(keyFocus))
		{
			Graphics::MoveCameraPosition(selectedEntity->position, 0.125f, EASE_OUTSIN);
			//Graphics::SetCameraPosition(selectedEntity->position);
		}

		if (selectedNode)
		{
			if (Input::IsKeyPressed(keyClone))
			{
				CloneNode();
			}
			if (Input::IsKeyPressed(keyDelete))
			{
				Node *lastSelectedNode = selectedNode;
				Select(selectedNode->GetPrev());
				lastSelectedNode->TakeOut();
				scene->Remove(lastSelectedNode);
				return;
			}
		}
		if (selectedFringeTile)
		{
			if (Input::IsKeyPressed(keyDelete))
			{
				Level::RemoveFringeTile(selectedFringeTile);
				scene->Remove(selectedEntity);
				Select(NULL);
				return;
			}

			if (Input::IsKeyPressed(KEY_LEFTBRACKET))
			{
				selectedFringeTile->PrevTile();
			}
			if (Input::IsKeyPressed(KEY_RIGHTBRACKET))
			{
				selectedFringeTile->NextTile();
			}
			if (Input::IsKeyPressed(keyClone))
			{
				Clone();
			}
			if (Input::IsKeyPressed(KEY_M))
			{
				std::string path = Monocle::GetWorkingDirectory() + selectedFringeTile->sprite->texture->filename;
				Debug::Log("Opening: " + path + " ...");
				Monocle::OpenURL(path);
			}
			if (Input::IsKeyPressed(KEY_R))
			{
				selectedFringeTile->sprite->texture->Reload();
			}

			if (Input::IsKeyHeld(KEY_LSHIFT) && Input::IsKeyPressed(KEY_0))
			{
				selectedEntity->rotation = 0;
			}

			if (Input::IsKeyPressed(keyFlipH))
			{
				selectedEntity->scale.x *= -1;
			}
			if (Input::IsKeyPressed(keyFlipV))
			{
				selectedEntity->scale.y *= -1;
			}
		}

		const float moveSpeed = 10.0f;
		if (Input::IsKeyHeld(KEY_LEFT))
		{
			selectedEntity->position += Vector2::left * moveSpeed * Monocle::deltaTime;
		}
		if (Input::IsKeyHeld(KEY_RIGHT))
		{
			selectedEntity->position += Vector2::right * moveSpeed * Monocle::deltaTime;
		}
		if (Input::IsKeyHeld(KEY_UP))
		{
			selectedEntity->position += Vector2::up * moveSpeed * Monocle::deltaTime;
		}
		if (Input::IsKeyHeld(KEY_DOWN))
		{
			selectedEntity->position += Vector2::down * moveSpeed * Monocle::deltaTime;
		}

		if (Input::IsKeyPressed(KEY_O))
		{
			Vector2 add = Vector2(SIGNOF(selectedEntity->scale.x), SIGNOF(selectedEntity->scale.y)) * 0.125f;
			selectedEntity->scale += add;
			printf("add(%f, %f)\n", add.x, add.y);
		}
		if (Input::IsKeyPressed(KEY_U))
		{
			selectedEntity->scale -= Vector2(SIGNOF(selectedEntity->scale.x), SIGNOF(selectedEntity->scale.y)) * 0.125f;
		}

		if (Input::IsKeyPressed(KEY_I))
		{
			selectedEntity->AdjustLayer(1);
			printf("layer is now: %d\n", selectedEntity->GetLayer());
		}
		if (Input::IsKeyPressed(KEY_K))
		{
			selectedEntity->AdjustLayer(-1);
			printf("layer is now: %d\n", selectedEntity->GetLayer());
		}

		if (!waitForLMBRelease && Input::IsKeyHeld(keyRotate))
		{
			moveStartPosition = Input::GetWorldMousePosition();
			startRotation = selectedEntity->rotation;
			SetState(FTES_ROTATE);
			return;
		}

		if (!waitForLMBRelease && Input::IsKeyHeld(keyScale))
		{
			Debug::Log("scale start");
			moveStartPosition = Input::GetWorldMousePosition();
			startScale = selectedEntity->scale;
			SetState(FTES_SCALE);
			return;
		}

		if (!waitForLMBRelease && Input::IsKeyPressed(keyMove))//Input::IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) //
		{
			Debug::Log("move start");
			moveStartPosition = selectedEntity->position;
			moveOffset = selectedEntity->position - Input::GetWorldMousePosition();
			moveAxisLock = 0;
			SetState(FTES_MOVE);
			return;
		}
	}