Esempio n. 1
0
void Player::draw(sf::RenderWindow &render) const
{
    View view(sf::FloatRect(0, 0, m_drawDim.x*(m_zooms[m_controller.getZoom()]), m_drawDim.y*m_zooms[m_controller.getZoom()]));
    view.setCenter(m_controller.getViewCenter());
    view.setViewport(sf::FloatRect(m_drawPos.x/m_resolution.x, m_drawPos.y/m_resolution.y, m_drawDim.x/m_resolution.x, m_drawDim.y/m_resolution.y));
    render.setView(view);
    std::vector<Entity*> toDraw = m_world.getEntitiesInRect(screenToWorld(Vec(0, 0)), screenToWorld(m_drawDim));
    //m_world.draw(render);
    for(int i=0; i<toDraw.size(); i++)
    {
        toDraw[i]->draw(render);
    }
    for(int i=0; i<m_selection.size(); i++)
    {
        m_selection[i]->drawSelected(render);
    }
    draw::drawRect(render, Vec(0, 0), Vec(m_world.getDim()), sf::Color::White);

    for(int i=0; i<toDraw.size(); i++)
    {
        toDraw[i]->drawForeground(render, screenToWorld(mousePos()));
    }
    view.reset(sf::FloatRect(0, 0, m_drawDim.x, m_drawDim.y));
    render.setView(view);
    if(m_selecting)
    {
        draw::drawRect(render, worldToScreen(m_A), worldToScreen(m_B)-worldToScreen(m_A), sf::Color(50, 100, 255, 100), 3);
        draw::drawRect(render, worldToScreen(m_A), worldToScreen(m_B)-worldToScreen(m_A), sf::Color(50, 100, 255, 100));
    }
    m_gui->drawChildren(render, Vec(0, 0), m_drawDim);


    Displayer::instance.draw(render);
    draw::drawRect(render, Vec(1, 1), m_drawDim-Vec(1, 1)*2, sf::Color::White);
}
Esempio n. 2
0
	void View::drawGrid(Renderer2D &out) const {
		if(!m_is_visible)
			return;

		const int2 tile_map_size = m_tile_map.dimensions();

		int2 p[4] = {
			screenToWorld(m_view_pos + int2(0, 0)),
			screenToWorld(m_view_pos + int2(0, m_view_size.y)),
			screenToWorld(m_view_pos + int2(m_view_size.x, m_view_size.y)),
			screenToWorld(m_view_pos + int2(m_view_size.x, 0)) };
		int2 offset = screenToWorld(worldToScreen(int3(0, m_height, 0)));
		for(int n = 0; n < 4; n++)
			p[n] -= offset;

		int2 tmin = min(min(p[0], p[1]), min(p[2], p[3]));
		int2 tmax = max(max(p[0], p[1]), max(p[2], p[3]));
		IRect box(max(tmin, int2(0, 0)), min(tmax, tile_map_size));

		Color color(255, 255, 255, 64);
		for(int x = box.min.x - box.min.x % m_cell_size; x <= box.max.x; x += m_cell_size)
			drawLine(out, int3(x, m_height, box.min.y), int3(x, m_height, box.max.y), color);
		for(int y = box.min.y - box.min.y % m_cell_size; y <= box.max.y; y += m_cell_size)
			drawLine(out, int3(box.min.x, m_height, y), int3(box.max.x, m_height, y), color);
	}
Esempio n. 3
0
void GameInterface::updateStructurePlacement()
{
    if (mPlaceStructure)
    {
        sf::Vector2f mousePos;
        mousePos.x = InputManager::get()->getMousePosition().x;
        mousePos.y = InputManager::get()->getMousePosition().y;
        mousePos = screenToWorld(mousePos-RenderingManager::get()->getCameraScreenOffset());
        mousePos.rotateBy(RenderingManager::get()->getCameraRotation(), RenderingManager::get()->getCameraPosition());

        mPlaceStructure->setPosition(mousePos);

        GameObject *planet = PlanetGenerator::get()->getPlanet(mPlaceStructure);
        sf::Vector2f distance = planet->getPosition()-mousePos;
        mPlaceStructure->setRotation(distance.getAngleTrig()+90);

        if (InputManager::get()->getKeyState(sf::Keyboard::Escape) == ButtonState::PRESSED)
        {
            mPlaceStructure->kill();
            mPlaceStructure = NULL;
        }

        if (InputManager::get()->getLMBState() == ButtonState::PRESSED) // Place the structure
        {
            sf::Packet packet;
            packet << PacketType::BUILD_STRUCTURE;
            packet << mCurrentStructureType->mTypeName << mPlaceStructure->getPosition().x << mPlaceStructure->getPosition().y
                   << mPlaceStructure->getRotation();
            NetworkManager::get()->send(packet);
            mPlaceStructure->kill();
            mPlaceStructure = NULL;
        }
    }
}
/**
 *	This function gets information text about a point at pos.
 *
 *  @param pos		The position (in client coordinates) to get information 
 *					about.
 *  @param chunkText	This is set to information about the chunk at this
 *					position.
 *  @param posText	This is set to information about the given position.
 *  @returns		True if information could be obtained.
 */
