Beispiel #1
0
void ShakeWidget::slot_timerOut()
{
    m_timer->stop();

    if(m_nPosition < MaxLimitTimes)
    {
        ++m_nPosition;
        switch(m_nPosition%4)
        {
        case 1:
        {
            QPoint tmpPos(m_curPos.x(),m_curPos.y()-MaxLimitSpace);
            this->move(tmpPos);
        }
            break;
        case 2:
        {
            QPoint tmpPos(m_curPos.x()-MaxLimitSpace,m_curPos.y()-MaxLimitSpace);
            this->move(tmpPos);
        }
            break;
        case 3:
        {
            QPoint tmpPos(m_curPos.x()-MaxLimitSpace,m_curPos.y());
            this->move(tmpPos);
        }
            break;
        default:
        case 0:
            this->move(m_curPos);
            break;
        }
        m_timer->start();
    }
}
Beispiel #2
0
void AreaCombat::getList(const Position& centerPos, const Position& targetPos, std::list<Tile*>& list) const
{
	const MatrixArea* area = getArea(centerPos, targetPos);
	if (!area) {
		return;
	}

	uint32_t centerY, centerX;
	area->getCenter(centerY, centerX);

	Position tmpPos(targetPos.x - centerX, targetPos.y - centerY, targetPos.z);
	uint32_t cols = area->getCols();
	for (uint32_t y = 0, rows = area->getRows(); y < rows; ++y) {
		for (uint32_t x = 0; x < cols; ++x) {
			if (area->getValue(y, x) != 0) {
				if (g_game.isSightClear(targetPos, tmpPos, true)) {
					Tile* tile = g_game.getTile(tmpPos);
					if (!tile) {
						tile = new StaticTile(tmpPos.x, tmpPos.y, tmpPos.z);
						g_game.setTile(tile);
					}
					list.push_back(tile);
				}
			}
			tmpPos.x++;
		}
		tmpPos.x -= cols;
		tmpPos.y++;
	}
}
Beispiel #3
0
vec3 & TransformPosition(vec3 & position, const mat4 & matrix)
{
	vec4 tmpPos(position, 1.0f);
	tmpPos = matrix * tmpPos;
	position = vec3(tmpPos / tmpPos.w);
	//position = vec3(tmpPos);
	return position;
}
Beispiel #4
0
//=============================================================================
// キーボードを使用しての移動
// Wiiリモコンを使わないカーソル移動はこちらを使う
//=============================================================================
void CCursor::AddForce(void){

	D3DXVECTOR3 tmpPos(GetPos());

	// 座標の設定
	SetPos(tmpPos + m_fVelocity);

}
Beispiel #5
0
void FlowField::draw() {
    for( int y=0; y<flowList.size(); y++){
        for( int x=0; x<flowList[y].size(); x++){
            ofVec2f np( x*resolution, y*resolution );
            drawVectorAt( flowList[y][x], np, flowList[y][x].length() );
            
            ofVec2f tmpPos(x*resolution, y*resolution);
        }
    }
}
Beispiel #6
0
//=============================================================================
// キーボードを使用しての移動
// Wiiリモコンを使わないカーソル移動はこちらを使う
//=============================================================================
void CCursor::SyncCharPos(D3DXVECTOR3 paramSyncPos){

	D3DXVECTOR3 tmpPos(GetPos());

	tmpPos.x = EsasingNone(tmpPos.x, paramSyncPos.x, m_Time);
	tmpPos.y = EsasingNone(tmpPos.y, paramSyncPos.y, m_Time);
	tmpPos.z = EsasingNone(tmpPos.z, paramSyncPos.z, m_Time);

	SetPos(tmpPos);

	if (m_Time >= 1.0f)
	{
		m_Time = 0.0f;
	}
	else
	{
		m_Time += 0.02f;
	}

}
Beispiel #7
0
//=============================================================================
// キーボードを使用しての移動
// Wiiリモコンを使わないカーソル移動はこちらを使う
//=============================================================================
void CCursor::MoveByKeybord(void){

	POINT tmpPointPos;
	D3DXVECTOR3 tmpPos(GetPos());

	HWND tmpWnd = CManager::GetWndHandle();

	GetCursorPos(&tmpPointPos);
	ScreenToClient(tmpWnd, &tmpPointPos);

	tmpPos.x = static_cast<float>(tmpPointPos.x);
	tmpPos.y = static_cast<float>(tmpPointPos.y);

	SetPos(tmpPos);

	// 初期化
	m_fVelocity.x = 0.0f;
	m_fVelocity.y = 0.0f;

}
Beispiel #8
0
void CUIWindowItem::PositionSelf()
{
	if( m_pWindow )
	{
		CEGUI::MouseCursor& cursor = CEGUI::MouseCursor::getSingleton();
        CEGUI::Rect screen( CEGUI::System::getSingleton().getRenderer()->getRect());
        CEGUI::Rect tipRect( m_pWindow->getUnclippedPixelRect());
        const CEGUI::Image* mouseImage = cursor.getImage();

        CEGUI::Point mousePos(cursor.getPosition());
        CEGUI::Size mouseSz(0,0);

        if (mouseImage)
        {
            mouseSz = mouseImage->getSize();
        }

        CEGUI::Point tmpPos(mousePos.d_x - tipRect.getWidth() - 5, mousePos.d_y - tipRect.getHeight() - 5);
        tipRect.setPosition(tmpPos);

        // if tooltip would be off the right of the screen,
        // reposition to the other side of the mouse cursor.
        if ( tipRect.d_right < 0 )
        {
            tmpPos.d_x = mousePos.d_x + mouseSz.d_width + 5;
        }

        // if tooltip would be off the bottom of the screen,
        // reposition to the other side of the mouse cursor.
        if ( tipRect.d_bottom < 0 )
        {
            tmpPos.d_y = mousePos.d_y + mouseSz.d_height + 5;
        }

        // set final position of tooltip window.
        m_pWindow->setPosition( CEGUI::Absolute, tmpPos);
	}
}
Beispiel #9
0
    void Tooltip::positionSelf(void)
    {
        MouseCursor& cursor = MouseCursor::getSingleton();
        Rect screen(Vector2(0, 0), System::getSingleton().getRenderer()->getDisplaySize());
        Rect tipRect(getUnclippedOuterRect());
        const Image* mouseImage = cursor.getImage();

        Point mousePos(cursor.getPosition());
        Size mouseSz(0,0);

        if (mouseImage)
        {
            mouseSz = mouseImage->getSize();
        }

        Point tmpPos(mousePos.d_x + mouseSz.d_width, mousePos.d_y + mouseSz.d_height);
        tipRect.setPosition(tmpPos);

        // if tooltip would be off the right of the screen,
        // reposition to the other side of the mouse cursor.
        if (screen.d_right < tipRect.d_right)
        {
            tmpPos.d_x = mousePos.d_x - tipRect.getWidth() - 5;
        }

        // if tooltip would be off the bottom of the screen,
        // reposition to the other side of the mouse cursor.
        if (screen.d_bottom < tipRect.d_bottom)
        {
            tmpPos.d_y = mousePos.d_y - tipRect.getHeight() - 5;
        }

        // set final position of tooltip window.
        setPosition(
            UVector2(cegui_absdim(tmpPos.d_x),
                     cegui_absdim(tmpPos.d_y)));
    }
