コード例 #1
0
ファイル: game.cpp プロジェクト: mvaganov/aiglut201410
Game::Game() ://mapGraph(NULL), mapPath(NULL), selected(NULL), selectedNode(NULL), delauny(NULL), 
drawDebug(true), objectMap(AABBf(V2f(-50,-50),V2f(50,50)), V2i(7,7)) {
	gameLoopRunning = true;
	paused = false;

	V2f min(-10, -10), max(10, 10);
}
コード例 #2
0
ファイル: ImathBoxAlgo.cpp プロジェクト: JohanAberg/Ramen
Box2f scale( const Box2f& b, float sx, float sy, float xcenter, float ycenter)
{
    Box2f box = offsetBy( b, V2f( -xcenter, -ycenter));
    box = scale( box, sx, sy);
    box = offsetBy( box, V2f( xcenter, ycenter));
    return box;
}
コード例 #3
0
ファイル: DogThing.cpp プロジェクト: wilbefast/black-dog
DogThing::DogThing(V2i _position, float start_difficulty) :
Thing(_position, "dog"),
// don't center animation horizontally
graphic(this, V2f(0,0), V2f(0, 0), GraphicIncarnation::CENTER_Y),
unleash_timer(this, STR_UNLEASH_TIMER),
state(OFFSCREEN)
{
}
コード例 #4
0
ファイル: djv_play2_widget.cpp プロジェクト: UIKit0/djv
void Widget::draw()
{
    Gl_Widget::draw();

    //DJV_DEBUG("Widget::draw");

    const Box2i & geom = this->geom();

    //DJV_DEBUG_PRINT("geom = " << geom);

    Gl_Util::ortho(V2i(geom.w, geom.h));
    DJV_DEBUG_GL(glViewport(0, 0, geom.w, geom.h));

    //DJV_DEBUG_GL(glClearColor(0.0, 0.0, 1.0, 0.0));
    DJV_DEBUG_GL(glClear(GL_COLOR_BUFFER_BIT));

    if (_image)
    {
        const Pixel_Data_Info & info = _image->info();

        //DJV_DEBUG_PRINT("info = " << info);

        try
        {
            _image->bind();
        }
        catch (Error error)
        {
            DJV_APP->error(error);
        }

        DJV_DEBUG_GL(glPushMatrix());

        double u [] = { 0, 0 }, v [] = { 0, 0 };

        u[! info.mirror.x] = info.size.x / static_cast<double>(info.size.x);
        v[! info.mirror.y] = info.size.y / static_cast<double>(info.size.y);

        const V2f uv [] =
        {
            V2f(u[0], v[0]),
            V2f(u[0], v[1]),
            V2f(u[1], v[1]),
            V2f(u[1], v[0])
        };

        DJV_DEBUG_GL(glBegin(GL_QUADS));

        Gl_Util::draw_box(info.size, uv);

        DJV_DEBUG_GL(glEnd());

        DJV_DEBUG_GL(glPopMatrix());
    }
}
コード例 #5
0
ファイル: ImfAcesFile.cpp プロジェクト: 09beezahmad/opencv
const Chromaticities &
acesChromaticities ()
{
    static const Chromaticities acesChr 
	    (V2f (0.73470,  0.26530),	// red
	     V2f (0.00000,  1.00000),	// green
	     V2f (0.00010, -0.07700),	// blue
	     V2f (0.32168,  0.33767));	// white

    return acesChr;
}
コード例 #6
0
ファイル: Application.cpp プロジェクト: wilbefast/black-dog
int Application::startSDL()
{
  // Initialise SDL
	ASSERT_SDL(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) >= 0,
		"Initialising SDL video and audio");

  // Initialise timing
  prev_tick = this_tick = SDL_GetTicks();

	// Open the window where we will draw. NB: Android will override the
	// specified height and width no matter what they are!
	window = SDL_CreateWindow(APP_NAME, SDL_WINDOWPOS_CENTERED,
                           SDL_WINDOWPOS_CENTERED, WINDOW_DEFAULT_W,
                           WINDOW_DEFAULT_H, WINDOW_FLAGS);
  ASSERT_SDL(window, "Opening SDL application window");

  // Since the window size can be overriden, check what it is actually
  SDL_GetWindowSize(window, &global::viewport.w, &global::viewport.h);
  global::scale = V2f(global::viewport.w / (float)WINDOW_DEFAULT_W,
                        global::viewport.h / (float)WINDOW_DEFAULT_H);

  // Create the OpenGL context for the window we just opened
  context = SDL_GL_CreateContext(window);
  SDL_GL_MakeCurrent(window, context);

  // Configure SDL/OpenGL interface
  ASSERT_SDL(SDL_GL_SetSwapInterval(1) != -1, "Activating SDL V-sync");
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GL_V_MAJOR);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, GL_V_MINOR);
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

  // No problems, return success code!
  return EXIT_SUCCESS;
}
コード例 #7
0
ファイル: ImfEnvmap.cpp プロジェクト: 09beezahmad/opencv
V2f
latLong (const Box2i &dataWindow, const V2f &pixelPosition)
{
    float latitude, longitude;

    if (dataWindow.max.y > dataWindow.min.y)
    {
	latitude = -M_PI *
		  ((pixelPosition.y  - dataWindow.min.y) /
		   (dataWindow.max.y - dataWindow.min.y) - 0.5f);
    }
    else
    {
	latitude = 0;
    }

    if (dataWindow.max.x > dataWindow.min.x)
    {
	longitude = -2 * M_PI *
		   ((pixelPosition.x  - dataWindow.min.x) /
		    (dataWindow.max.x - dataWindow.min.x) - 0.5f);
    }
    else
    {
	longitude = 0;
    }

    return V2f (latitude, longitude);
}
コード例 #8
0
ファイル: djv_glsl_util.cpp プロジェクト: UIKit0/djv
void Util::quad(const Pixel_Data_Info & in)
{
    double u [] = { 0, 0 }, v [] = { 0, 0 };
    u[! in.mirror.x] = in.size.x;
    v[! in.mirror.y] = in.size.y;
    const V2f uv [] =
    {
        V2f(u[0], v[0]),
        V2f(u[0], v[1]),
        V2f(u[1], v[1]),
        V2f(u[1], v[0])
    };

    glBegin(GL_QUADS);
    Gl_Util::draw_box(Box2i(in.size), uv);
    glEnd();
}
コード例 #9
0
ファイル: ImfEnvmap.cpp プロジェクト: 09beezahmad/opencv
V2f
pixelPosition (const Box2i &dataWindow, const V2f &latLong)
{
    float x = latLong.y / (-2 * M_PI) + 0.5f;
    float y = latLong.x / -M_PI + 0.5f;

    return V2f (x * (dataWindow.max.x - dataWindow.min.x) + dataWindow.min.x,
		y * (dataWindow.max.y - dataWindow.min.y) + dataWindow.min.y);
}
コード例 #10
0
ファイル: FallingThing.cpp プロジェクト: wilbefast/black-dog
FallingThing::FallingThing(V2i _position, const char* name, Animation* loop,
                          float loop_speed, float gravity, float max_speed) :