bool 
ChunkWatchControl::getInfoText
(
	CPoint			const &pos, 
	std::string		&chunkText, 
	std::string		&posText
) const
{
	float wx, wz;
	if (screenToWorld(pos, &wx, &wz))
	{
		Vector3 pos3(wx, 0.0f, wz);
		posText = sformat("({0}, {1})", wx, wz);

		Chunk *chunk = 
			ChunkManager::instance().cameraSpace()->findChunkFromPoint(pos3);
		if (chunk != NULL)
			chunkText = chunk->identifier();
		else
			chunkText = L("WORLDEDITOR/GUI/CONTROLS/CHUNK_WATCH_CONTROL/NOT_LOADED_STRING");
		return true;
	}
	else
	{
		return false;
	}
}
Esempio n. 5
0
void Player::sendOrder()
{
    if(m_selection.size() > 0)
    {
        if(m_selection[0]->getType() == BALL)
        {
            if(m_controller.pressed(ORDER))
            {
                std::vector<Ball*> balls;
                for(int i=0; i<m_selection.size(); i++)
                {
                    Ball* ball = (Ball*)m_selection[i];
                    balls.push_back(ball);
                    m_world.stopMovement(ball);
                }
                MovementHandler *handler = new MovementHandler(balls, m_controller);
                m_world.addMovement(handler);
            }
            else if(m_controller.down(ORDER))
            {
                m_world.updateTarget((Ball*)m_selection[0], screenToWorld(mousePos()));
            }
        }
        else if(m_selection[0]->getType() == BUILDING)
        {
            Building* building = (Building*)m_selection[0];
            building->receiveOrder(m_controller);
        }
    }
}
Esempio n. 6
0
//Handle mouse input
void mouse(int mouseButton, int buttonState, int x, int y)
{
	GLfloat mouseX,mouseY;
	screenToWorld(x,y,mouseX,mouseY);
	Point mousePt(mouseX,mouseY,0);

	if(sb->getResetButton().pointInButton(mousePt) &&
		buttonState == GLUT_DOWN)  //did user click on reset button
	{
		sb->getResetButton().setButtonIsPressed(true);		
		return;
	}
	if(sb->getResetButton().pointInButton(mousePt) &&
		sb->getResetButton().isButtonPressed() &&
		buttonState == GLUT_UP)  //did user click on reset button
	{
		initGame();
		initStartupScript();
		return;
	}
	sb->getResetButton().setButtonIsPressed(false);		

	if (gameStatus!= IN_PLAY)
		return;
	if( mouseButton == GLUT_LEFT_BUTTON  &&
		buttonState == GLUT_DOWN)
	{
		gamePiece tmp = player1Turn?player1GamePiece:player2GamePiece;
		Move m= getSlotFromPoint(mousePt);
		makeMove(m ,tmp);
	}
	glutPostRedisplay();
}
Esempio n. 7
0
void getSelectedTileXY(int mouseX, int mouseY, int& mapX, int& mapY)
{
	SDL_Rect rect;
	rect.x = mouseX;
	rect.y = mouseY;
	rect.w = 0;
	rect.h = 0;
	
	screenToWorld(rect.x, rect.y);
	rect.x -= tileSizeX / 2;
	unzoom(rect);
	isoToMap(rect.x, rect.y, mapX, mapY);

// 	const int tileSizeX = 32;
// 	const int tileWidth = 16;
// 	const double cst = (2 * tileSizeX*tileWidth);
// 	const double fx = -camX + tileSizeX;
// 	const double fy = -camY;//-(tileSizeY*input_scale - tileWidth*input_scale);
// 	double x = (tileWidth*mouseX + tileSizeX*mouseY + (-fx*tileWidth - fy*tileSizeX));
// 	double y = (-tileWidth*mouseX + tileSizeX*mouseY + (fx*tileWidth - fy*tileSizeX));
// 	x /= cst;
// 	y /= cst;
// 	mapX = x;
// 	mapY = y;

	std::cout << mouseX << "," << mouseY << "\n";
	std::cout << rect.x << "," << rect.y << "\n";
}
	void CameraBase::getMouseRay(int cursorX, int cursorY, Ray& out) const
	{
		out.origin = screenToWorld(cursorX,cursorY);
		out.dir = out.origin-m_eyePos;	//从From点出发,指向"鼠标所指向的点"的方向
		D3DXVec3Normalize(&out.dir,&out.dir);

		out.origin += out.dir*m_fZNear;//进行near剪裁
	}