Beispiel #10
0
bool Spawn::addMonster(std::string name, Direction dir, int x, int y, int spawntime)
{
	Position tmpPos(centerPos.x + x, centerPos.y, centerPos.z);
	if(!isInSpawnRange(tmpPos)) {
// #ifdef __DEBUG__
		std::cout << "Monster is outside the spawn-area!" << std::endl;
// #endif
		return false;
	}

	struct spawninfo si;
	si.name = name;
	si.dir = dir;
	si.pos.x = centerPos.x + x;
	si.pos.y = centerPos.y + y;
	si.pos.z = centerPos.z;
	si.spawntime = spawntime;
	si.lastspawn = 0;

	unsigned long spawnid = (int)spawnmap.size() + 1;
	spawnmap[spawnid] = si;

	return true;
}
Beispiel #11
0
// Move to a point with collision test
collision_t PhysicalObj::NotifyMove(Point2d oldPos, Point2d newPos)
{
  if (IsGhost())
    return NO_COLLISION;

  Point2d contactPos;
  Double contactAngle;
  Point2d pos, offset;
  PhysicalObj* collided_obj = NULL;

  collision_t collision = NO_COLLISION;

  // Convert meters to pixels.
  oldPos *= PIXEL_PER_METER;
  newPos *= PIXEL_PER_METER;

  // Compute distance between old and new position.
  Double lg = oldPos.SquareDistance(newPos);

  MSG_DEBUG("physic.move", "%s moves (%s, %s) -> (%s, %s), square distance: %s",
            GetName().c_str(),
            Double2str(oldPos.x).c_str(), Double2str(oldPos.y).c_str(),
            Double2str(newPos.x).c_str(), Double2str(newPos.y).c_str(),
            Double2str(lg).c_str());

  if (!lg.IsNotZero())
    return NO_COLLISION;

  // Compute increments to move the object step by step from the old
  // to the new position.
  lg = sqrt(lg);
  offset = (newPos - oldPos) / lg;

  // First iteration position.
  pos = oldPos + offset;

  if (!m_collides_with_ground || IsInWater()) {
    MSG_DEBUG("physic.move", "%s moves (%s, %s) -> (%s, %s), collides ground:%d, water:%d",
              GetName().c_str(),
              Double2str(oldPos.x).c_str(), Double2str(oldPos.y).c_str(),
              Double2str(newPos.x).c_str(), Double2str(newPos.y).c_str(),
              m_collides_with_ground, IsInWater());

    SetXY(newPos);
    return NO_COLLISION;
  }

  do {
    Point2i tmpPos(uround(pos.x), uround(pos.y));

    // Check if we exit the GetWorld(). If so, we stop moving and return.
    if (IsOutsideWorldXY(tmpPos)) {

      if (!GetWorld().IsOpen()) {
        tmpPos.x = InRange_Long(tmpPos.x, 0, GetWorld().GetWidth() - GetWidth() - 1);
        tmpPos.y = InRange_Long(tmpPos.y, 0, GetWorld().GetHeight() - GetHeight() - 1);
        MSG_DEBUG("physic.state", "%s - DeplaceTestCollision touche un bord : %d, %d",
                  GetName().c_str(), tmpPos.x, tmpPos.y);
        collision = COLLISION_ON_GROUND;
        break;
      }

      SetXY(pos);

      MSG_DEBUG("physic.move", "%s moves (%f, %f) -> (%f, %f) : OUTSIDE WORLD",
                GetName().c_str(), oldPos.x.tofloat(), oldPos.y.tofloat(),
                newPos.x.tofloat(), newPos.y.tofloat());
      return NO_COLLISION;
    }

    // Test if we collide...
    collided_obj = CollidedObjectXY(tmpPos);
    if (collided_obj) {
      if (!m_go_through_objects || m_last_collided_object != collided_obj) {
        MSG_DEBUG("physic.state", "%s collide on %s", GetName().c_str(), collided_obj->GetName().c_str());

        if (m_go_through_objects) {
          SignalObjectCollision(GetSpeed(), collided_obj, collided_obj->GetSpeed());
          collision = NO_COLLISION;
        } else {
          collision = COLLISION_ON_OBJECT;
        }
        m_last_collided_object = collided_obj;
      } else {
        collided_obj = NULL;
        collision = NO_COLLISION;
      }
    } else if (!IsInVacuumXY(tmpPos, false)) {
      collision = COLLISION_ON_GROUND;
      m_last_collided_object = NULL;
    }

    if (collision != NO_COLLISION) {
      // Nothing more to do!
      MSG_DEBUG("physic.state", "%s - Collision at %d,%d : on %s",
                GetName().c_str(), tmpPos.x, tmpPos.y,
                collision == COLLISION_ON_GROUND ? "ground" : "an object");

      // Set the object position to the current position.
      SetXY(Point2d(pos.x - offset.x, pos.y - offset.y));
      break;
    }

    // Next motion step
    pos += offset;
    lg -= ONE;
  } while (ZERO < lg);

  Point2d speed_before_collision = GetSpeed();
  Point2d speed_collided_obj;
  if (collided_obj) {
    speed_collided_obj = collided_obj->GetSpeed();
  }

  ContactPointAngleOnGround(pos, contactPos, contactAngle);

  Collide(collision, collided_obj, pos);

  // ===================================
  // it's time to signal object(s) about collision!
  // WARNING: the following calls can send Action(s) over the network (cf bug #11232)
  // Be sure to keep it isolated here
  // ===================================
  ActiveTeam().AccessWeapon().NotifyMove(!!collision);
  switch (collision) {
  case NO_COLLISION:
    // Nothing more to do!
    break;
  case COLLISION_ON_GROUND:
    SignalGroundCollision(speed_before_collision, contactAngle);
    break;
  case COLLISION_ON_OBJECT:
    SignalObjectCollision(speed_before_collision, collided_obj, speed_collided_obj);
    collided_obj->SignalObjectCollision(speed_collided_obj, this, speed_before_collision);
    break;
  }
  // ===================================

  return collision;
}
Beispiel #12
0
void ARX_INTERFACE_ManageOpenedBook_Finish(const Vec2f & mousePos, Rectf rect, float scale)
{
	
	RenderState baseState = render3D().depthTest(false).fog(false);
	
	Vec3f pos = Vec3f(0.f, 0.f, 2100.f);
	
	EERIE_LIGHT * light = lightHandleGet(torchLightHandle);
	
	EERIE_LIGHT tl = *light;
	
	light->pos = Vec3f(500.f, -1960.f, 1590.f);
	light->m_exists = true;
	light->rgb = Color3f(0.6f, 0.7f, 0.9f);
	light->intensity = 1.8f;
	light->fallstart = 4520.f;
	light->fallend = light->fallstart + 600.f;
	RecalcLight(light);
	
	Camera * oldcam = g_camera;
	
	g_culledDynamicLights[0] = light;
	g_culledDynamicLightsCount = 1;
	
	Vec2i tmpPos(0);
	
	GRenderer->SetAntialiasing(true);
	
	float wave = timeWaveSin(g_platformTime.frameStart(), PlatformDurationMsf(1256.6370614f));
	float ptDelta = toMs(g_platformTime.lastFrameDuration());
	
	Camera bookcam;
	bookcam.angle = Anglef();
	bookcam.m_pos = Vec3f(0.f);
	bookcam.focal = 500.f;
	bookcam.cdepth = 2200.f;
	
	for(size_t i = 0; i < RUNE_COUNT; i++) {
		if(!gui::necklace.runes[i])
			continue;
		
		EERIE_3DOBJ * rune = gui::necklace.runes[i];
		
		Vec2i projectionCenter = Vec2i(rect.topLeft() + (Vec2f(285, 36) + Vec2f(tmpPos) * Vec2f(45, 64)) * scale);
		
		PrepareCamera(&bookcam, Rect(rect), projectionCenter);
		
		if(player.hasRune((Rune)i)) {
			
			Anglef angle;
			if(rune->angle.getYaw() != 0.f) {
				if(rune->angle.getYaw() > 300.f) {
					rune->angle.setYaw(300.f);
				}
				angle.setYaw(wave * rune->angle.getYaw() * (1.0f / 40));
			}
			
			rune->angle.setYaw(rune->angle.getYaw() - ptDelta * 0.2f);
			
			if(rune->angle.getYaw() < 0.f)
				rune->angle.setYaw(0.f);
			
			// Now draw the rune
			TransformInfo t2(pos, glm::quat_cast(toRotationMatrix(angle)));
			DrawEERIEInter(rune, t2, NULL, false, 0.f);
			
			Rectf runeBox = UpdateBbox2d(*rune).toRect();
			
			PopAllTriangleListOpaque(baseState);
			
			tmpPos.x++;
			
			if(tmpPos.x > 4) {
				tmpPos.x = 0;
				tmpPos.y++;
			}
			
			// TODO this is a workaround for vertexClipPositions being relative to viewport
			Vec2f mousePosInViewport = mousePos - rect.topLeft();
			
			// Checks for Mouse floating over a rune...
			if(runeBox.contains(mousePosInViewport)) {
				bool r = false;
				
				for(size_t j = 0; j < rune->facelist.size(); j++) {
					float n = PtIn2DPolyProj(rune->vertexClipPositions, &rune->facelist[j], mousePosInViewport.x, mousePosInViewport.y);
					if(n != 0.f) {
						r = true;
						break;
					}
				}
				
				if(r) {
					
					TransformInfo t(pos, glm::quat_cast(toRotationMatrix(angle)));
					DrawEERIEInter(rune, t, NULL, false, 0.f);
					
					rune->angle.setYaw(rune->angle.getYaw() + ptDelta * 2.f);
					
					PopAllTriangleListOpaque(baseState.blendAdditive());
					
					cursorSetInteraction();
					
					if(eeMouseDown1()) {
						PlayerBookDrawRune((Rune)i);
					}
				}
			}
			
			TransformInfo t1(pos, quat_identity());
			DrawEERIEInter(gui::necklace.lacet, t1, NULL, false, 0.f);
			
			PopAllTriangleListOpaque(baseState);
		}
	}
	
	*light = tl;
	
	PrepareCamera(oldcam, g_size);
	
	GRenderer->SetAntialiasing(false);
	
}
//--------------------------------------------------------------
void ofApp::generateTerrainMesh()
{
	if( heightmap.size() != heightmapRes*heightmapRes )
	{
		heightmap.resize(heightmapRes*heightmapRes);
		for( int i = 0; i < heightmap.size(); i++ ) heightmap[i] = 0;
	}
	
	float currTime = ofGetElapsedTimef();
	
	int res = heightmapRes;
	ofVec3f step = dimension.get() / (float)(res-1);
	
	//ofVec3f startPos( noisePositionX * step.x, 0 , noisePositionZ * step.z);
	ofVec3f startPos( noisePositionX * step.x, 0 , noisePositionZ * step.z);
	
	
	// Update heightmap
	
	float perlinSpaceDivider = 8000.0f;
	
	int octaves			= 5;
	
	int tmpIndex = 0;
	for( int indexZ = 0; indexZ < res; indexZ++ )
	{
		for( int indexX = 0; indexX < res; indexX++ )
		{
			float frequency		= 0.7f;
			float persistence	= 0.8f;
			float amplitude		= 0.6f;
			
			//ofVec2f perlinLookup( terrainMeshRenderingPosition.x + (indexX * step.x), terrainMeshRenderingPosition.z + (indexZ * step.z) );
			ofVec2f perlinLookup( startPos.x + (indexX * step.x), startPos.z + (indexZ * step.z) );
			perlinLookup /= perlinSpaceDivider;
			
			float tmpHeight = 0.0f;
			for(int k = 0; k < octaves; k++)
			{
				tmpHeight += ofNoise(perlinLookup.x, perlinLookup.y) * amplitude;
				amplitude *= persistence;
				frequency *= 2.0f;
			}
			
			heightmap[tmpIndex] = tmpHeight;
			tmpIndex++;
		}
	}
	
	// Fill mesh with terrain vertices
	
	terrainMesh.clear();
	terrainMesh.setMode( OF_PRIMITIVE_TRIANGLES );
	
	
	//float startX = dimension.x * -0.5f;
	//float startZ = dimension.z * -0.5f;
	
	ofVec3f meshStartPos = terrainMeshRenderingPosition + (dimension.get() * -0.5f);
	//ofVec3f meshStartPos = (dimension.get() * -0.5f);
	
	tmpIndex = 0;
	for( int indexZ = 0; indexZ < res; indexZ++ )
	{
		for( int indexX = 0; indexX < res; indexX++ )
		{
			/*
			 ofVec3f tmpPos( startPos.x + (indexX * step.x),
			 heightmap[tmpIndex] * dimension.get().y,
			 startPos.z + (indexZ * step.z) );
			 */
			ofVec3f tmpPos( meshStartPos.x + (indexX * step.x),
						   heightmap[tmpIndex] * dimension.get().y,
						   meshStartPos.z + (indexZ * step.z) );
			
			terrainMesh.addVertex( tmpPos );
			terrainMesh.addNormal( ofVec3f(0,0,0) );
			tmpIndex++;
		}
	}
	
	// Compute normals
	
	vector<ofVec3f>& normals = terrainMesh.getNormals();
	
	float fracX = 0.0f;
	float fracY = 0.0f;
	
	for( int indexY = 1; indexY < res-1; indexY++ )
	{
		int tmpIndex = indexY * res;
		
		for( int indexX = 1; indexX < res-1; indexX++ )
		{
			float scale = 0.1f;
			float z0 = getHeightmapValue( indexX, indexY ); //paV[ 0 ].m_Z;
			
			float Az = ( indexX + 1 < res	) ? ( getHeightmapValue( indexX + 1, 	indexY ) )		: z0;
			float Bz = ( indexY + 1 < res	) ? ( getHeightmapValue( indexX, 		indexY + 1 ) )	: z0;
			float Cz = ( indexX - 1 >= 0			) ? ( getHeightmapValue( indexX - 1, 	indexY ) )		: z0;
			float Dz = ( indexY - 1 >= 0			) ? ( getHeightmapValue( indexX, 		indexY - 1)  )	: z0;
			
			normals[tmpIndex] = ofVec3f( Cz - Az, 2.f * scale, Dz - Bz ).getNormalized();
			
			tmpIndex++;
		}
	}
	
	// Add indices to draw triangles with our mesh
	
	for( int indexY = 0; indexY < res-1; indexY++ )
	{
		int tmpIndex = indexY * res;
		
		for( int indexX = 0; indexX < res-1; indexX++ )
		{
			terrainMesh.addTriangle( tmpIndex, tmpIndex + 1, tmpIndex + res + 1 );
			terrainMesh.addTriangle( tmpIndex, tmpIndex + res + 1, tmpIndex + res );
			
			tmpIndex++;
		}
	}
	
	// If we want to have a look at the normals
	
	debugDrawNormals = false;
	
	if( debugDrawNormals )
	{
		debugNormalsMesh.clear();
		debugNormalsMesh.setMode( OF_PRIMITIVE_LINES );
		for( unsigned int i = 0; i < terrainMesh.getNumNormals(); i++ )
		{
			ofVec3f tmpPos = terrainMesh.getVertex(i);
			debugNormalsMesh.addVertex( tmpPos );
			debugNormalsMesh.addVertex( tmpPos + (terrainMesh.getNormal(i) * 10.0f));
		}
	}
	
}
Beispiel #14
0
/**
 *
 *
 *  @author OLiver
 */