Thing(_position, name),
graphic(this),
movement(this, max_speed)
{
  graphic.setSprite(loop, loop_speed);
  graphic.setRandFrame();
  movement.setSpeed(V2f(-X_SPEED, gravity));
  body = new ColliderElement(this, V2d(V2d(32, 32))); // freed by ~Thing
}
コード例 #11
0
ファイル: ImfEnvmap.cpp プロジェクト: 09beezahmad/opencv
void
faceAndPixelPosition (const V3f &direction,
		      const Box2i &dataWindow,
		      CubeMapFace &face,
		      V2f &pif)
{
    int sof = sizeOfFace (dataWindow);
    float absx = abs (direction.x);
    float absy = abs (direction.y);
    float absz = abs (direction.z);

    if (absx >= absy && absx >= absz)
    {
	if (absx == 0)
	{
	    //
	    // Special case - direction is (0, 0, 0)
	    //

	    face = CUBEFACE_POS_X;
	    pif = V2f (0, 0);
	    return;
	}

	pif.x = (direction.y / absx + 1) / 2 * (sof - 1);
	pif.y = (direction.z / absx + 1) / 2 * (sof - 1);

	if (direction.x > 0)
	    face = CUBEFACE_POS_X;
	else
	    face = CUBEFACE_NEG_X;
    }
    else if (absy >= absz)
    {
	pif.x = (direction.x / absy + 1) / 2 * (sof - 1);
	pif.y = (direction.z / absy + 1) / 2 * (sof - 1);

	if (direction.y > 0)
	    face = CUBEFACE_POS_Y;
	else
	    face = CUBEFACE_NEG_Y;
    }
    else
    {
	pif.x = (direction.x / absz + 1) / 2 * (sof - 1);
	pif.y = (direction.y / absz + 1) / 2 * (sof - 1);

	if (direction.z > 0)
	    face = CUBEFACE_POS_Z;
	else
	    face = CUBEFACE_NEG_Z;
    }
}
コード例 #12
0
ファイル: ImfEnvmap.cpp プロジェクト: 09beezahmad/opencv
V2f	
latLong (const V3f &dir)
{
    float r = sqrt (dir.z * dir.z + dir.x * dir.x);

    float latitude = (r < abs (dir.y))?
			 acos (r / dir.length()) * sign (dir.y):
			 asin (dir.y / dir.length());

    float longitude = (dir.z == 0 && dir.x == 0)? 0: atan2 (dir.x, dir.z);

    return V2f (latitude, longitude);
}
コード例 #13
0
MeshPlane::MeshPlane(GLfloat x, GLfloat y, GLfloat z, GLfloat x_len, GLfloat y_len, int x_tiles, int y_tiles, GLuint texid){
	MeshPlane::texid=texid;
	textured=true;
	t.push_back(V2f(0,0));
	t.push_back(V2f(0,1));
	t.push_back(V2f(1,1));
	t.push_back(V2f(1,0));
	for(int i = 0; i<=x_tiles; i++)
		for(int j = 0; j<=y_tiles; j++)
			v.push_back(V3f(i*x_len+x,y, j*y_len+z));

	for(int i = 1; i<v.size()-y_tiles-1; i++){
		if(i%(y_tiles+1)!=0){
		vi.push_back(V3i(i-1,i,i+y_tiles+1));
		ti.push_back(V3i(0,1,2));
		vi.push_back(V3i( i-1,i+y_tiles+1, i+y_tiles));
		ti.push_back(V3i(0,2,3));
		}
	}
	calcFaceNormals();
	calcVertexNormalsAverage();
	calcVertexNormalsWeight();
}
コード例 #14
0
//-*****************************************************************************
// much like lib/Alembic/Abc/OTypedProperty.cpp, this is just a compile test,
// due to the implementation being in the .h file, due to templates.
void __testOGeomParamCompile( Abc::OCompoundProperty &iParent )
{
    OV2fGeomParam uvs( iParent, "uv", false, kVertexScope, 1 );

    std::vector<V2f> vec;

    vec.push_back( V2f( 1.0f, 2.0f ) );

    V2fArraySample val( vec );

    OV2fGeomParam::Sample samp( val, kUnknownScope );

    uvs.set( samp );
}
コード例 #15
0
ファイル: samplegen.cpp プロジェクト: UIKit0/aqsis
//------------------------------------------------------------------------------
// DofMbTileSet implementation.
DofMbTileSet::DofMbTileSet(int tileWidth, float timeStratQuality,
                           float shutterMin, float shutterMax)
    : m_tileWidth(tileWidth)
{
    // Generate time and lens samples, and copy them into a convenient
    // format.
    std::vector<float> tuv;
    canonicalTimeLensSamps(tuv, tileWidth*tileWidth);
    m_tuv.resize(tileWidth*tileWidth);
    for(int i = 0, iend=m_tuv.size(); i < iend; ++i)
    {
        m_tuv[i].time = lerp(shutterMin, shutterMax, tuv[3*i]);
        m_tuv[i].lens = V2f(tuv[3*i+1], tuv[3*i+2]);
    }
    makeTileSet(m_tileIndices, tileWidth, tuv, timeStratQuality);
}
コード例 #16
0
void Magnify_Dialog::widget_update()
{
    if (! _view)
    {
        return;
    }

    //DJV_DEBUG("Magnify_Dialog::widget_update");

    callbacks(false);

    const double zoom = Math::pow(2, _zoom);

    //DJV_DEBUG_PRINT("zoom = " << zoom);

    _widget->set(
        _view,
        Vector_Util::floor<double, int>(V2f(_pick) * zoom),
        _view->zoom() * zoom);

    _zoom_widget->set(_zoom);

    callbacks(true);
}
コード例 #17
0
ファイル: View3D.cpp プロジェクト: landersson/displaz
/// Draw the 3D cursor
void View3D::drawCursor(const TransformState& transStateIn, const V3d& cursorPos, float centerPointRadius) const
{
    V3d offset = transStateIn.cameraPos();
    TransformState transState = transStateIn.translate(offset);
    V3d relCursor = cursorPos - offset;

    // Cull if behind camera
    if((relCursor * transState.modelViewMatrix).z > 0)
        return;

    // Find position of cursor in screen space
    V3d screenP3 = relCursor * transState.modelViewMatrix * transState.projMatrix;
    // Position in ortho coord system
    V2f p2 = 0.5f * V2f(width(), height()) * (V2f(screenP3.x, screenP3.y) + V2f(1.0f));

    // Draw cursor
    if (m_cursorShader->isValid())
    {
        QGLShaderProgram& cursorShader = m_cursorShader->shaderProgram();
        // shader
        cursorShader.bind();
        // vertex array
        glBindVertexArray(m_cursorVertexArray);

        transState.projMatrix.makeIdentity();
        transState.setOrthoProjection(0, width(), 0, height(), 0, 1);
        transState.modelViewMatrix.makeIdentity();

        if (centerPointRadius > 0)
        {
            // fake drawing of white point through scaling ...
            //
            TransformState pointState = transState.translate( V3d(p2.x, p2.y, 0) );
            pointState = pointState.scale( V3d(0.0,0.0,0.0) );
            glLineWidth(centerPointRadius);
            cursorShader.setUniformValue("color", 1.0f, 1.0f, 1.0f, 1.0f);
            pointState.setUniforms(cursorShader.programId());
            glDrawArrays( GL_POINTS, 0, 1 );
        }

        // Now draw a 2D overlay over the 3D scene to allow user to pinpoint the
        // cursor, even when when it's behind something.
        glDisable(GL_DEPTH_TEST);

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_LINE_SMOOTH);

        glLineWidth(1); // this won't work anymore for values larger than 1 (2.0f);

        // draw white lines
        transState = transState.translate( V3d(p2.x, p2.y, 0) );
        cursorShader.setUniformValue("color", 1.0f, 1.0f, 1.0f, 1.0f);
        transState.setUniforms(cursorShader.programId());
        glDrawArrays( GL_LINES, 0, 8 );

        // draw black lines
        transState = transState.rotate( V4d(0,0,1,0.785398) ); //45 deg
        cursorShader.setUniformValue("color", 0.0f, 0.0f, 0.0f, 1.0f);
        transState.setUniforms(cursorShader.programId());
        glDrawArrays( GL_LINES, 0, 8 );
    }
}
コード例 #18
0
ファイル: v2f.cpp プロジェクト: ozkriff/marauder-cpp11
V2f V2f::operator-(const V2f& b) {
  return V2f(x() - b.x(), y() - b.y());
}
コード例 #19
0
ファイル: Application.cpp プロジェクト: wilbefast/black-dog
// deal with input messages, return BACK, EXIT or CONTINUE
int Application::treatEvents()
{
  // local variables
  static V2i cursor(0,0);
  static bool clicking(false);

  // static to avoid reallocating it ever time we run the function
  static SDL_Event event;


  // write each event to our static variable
  while (SDL_PollEvent(&event))
  {
    switch (event.type)
    {
      // exit if the window is closed (ex: pressing the cross)
      case SDL_QUIT:
        return Application::EXIT;
        break;

      // check for keypresses
      case SDL_KEYDOWN:
        switch (event.key.keysym.sym)
        {
          case KEY_BACK:
            return Application::BACK;
          case KEY_EXIT:
            return Application::EXIT;
          case KEY_VOLUME_UP:
            AudioManager::getInstance()->volume_up();
            break;
          case KEY_VOLUME_DOWN:
            AudioManager::getInstance()->volume_down();
            break;
          default:
            // here we DO want a default break, as not all keys are needed
            break;
        }
        break;

      #if USE_TOUCH
      // touch events
      case SDL_FINGERDOWN:
        cursor = normaliseTouch(event.tfinger.touchId,
                                   V2i(event.tfinger.x, event.tfinger.y));
        clicking = true;
        break;

      case SDL_FINGERUP:
        clicking = false;
        break;

      case SDL_FINGERMOTION:
        cursor = normaliseTouch(event.tfinger.touchId,
                                V2i(event.tfinger.x, event.tfinger.y));
        break;
      #endif  // USE_TOUCH

      #if USE_MOUSE
      // mouse events
      case SDL_MOUSEBUTTONDOWN:
        if(event.button.button == SDL_BUTTON_RIGHT)
          return Application::BACK;
        clicking = true;
        break;

      case SDL_MOUSEBUTTONUP:
        if(event.button.button == SDL_BUTTON_LEFT)
          clicking = false;
        break;

      case SDL_MOUSEMOTION:
        cursor = V2f(event.motion.x, event.motion.y) / global::scale;
        break;
      #endif  // USE_MOUSE

      default:
        // not all possible inputs are needed, so we DO want a default break
        break;
    }
  }

  // Update the scene with the new input
  scene->getState()->setCursor(cursor, clicking);

  // No exit events encountered, we can continue
  return Application::CONTINUE;
}
コード例 #20
0
ファイル: v2f.cpp プロジェクト: ozkriff/marauder-cpp11
V2f V2f::operator+(float b) {
  return V2f(x() + b, y() + b);
}
コード例 #21
0
ファイル: v2f.cpp プロジェクト: ozkriff/marauder-cpp11
V2f V2f::operator+(const V2f& b) {
  return V2f(x() + b.x(), y() + b.y());
}
コード例 #22
0
ファイル: ImathBoxAlgo.cpp プロジェクト: JohanAberg/Ramen
Box2f scale( const Box2f& b, float sx, float sy)
{
    return Box2f( V2f( b.min.x * sx, b.min.y * sy), V2f( b.max.x * sx, b.max.y * sy));
}
コード例 #23
0
ファイル: v2f.cpp プロジェクト: ozkriff/marauder-cpp11
V2f V2f::operator/(float b) {
  return V2f(x() / b, y() / b);
}
コード例 #24
0
ファイル: v2f.cpp プロジェクト: ozkriff/marauder-cpp11
V2f V2f::operator*(float b) {
  return V2f(x() * b, y() * b);
}
コード例 #25
0
ファイル: ImfEnvmap.cpp プロジェクト: 09beezahmad/opencv
V3f
direction (CubeMapFace face, const Box2i &dataWindow, const V2f &positionInFace)
{
    int sof = sizeOfFace (dataWindow);

    V2f pos;
    
    if (sof > 1)
    {
	pos = V2f (positionInFace.x / (sof - 1) * 2 - 1,
		   positionInFace.y / (sof - 1) * 2 - 1);
    }
    else
    {
	pos = V2f (0, 0);
    }

    V3f dir (1, 0, 0);

    switch (face)
    {
      case CUBEFACE_POS_X:

	dir.x = 1;
	dir.y = pos.x;
	dir.z = pos.y;
	break;

      case CUBEFACE_NEG_X:

	dir.x = -1;
	dir.y = pos.x;
	dir.z = pos.y;
	break;

      case CUBEFACE_POS_Y:

	dir.x = pos.x;
	dir.y = 1;
	dir.z = pos.y;
	break;

      case CUBEFACE_NEG_Y:

	dir.x = pos.x;
	dir.y = -1;
	dir.z = pos.y;
	break;

      case CUBEFACE_POS_Z:

	dir.x = pos.x;
	dir.y = pos.y;
	dir.z = 1;
	break;

      case CUBEFACE_NEG_Z:

	dir.x = pos.x;
	dir.y = pos.y;
	dir.z = -1;
	break;
    }

    return dir;
}
コード例 #26
0
ファイル: game.cpp プロジェクト: mvaganov/aiglut201410
void Game::init() {
	objectMap.addLayer(Obstacle::STATIC, AABBf(V2f(-60, -60), V2f(60, 60)), V2i(16, 16));
	addObstacle(new CircleObject(Circf(V2f(-4, -4), 2), Obstacle::STATIC));
	addObstacle(new AABBObject(AABBf(V2f(-4, 1), V2f(-2, 5)), Obstacle::STATIC));
	addObstacle(new BoxObject(Boxf(V2f(4, 0), V2f(2, 5), V2f(1)), Obstacle::STATIC));
	addObstacle(new ConeObject(Conef(V2f(0, 1), 1.5f, (float)V_2PI * 1 / 8, (float)V_2PI * 3 / 8), Obstacle::STATIC)); // make the radius of the cone correct based on the calculated center
	V2f trapezoid[] = { V2f(-.5f, .5f), V2f(.5f, 1.2f), V2f(.5f, -1.5f), V2f(-.5f, -.8f) };
	int trapezoidCount = sizeof(trapezoid) / sizeof(trapezoid[0]);
	addObstacle(new PolygonObject(Polygon2f(V2f(5, -7), V2f((float)V_2PI*0.0f/6), trapezoid, trapezoidCount), Obstacle::STATIC)); // TODO raycast does not always hit the shape correctly from all sides
	V2f a(-2, -2), b(5, -4);
	addObstacle(new LineObject(Linef(&a, &b), Obstacle::STATIC));
	addObstacle(new PointObject(V2f(7, 7), Obstacle::STATIC));

	delaunyBoundary = new CircleObject(Circf(V2f::ZERO(), 100), Obstacle::EVERYTHING);
	delauny = new DelaunySet(delaunyBoundary);
	//delauny->addNode(V2f(3, 4));
	//delauny->addNode(V2f(-3, 4));
	//delauny->addNode(V2f(-3, -4));
	//delauny->addNode(V2f(0, -1));
//	for (int i = 0; i < 10; ++i) {
//		delauny->addNode(V2f::randomUnitVector() * Random::PRNGf() * 100);
//	}
	delauny->makeRandom(6);
	delauny->calculateAllTriangles();
}