Esempio n. 9
0
	const IBox View::computeCursor(const int2 &start, const int2 &end, const int3 &bbox, int height, int offset) const {
		float2 height_off = worldToScreen(float3(0, height, 0));
		int3 gbox(cellSize(), 1, cellSize());

		int3 start_pos = asXZ((int2)( screenToWorld(float2(start + pos()) - height_off) + float2(0.5f, 0.5f)));
		int3 end_pos   = asXZ((int2)( screenToWorld(float2(end   + pos()) - height_off) + float2(0.5f, 0.5f)));

		start_pos.y = end_pos.y = height + offset;
		
		{
			int apos1 = start_pos.x % gbox.x;
			int apos2 = apos1 - gbox.x + bbox.x;
			start_pos.x -= apos1 < gbox.x - apos1 || bbox.x >= gbox.x? apos1 : apos2;
		}
		{
			int apos1 = start_pos.z % gbox.z;
			int apos2 = apos1 - gbox.z + bbox.z;
			start_pos.z -= apos1 < gbox.z - apos1 || bbox.z >= gbox.z? apos1 : apos2;
		}
		if(end == start)
			end_pos = start_pos;
		
		int3 dir(end_pos.x >= start_pos.x? 1 : -1, 1, end_pos.z >= start_pos.z? 1 : -1);
		int3 size(::abs(end_pos.x - start_pos.x), 1, ::abs(end_pos.z - start_pos.z));
		size += bbox - int3(1, 1, 1);
		size.x -= size.x % bbox.x;
		size.z -= size.z % bbox.z;
		size = max(bbox, size);

		if(dir.x < 0)
			start_pos.x += bbox.x;
		if(dir.z < 0)
			start_pos.z += bbox.z;
		end_pos = start_pos + dir * size;

		if(start_pos.x > end_pos.x) swap(start_pos.x, end_pos.x);
		if(start_pos.z > end_pos.z) swap(start_pos.z, end_pos.z);
		
		int2 dims = m_tile_map.dimensions();
		start_pos = asXZY(clamp(start_pos.xz(), int2(0, 0), dims), start_pos.y);
		  end_pos = asXZY(clamp(  end_pos.xz(), int2(0, 0), dims),   end_pos.y);

		return IBox(start_pos, end_pos);

	}