void nofCarrier::LostWork()
{
    workplace = 0;
    em->RemoveEvent(productivity_ev);
    productivity_ev = 0;

    if(state == CARRS_FIGUREWORK)
        GoHome();
    else
    {
        // Wenn ich noch ne Ware in der Hand habe, muss die gelöscht werden
        if(carried_ware)
        {
            carried_ware->WareLost(player);
            delete carried_ware;
            carried_ware = 0;
        }

        // Is this a boat carrier (i.e. he is on the water)
        if(ct == CT_BOAT)
        {
            MapPoint tmpPos(pos);
            if(state != CARRS_WAITFORWARE && state != CARRS_WAITFORWARESPACE)
            {
                // If we are walking choose the destination point as start point
                // for the pathfinding!
                tmpPos = gwg->GetNeighbour(tmpPos, GetCurMoveDir());
            }

            // Look for the shore
            for(MapCoord tx = gwg->GetXA(tmpPos, 0), r = 1; r <= 5; tx = gwg->GetXA(tx, tmpPos.y, 0), ++r)
            {

                MapPoint t2(tx, tmpPos.y);
                for(unsigned i = 2; i < 8; ++i)
                {
                    for(MapCoord r2 = 0; r2 < r; t2 = gwg->GetNeighbour(t2,  i % 6), ++r2)
                    {
                        if(gwg->IsCoastalPoint(t2) && gwg->IsNodeForFigures(t2))
                        {
                            shore_path = new std::vector<unsigned char>;
                            if(gwg->FindShipPath(tmpPos, t2, shore_path, NULL))
                            {
                                // Ok let's paddle to the coast
                                rs_pos = 0;
                                cur_rs = NULL;
                                if(state == CARRS_WAITFORWARE || state == CARRS_WAITFORWARESPACE)
                                    WanderOnWater();
                                state = CARRS_BOATCARRIER_WANDERONWATER;
                                return;
                            }
                        }
                    }
                }
            }
        }

        StartWandering();
        if(state == CARRS_WAITFORWARE || state == CARRS_WAITFORWARESPACE)
            Wander();
    }
    state = CARRS_FIGUREWORK;
}