Esempio n. 10
0
bool StageLayer::handleEventMouse(EventMouse *e)
{
    auto btn = e->getMouseButton();
    auto idx = (int)btn;
    switch(e->getMouseCode()) {
    // FIX: no need to start with press ok
    case MouseCode::SCROLL:
    case MouseCode::PRESS:
    {
        auto const &pos = e->getCursorPos();
        if(!inView(pos.x, pos.y))
            return false;

        auto worldPos = screenToWorld(pos);
        e->setCursorWorld(worldPos.x, worldPos.y);

        return dispatchEvent(e);
    }
    case MouseCode::RELEASE:
    {
        auto l = static_cast<EventMouseListener*>(mouseSlots_[idx].get());
        auto ok = l && l->isRunning();
        if(ok && l->onRelease) {
            auto worldPos = screenToWorld(e->getCursorPos());
            e->setCursorWorld(worldPos);
            l->onRelease(e);
        }
        mouseSlots_[idx] = nullptr;
        return ok;
    }
    case MouseCode::MOVE:
    {
        auto l = static_cast<EventMouseListener*>(mouseSlots_[idx].get());
        auto ok = l && l->isRunning();
        if(ok && l->onMove) {
            auto worldPos = screenToWorld(e->getCursorPos());
            e->setCursorWorld(worldPos);
            l->onMove(e);
        }
        return ok;
    }
    }
    return false;
}
Esempio n. 11
0
void GameInterface::onStructureBuildClick()
{
    sf::Vector2f mousePos;
    mousePos.x = InputManager::get()->getMousePosition().x;
    mousePos.y = InputManager::get()->getMousePosition().y;
    mousePos = screenToWorld(mousePos-RenderingManager::get()->getCameraScreenOffset());
    mousePos.rotateBy(RenderingManager::get()->getCameraRotation(), RenderingManager::get()->getCameraPosition());

    mPlaceStructure = StructureManager::get()->createStructure(mCurrentStructureType->mTypeName, mousePos, 0);
}
Esempio n. 12
0
  //mouse move event
  void GlWidget::mouseMoveEvent(QMouseEvent *event)
  {
      int dx = event->x() - lastPos.x();
      int dy = event->y() - lastPos.y();
      if(event->x()>0 && event->y()>0 && event->x()<this->width() && event->y()< this->height()){
          QPointF clicked=screenToWorld(lastPos.x(),lastPos.y());
          QPointF currentClicked=screenToWorld(event->x(),event->y());

          if (event->buttons() & Qt::MiddleButton) {

          } else if (event->buttons() & Qt::LeftButton) {
              // Mouse point to angle conversion
              theta -= dy*1.0;
              phi -= dx*1.0;

              // Spherical to Cartesian conversion.
              // Degrees to radians conversion factor 0.0174532
              eyeX = r * cos(theta*0.0174532) * cos(phi*0.0174532);
              eyeY = r * cos(theta*0.0174532) * sin(phi*0.0174532);
              eyeZ = r * sin(theta*0.0174532);

              // Reduce theta slightly to obtain another point on the same longitude line on the sphere.
              GLfloat dt=0.01;
              GLfloat eyeXtemp = r * cos(theta*0.0174532-dt) * cos(phi*0.0174532);
              GLfloat eyeYtemp = r * cos(theta*0.0174532-dt) * sin(phi*0.0174532);
              GLfloat eyeZtemp = r * sin(theta*0.0174532-dt);

              // Connect these two points to obtain the camera's up vector.
              upX=eyeXtemp-eyeX;
              upY=eyeYtemp-eyeY;
              upZ=eyeZtemp-eyeZ;

              updateGL();
          } else if (event->buttons() & Qt::RightButton){
              xMove -= clicked.x()-currentClicked.x();
              yMove -= clicked.y()-currentClicked.y();
              updateGL();
          }

          lastPos = event->pos();
      }
  }
Esempio n. 13
0
Ray SceneGraph::screenToWorldRay(int x, int y) {

	vec4i vp = viewport();
	int screenWidth = vp[2];
	int screenHeight = vp[3];

	//Select Gizmo First
	vec3f ns(x, screenHeight - y, 0.0f);
	vec3f fs(x, screenHeight - y, 1.0f);
	vec3f nw;
	vec3f fw;
	Ray r;

	if (screenToWorld(ns, nw) && screenToWorld(fs, fw)) {
		vec3f dir = fw - nw;
		r.set(nw, dir.normalized());
	} else {
		LogError("Unable to convert screen to world!");
	}

	return r;
}
Esempio n. 14
0
void Player::update()
{
    m_controller.update();
    m_gui->updateChildren(m_controller, Vec(0, 0), m_drawDim);

    if(m_controller.pressed(SELECT) && !m_gui->isInside(m_controller.mousePos()))
    {
        m_A = screenToWorld(mousePos());
        m_selecting = true;
    }
    if(m_controller.down(SELECT))
        m_B = screenToWorld(mousePos());
    else
    {
        m_A = m_B;
        m_selecting = false;
    }
    if(m_selecting)
    {
        m_selection = m_world.selectEntitiesInRect(this, m_A, m_B);
    }
    if(!m_gui->isInside(m_controller.mousePos()) && m_selection.size() > 0)
        sendOrder();
}
Esempio n. 15
0
	void EntitiesEditor::computeCursor(int2 start, int2 end, bool floor_mode) {
		float2 height_off = worldToScreen(int3(0, 0, 0));

		start += m_view.pos();
		  end += m_view.pos();

		Ray ray = screenRay(start);

		Flags::Type flags = Flags::all;
		if(floor_mode)
			flags = flags & ~(Flags::wall_tile | Flags::object_tile);

		auto isect = m_tile_map.trace(ray, -1, flags | Flags::visible);
		float3 pos = isect.first == -1? (float3)asXZ(screenToWorld(start)) : ray.at(isect.second);

		m_cursor_pos = (float3)round(pos);
		m_selection = IRect(min(start, end), max(start, end));
	}
/**
 *	This is called when the mouse button is released.
 *
 *  @param flags	The flags which shift-key status etc.
 *  @param point	The coordinates of the mouse.
 */
/*afx_msg*/ void ChunkWatchControl::OnLButtonUp(UINT /*flags*/, CPoint point)
{
	getDrawConstants();

    float x, z;
    if (screenToWorld(point, &x, &z))
    {    
		// Find the height at this point
		float fheight = TerrainUtils::heightAtPos(x, z, true);
		float y = fheight + Options::getOptionInt( "graphics/farclip", 500 )/10.0f;

		// Set the view matrix to the new world coords and preserve the 
		// current orientation:
		Matrix view = WorldEditorCamera::instance().currentCamera().view();
		view.invert();
		view.translation(Vector3(x, y, z));
		view.invert();
		WorldEditorCamera::instance().currentCamera().view(view);
	}
}
Esempio n. 17
0
void Brick::addToWorld(b2World &world)
{
	if(state == ACTIVE)
	{
		b2Vec2 worldPosition = screenToWorld(position);

		b2BodyDef brickBodyDef;
		brickBodyDef.position.Set(worldPosition.x, worldPosition.y);
		body = world.CreateBody(&brickBodyDef);

		b2PolygonShape brickBox;
		brickBox.SetAsBox(BRICK_WIDTH/(2*SCALING_FACTOR), BRICK_HEIGHT/(2*SCALING_FACTOR));

		b2FixtureDef fixtureDef;
		fixtureDef.shape = &brickBox;
		fixtureDef.density = 0.0f;
		fixtureDef.friction = 0.0f;
		fixtureDef.restitution = 1.0f;

		body->CreateFixture(&fixtureDef);
		body->SetUserData(this);
	}
}
Esempio n. 18
0
Vector SphericalCamera::rasterToWorld(const Vector &rsP, const PTime time) const
{
  Vector ssP;
  m_rasterToScreen.multVecMatrix(rsP, ssP);
  return screenToWorld(ssP, time);
}
Esempio n. 19
0
bool UI_SDL::doToolEvents(SDL_Event e) {
	SDL_Point p;
	switch (e.type) {
		case SDL_MOUSEMOTION:
			p.x = e.motion.x;
			p.y = e.motion.y;
			switch(currtool) {
				case T_Circle:
					dragMesh.clear();

					//If a center has been picked, draw the temp circle
					if(toolstate == 1) {
						Vect4 delta = screenToWorld(p) - clicks[0];
						double mag = delta.magnitude();

						dragMesh.genPrimCircle(clicks[0], mag);
					}
					break;
				case T_Line:
					dragMesh.clear();

					//If a center has been picked, draw the temp circle
					if(toolstate == 1) {
						Vect4 end = screenToWorld(p);

						dragMesh.genPrimEdge(clicks[0], end);
					}
					break;
				case T_Hermite:
					dragMesh.clear();
					
					if(toolstate >= 1) {
						Vect4 v[4];

						Vect4 curr = screenToWorld(p);

						if(toolstate == 1) {
							dragMesh.genPrimEdge(clicks[0], curr);
						} else {
							dragMesh.genPrimEdge(clicks[0], clicks[1]);
							if(toolstate == 3) {
								dragMesh.genPrimEdge(clicks[2], curr);
								dragMesh.genPrimHermite(
										clicks[0],
										clicks[2],
										clicks[1],
										curr);
							}
						}
					}
					break;
				case T_Bezier:
					dragMesh.clear();
					
					if(toolstate >= 1) {
						Vect4 v[4];

						Vect4 curr = screenToWorld(p);

						if(toolstate == 1) {
							dragMesh.genPrimEdge(clicks[0], curr);
						} else {
							dragMesh.genPrimEdge(clicks[0], clicks[1]);
							if(toolstate == 3) {
								dragMesh.genPrimEdge(clicks[2], curr);
								dragMesh.genPrimBezier(
										clicks[0],
										clicks[1],
										curr,
										clicks[2]);
							}
						}
					}
					break;
				case T_Box:
					dragMesh.clear();

					//If a start point has been picked, draw the temp box
					if(toolstate == 1) {
						Vect4 end = screenToWorld(p);

						dragMesh.genPrimBox(end[0], end[1], end[1]);
					}
					break;
				case T_Sphere:
					dragMesh.clear();

					//If a center has been picked, draw the temp sphere
					if(toolstate == 1) {

						Vect4 delta = screenToWorld(p) - clicks[0];
						double mag = delta.magnitude();

						dragMesh.genPrimSphere(mag);
					}
					break;
				case T_Torus:
					dragMesh.clear();

					//If a start point has been picked, draw the temp torus
					if(toolstate == 1) {
						Vect4 end = screenToWorld(p);

						dragMesh.genPrimTorus(std::abs(end[0]), std::abs(end[1]));
					}
					break;
				default:
					break;
			}
			break;
		case SDL_MOUSEBUTTONDOWN:
			p.x = e.button.x;
			p.y = e.button.y;
			switch(currtool) {
				//keep track of the starting click
				case T_Circle:
				case T_Line:
				case T_Box:
				case T_Sphere:
				case T_Torus:
					//All of these just store the start point
					clicks[0] = screenToWorld(p);
					toolstate = 1;
					break;
				case T_Hermite:
					if(toolstate == 0 || toolstate == 2) {
						clicks[toolstate] = screenToWorld(p);
						toolstate++;
					} else {
						std::cerr << "ERR in mousedown Hermite\n";
					}
					break;
				case T_Bezier:
					if(toolstate == 0 || toolstate == 2) {
						clicks[toolstate] = screenToWorld(p);
						toolstate++;
					} else {
						std::cerr << "ERR in mousedown Bezier\n";
					}
					break;
				default:
					break;
			}
			break;
		case SDL_MOUSEBUTTONUP:
			switch(currtool) {
				case T_Circle:
				case T_Line:
				case T_Sphere:
				case T_Box:
				case T_Torus:
					//Make it so
					if(toolstate == 1) {
						world->addMesh(new Mesh(dragMesh));
						dragMesh.clear();
						toolstate = 0;
					}
					break;
				case T_Hermite:
					if(toolstate == 1 || toolstate == 3) {
						SDL_Point p;
						p.x = e.button.x;
						p.y = e.button.y;
						clicks[toolstate] = screenToWorld(p);
						toolstate++;
					} else {
						std::cerr << "ERR in mouseup Hermite\n";
					}

					if(toolstate == 4) { //finished
						dragMesh.clear();
						dragMesh.genPrimHermite(
								clicks[0],
								clicks[2],
								clicks[1],
								clicks[3]);
						world->addMesh(new Mesh(dragMesh));
						dragMesh.clear();
						toolstate = 0;
					}
					break;
				case T_Bezier:
					if(toolstate == 1 || toolstate == 3) {
						SDL_Point p;
						p.x = e.button.x;
						p.y = e.button.y;
						clicks[toolstate] = screenToWorld(p);
						toolstate++;
					} else {
						std::cerr << "ERR in mouseup Bezier\n";
					}

					if(toolstate == 4) { //finished
						dragMesh.clear();
						dragMesh.genPrimBezier(
								clicks[0],
								clicks[1],
								clicks[3],
								clicks[2]);
						world->addMesh(new Mesh(dragMesh));
						dragMesh.clear();
						toolstate = 0;
					}
					break;
				default:
					break;
			}
			break;
		case SDL_KEYDOWN:
			switch(e.key.keysym.sym) {
				case SDLK_RIGHTBRACKET:
					changeTool(1);
					break;
				case SDLK_LEFTBRACKET:
					changeTool(-1);
					break;
				default:
					return false;
			}
			break;
		case SDL_WINDOWEVENT:
			switch (e.window.event) {
				case SDL_WINDOWEVENT_ENTER:
					//uistate.mouseinwindow = 1;
				case SDL_WINDOWEVENT_LEAVE:
					//uistate.mouseinwindow = 0;
					break;
			}
			return false;
			break;
		default:
			return false;
	}
	return true;
}
Esempio n. 20
0
File: Game.cpp Progetto: w23/o08
void Game::inputPointer(const PointerState& pointers) {
  if (pointers.wasPressed()) {
    logic_.place(screenToWorld(pointers.main().getPosition()), static_cast<Rotation>(pattern_rotation_), 2);
  }
}
Esempio n. 21
0
void R_drawWorldDebug()
{	
	glUseProgramObjectARB(NULL);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	glDisable(GL_TEXTURE_2D);

	float x0,y0,x1,y1,w,h;

	//axis
	glLineWidth(4.0f);
	glBegin(GL_LINES);
	{

		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
		x0 = max(-10000,camera.position.x);
		x1 = min(10000,camera.position.x+camera.size.x);
		glVertex2f(x0, 0);
		glVertex2f(x1, 0);
		glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
		y0 = max(-10000,camera.position.y);
		y1 = min(10000,camera.position.y+camera.size.y);
		glVertex2f(0, y0);
		glVertex2f(0, y1);
	}
	glEnd();

	//grid
	glLineWidth(4.0f);
	glBegin(GL_LINES);
	{
		w = tilemap_back.w_tileSize.x;
		h = tilemap_back.w_tileSize.y;
		for (int y = tilemap_back.Min.y; y < tilemap_back.Max.y; y++)
		{
			for (int x = tilemap_back.Min.x; x < tilemap_back.Max.x; x++)
			{
				x0 = tilemap_back.position.x + x * w;
				y0 = tilemap_back.position.y + y * h;

				glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
				glVertex2f(x0, y0);
				glVertex2f(x0, y0 + h);
				glVertex2f(x0, y0);
				glVertex2f(x0 + w, y0);

				glColor4f(1.0f, 0.0f, 1.0f, 0.5f);
				if(y == tilemap_back.Max.y-1)
				{
					glVertex2f(x0, y0 + h);
					glVertex2f(x0 + w, y0 + h);
				}
				glColor4f(0.0f, 0.0f, 1.0f, 0.5f);
				if(x == tilemap_back.Max.x-1)
				{
					glVertex2f(x0 + w, y0);
					glVertex2f(x0 + w, y0 + h);
				}
			}
		}
	}
	glEnd();

	//highlightedTile
	if(PointinRect(Point(input.mouse.lX,input.mouse.lY),s_dstRect))
	{
		Point cursor(CLAMP(input.mouse.lX,lmenuw,client_rect.w - rmenuw),input.mouse.lY);
		Vector2 worldcursor = screenToWorld(cursor,camera,client_rect);
		highlightedTile = worldToTile(worldcursor - pselected_tilemap->position, pselected_tilemap->w_tileSize);
		highlightedTile.x = CLAMP(highlightedTile.x,0,pselected_tilemap->t_mapSize.x-1);
		highlightedTile.y = CLAMP(highlightedTile.y,0,pselected_tilemap->t_mapSize.y-1);
	}

	float lw = 2.0f;
	ScreenRect srcRect,dstRect;

	w = pselected_tilemap->w_tileSize.x;
	h = pselected_tilemap->w_tileSize.y;		
	x0 = pselected_tilemap->position.x + highlightedTile.x * w;
	y0 = pselected_tilemap->position.y + highlightedTile.y * h;

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	srcRect = atlas_tile.sourceRectangles[selectedBrush];
	dstRect = ScreenRect(x0,y0,w,h);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, *(atlas_tile.texture));
	glBegin(GL_QUADS);
	{
		glTexCoord2d(srcRect.fLeft(), srcRect.fTop());	glVertex2f(dstRect.fLeft(), dstRect.fBottom());
		glTexCoord2d(srcRect.fRight(), srcRect.fTop());	glVertex2f(dstRect.fRight(), dstRect.fBottom());
		glTexCoord2d(srcRect.fRight(), srcRect.fBottom());	glVertex2f(dstRect.fRight(),  dstRect.fTop());
		glTexCoord2d(srcRect.fLeft(), srcRect.fBottom());	glVertex2f(dstRect.fLeft(),  dstRect.fTop());
	}
	glEnd();
	glDisable(GL_TEXTURE_2D);

	//image map
	if(blayer01loaded)
	{
		glColor4f(0.0f, 0.5f, 1.0f, 1.0f);
		x0 = pselected_tilemap->position.x + selectedTile.x * w;
		y0 = pselected_tilemap->position.y + selectedTile.y * h;

		R_DrawHorizontalLine(x0 - lw, y0, w + 2*lw, lw);
		R_DrawVerticalLine(x0, y0 , h, lw);
		R_DrawHorizontalLine(x0 - lw, y0 + h, w + 2*lw, lw);
		R_DrawVerticalLine(x0 + w, y0 + h, -h, lw);

		glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
		x0 = pselected_tilemap->position.x + highlightedTile.x * w;
		y0 = pselected_tilemap->position.y + highlightedTile.y * h;

		R_DrawHorizontalLine(x0 - lw, y0, w + 2*lw, lw);
		R_DrawVerticalLine(x0, y0 , h, lw);
		R_DrawHorizontalLine(x0 - lw, y0 + h, w + 2*lw, lw);
		R_DrawVerticalLine(x0 + w, y0 + h, -h, lw);
	}

	glEnable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
Esempio n. 22
0
 inline Vec2 screenToWorld(const Vec2 &screen)
 {return screenToWorld(screen.x,screen.y);}
Esempio n. 23
0
	bool EntitiesEditor::onMouseDrag(const InputState &state, int2 start, int2 current, int key, int is_final) {
		bool shift_pressed = state.isKeyPressed(InputKey::lshift);
		if(key == 0 && !state.isKeyPressed(InputKey::lctrl)) {
			computeCursor(start, current, shift_pressed);
			m_is_selecting = !is_final;

			if(m_mode == Mode::selecting && is_final && is_final != -1) {
				findVisible(m_selected_ids, m_selection);
				computeCursor(current, current, shift_pressed);
			}
			else if(m_mode == Mode::placing) {
				if(m_proto->typeId() == EntityId::trigger) {
					Trigger *trigger = static_cast<Trigger*>(m_proto.get());

					if(m_trigger_mode == 0) {
						m_trigger_box = m_view.computeCursor(start, current, int3(1, 1, 1), m_cursor_pos.y, 0);
					
						if(state.isMouseButtonDown(InputButton::right)) {
							m_trigger_mode = 1;
							m_trigger_offset = current;
						}
					}

					IBox new_box = m_trigger_box;
					if(m_trigger_mode == 1) {
						int offset = screenToWorld(int2(0, m_trigger_offset.y - current.y)).y;
						if(offset < 0)
							new_box.min.y += offset;
						else
							new_box.max.y += offset;
					}
					
					trigger->setBox((FBox)new_box);
					m_cursor_pos = trigger->pos();
			
					if(is_final > 0) {
						m_entity_map.add(PEntity(m_proto->clone()));
					}
					if(is_final) {
						m_trigger_mode = 0;
						trigger->setBox(FBox(0, 0, 0, 1, 1, 1) + trigger->pos());
					}
				}
				else if(is_final > 0)
					m_entity_map.add(PEntity(m_proto->clone()));
			}

			return true;
		}
		else if(key == 1 && m_mode == Mode::selecting) {
			if(!m_is_moving) {
				m_is_moving_vertically = state.isKeyPressed(InputKey::lshift);
				m_is_moving = true;
			}

			if(m_is_moving_vertically)
				m_move_offset = int3(0, screenToWorld(int2(0, start.y - current.y)).y, 0);
			else
				m_move_offset = asXZY(screenToWorld(current - start), 0);

			if(is_final)
				m_is_moving = false;

			if(is_final > 0) {
				for(int n = 0; n < (int)m_selected_ids.size(); n++) {
					auto &object = m_entity_map[m_selected_ids[n]];
					object.ptr->setPos(object.ptr->pos() + float3(m_move_offset));
					m_entity_map.update(m_selected_ids[n]);
				}
			}

			return true;
		}

		return false;
	}