Пример #1
0
static glm::mat4 Util_SetViewMatrix(EERIE_TRANSFORM &transform) {

	Vec3f vFrom(transform.pos.x, -transform.pos.y, transform.pos.z);
	Vec3f vTout(0.0f, 0.0f, 1.0f);

	Vec3f vView;
	rotPoint(&vTout, &vView, transform);
	
	Vec3f up(0.f, 1.f, 0.f);
	Vec3f vWorldUp;
	rotPoint(&up, &vWorldUp, transform);

	return Util_LookAt(vFrom, vView, vWorldUp);
}
Пример #2
0
int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
{
    const SELECTION& selection = m_selectionTool->GetSelection();

    // Shall the selection be cleared at the end?
    bool unselect = selection.Empty();

    if( !hoverSelection( selection ) )
        return 0;

    wxPoint translation;
    double rotation = 0;

    PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();

    DIALOG_MOVE_EXACT dialog( editFrame, translation, rotation );
    int ret = dialog.ShowModal();

    if( ret == wxID_OK )
    {
        if( !isUndoInhibited() )
        {
            editFrame->OnModify();
            // Record an action of move and rotate
            editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED );
        }

        VECTOR2I rp = selection.GetCenter();
        wxPoint rotPoint( rp.x, rp.y );

        for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
        {
            BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );

            item->Move( translation );
            item->Rotate( rotPoint, rotation );

            if( !m_dragging )
                item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
        }

        updateRatsnest( m_dragging );

        if( m_dragging )
            selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
        else
            getModel<BOARD>()->GetRatsnest()->Recalculate();

        if( unselect )
            m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );

        m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
    }

    return 0;
}
Пример #3
0
void drawPlayer(point pos, short angle, bool doExhaust) {		//At angle = 0, player faces to the right.
	point vertex, port, starboard, exhaust;
	point myShip[4];
	vertex = rotPoint(pos, angle, makePoint(pos.x+6, pos.y));
	port = rotPoint(pos, angle, makePoint(pos.x-5, pos.y-5));
	starboard = rotPoint(pos, angle, makePoint(pos.x-5, pos.y+5));
	exhaust = rotPoint(pos, angle, makePoint(pos.x-3, pos.y));
	myShip[0] = vertex;
	myShip[1] = port;
	myShip[2] = exhaust;
	myShip[3] = starboard;
	if(getSetting() >= 1) {
		drawFilledPolygon(myShip, 4, PLAYER_SHADE);
	} else {
		drawPolygon(myShip, 4, PLAYER_SHADE);
	}
	if(doExhaust) {
		if(isExhaustOn) {
			drawPlayerExhaust(pos, angle);
		}
		isExhaustOn ^= 1; //Flip the bit.
	}
}
Пример #4
0
void drawPlayerExhaust(point pos, short angle) {
	point innerVertex, outerVertex, port, starboard, exhaust;
	point innerFire[4], outerFire[4];
	outerVertex = rotPoint(pos, angle, makePoint(pos.x-7, pos.y));
	port = rotPoint(pos, angle, makePoint(pos.x-5, pos.y-3));
	starboard = rotPoint(pos, angle, makePoint(pos.x-5, pos.y+3));
	exhaust = rotPoint(pos, angle, makePoint(pos.x-3, pos.y));
	outerFire[0] = outerVertex;
	outerFire[1] = port;
	outerFire[2] = exhaust;
	outerFire[3] = starboard;
	if(getSetting() >= 1) {
		innerVertex = rotPoint(pos, angle, makePoint(pos.x-5, pos.y));
		innerFire[0] = innerVertex;
		innerFire[1] = port;
		innerFire[2] = exhaust;
		innerFire[3] = starboard;
		drawFilledPolygon(outerFire, 4, PLAYER_EXHAUST_SHADE2);
		drawFilledPolygon(innerFire, 4, PLAYER_EXHAUST_SHADE);
	} else {
		drawLine(outerVertex, port, PLAYER_EXHAUST_SHADE);
		drawLine(outerVertex, starboard, PLAYER_EXHAUST_SHADE);
	}
}
Пример #5
0
// "Bend" our line of sight around corners until we can "see" the point.
bool CCSBot::BendLineOfSight(const Vector *eye, const Vector *point, Vector *bend) const
{
	// if we can directly see the point, use it
	TraceResult result;
	UTIL_TraceLine(*eye, *point + Vector(0, 0, HalfHumanHeight), ignore_monsters, ENT(pev), &result);

	if (result.flFraction == 1.0f && !result.fStartSolid)
	{
		// can directly see point, no bending needed
		*bend = *point;
		return true;
	}

	// "bend" our line of sight until we can see the approach point
	Vector v = *point - *eye;
	float startAngle = UTIL_VecToYaw(v);
	float length = v.Length2D();
	v.NormalizeInPlace();

	float angleInc = 10.0f;
	for (float angle = angleInc; angle <= 135.0f; angle += angleInc)
	{
		// check both sides at this angle offset
		for (int side = 0; side < 2; ++side)
		{
			float actualAngle = (side) ? (startAngle + angle) : (startAngle - angle);

			float dx = BotCOS(actualAngle);
			float dy = BotSIN(actualAngle);

			// compute rotated point ray endpoint
			Vector rotPoint(eye->x + length * dx, eye->y + length * dy, point->z);

			TraceResult result;
			UTIL_TraceLine(*eye, rotPoint + Vector(0, 0, HalfHumanHeight), ignore_monsters, ENT(pev), &result);

			// if this ray started in an obstacle, skip it
			if (result.fStartSolid)
			{
				continue;
			}

			Vector ray = rotPoint - *eye;
			float rayLength = ray.NormalizeInPlace();
			float visibleLength = rayLength * result.flFraction;

			// step along ray, checking if point is visible from ray point
			const float bendStepSize = 50.0f;
			for (float bendLength = bendStepSize; bendLength <= visibleLength; bendLength += bendStepSize)
			{
				// compute point along ray
				Vector rayPoint = *eye + bendLength * ray;

				// check if we can see approach point from this bend point
				UTIL_TraceLine(rayPoint, *point + Vector(0, 0, HalfHumanHeight), ignore_monsters, ENT(pev), &result);

				if (result.flFraction == 1.0f && !result.fStartSolid)
				{
					// target is visible from this bend point on the ray - use this point on the ray as our point

					// keep "bent" point at correct height along line of sight
					if (!GetGroundHeight(&rayPoint, &rayPoint.z))
					{
						rayPoint.z = point->z;
					}

					*bend = rayPoint;
					return true;
				}
			}
		}
	}

	*bend = *point;

	// bending rays didn't help - still can't see the point
	return false;
}
Пример #6
0
void gameUpdate(void) {
	point vertex, port, starboard, exhaust, playerPos;
	point playerShip[5];
	int i, j;
	//Level defaults to finished, changed when rocks or enemies are alive.
	HWREGBITW(&gFlags, LEVEL_COMPLETE) = True;
	//Update player
	gPlayer.x += gPlayer.dx;
	gPlayer.y += gPlayer.dy;
	gPlayer.x = floatMod(gPlayer.x, 128);
	gPlayer.y = floatMod(gPlayer.y, 96);
	gPlayer.dx = (gPlayer.dx*SPEED_DECAY);
	gPlayer.dy = (gPlayer.dy*SPEED_DECAY);
	gPlayer.exhaustOn = False;
	playerPos = makePoint((int)gPlayer.x, (int)gPlayer.y);
	vertex = rotPoint(playerPos, gPlayer.angle,
										makePoint(playerPos.x+6, playerPos.y));
	port = rotPoint(playerPos, gPlayer.angle,
									makePoint(playerPos.x-5, playerPos.y-5));
	starboard = rotPoint(playerPos, gPlayer.angle,
											 makePoint(playerPos.x-5, playerPos.y+5));
	exhaust = rotPoint(playerPos, gPlayer.angle,
										 makePoint(playerPos.x-3, playerPos.y));
	playerShip[0] = vertex;
	playerShip[1] = port;
	playerShip[2] = exhaust;
	playerShip[3] = starboard;
	playerShip[4] = makePoint((int)gPlayer.x, (int)gPlayer.y);
	switch(gPlayer.status) {
		case ALIVE:
			////Button movement input
			//Forward (up)
			if ((GPIO_PORTG_DATA_R&0x08) == 0 || HWREGBITW(&gFlags, ANALOG_UP)) {
				if((gPlayer.dx*gPlayer.dx + gPlayer.dy*gPlayer.dy) <
					 MAX_PLAYER_SPEED*MAX_PLAYER_SPEED) {
					gPlayer.dx += cosDeg(gPlayer.angle)*PLAYER_ACCEL;
					gPlayer.dy -= sinDeg(gPlayer.angle)*PLAYER_ACCEL;
				}
				gPlayer.exhaustOn = True;
			}
			//Left
			if((GPIO_PORTG_DATA_R&0x20) == 0) {//|| HWREGBITW(&gFlags, ANALOG_LEFT)) {
				gPlayer.angle += PLAYER_TURN_RATE;
			}
			//Right
			if((GPIO_PORTG_DATA_R&0x40) == 0) {// || HWREGBITW(&gFlags, ANALOG_RIGHT)) {
				gPlayer.angle -= PLAYER_TURN_RATE;
			}
			//Select (positive edge)
			if((GPIO_PORTG_DATA_R & 0x80) != 0) {
				selectNotPressed = True;
			}
			if(HWREGBITW(&gFlags, SELECT_DOWN) == 1 ||
				(selectNotPressed == True && (GPIO_PORTG_DATA_R & 0x80) == 0)) {
				selectNotPressed = False;
				if(HWREGBITW(&gFlags, TITLE_SCREEN) == True) {
					HWREGBITW(&gFlags, TITLE_SCREEN) = False;
					setXYAvg();
				}
				HWREGBITW(&gFlags, SELECT_DOWN) = 0;	//reset flag
				addBullet(makePoint((int)gPlayer.x, (int)gPlayer.y),
									(cosDeg(gPlayer.angle)*MAX_BULLET_SPEED),
									-1*(sinDeg(gPlayer.angle)*MAX_BULLET_SPEED),
									True);
			}
			break;
		case HIT:
			gPlayer.status = DEAD;
			addExplosion(makePoint(gPlayer.x, gPlayer.y), 12);
			gPlayer.dx = 0;
			gPlayer.dy = 0;
			killBullets();
			killRocks();
			break;
		case DEAD:
			//Wait for explosions to stop, then stop updating the game.
			for(i = 0; i < MAX_EXPLOSIONS; i++) {
				if(gExplosions[i].status == ALIVE) { break; }
			}
			HWREGBITW(&gFlags, LEVEL_COMPLETE) = False;
			HWREGBITW(&gFlags, GAME_OVER) = True;
			killRocks();
			killBullets();
			killEnemies();
			return;
	}
	if(HWREGBITW(&gFlags, TITLE_SCREEN) == True) {
		return;
	}
	//Update bullets
	for(i = 0; i < MAX_PLAYER_BULLETS; i++) {
		switch(gPlayerBullets[i].status) {		//Only update visible bullets.
			case ALIVE:
				if(gPlayerBullets[i].life++ > BULLET_LIFETICKS) {
					gPlayerBullets[i].status = DEAD;
					break;
				}
				gPlayerBullets[i].x = gPlayerBullets[i].x+gPlayerBullets[i].dx;
				gPlayerBullets[i].y = gPlayerBullets[i].y+gPlayerBullets[i].dy;
				break;
			case HIT:
				break;
			case DEAD:
				break;
		}
	}
	for(i = 0; i < MAX_ENEMY_BULLETS; i++) {
		switch(gEnemyBullets[i].status) {		//Only update visible bullets.
			case ALIVE:
				if(gEnemyBullets[i].life++ > BULLET_LIFETICKS) {
					gEnemyBullets[i].status = DEAD;
					break;
				}
				HWREGBITW(&gFlags, LEVEL_COMPLETE) = False;
				gEnemyBullets[i].x = gEnemyBullets[i].x+gEnemyBullets[i].dx;
				gEnemyBullets[i].y = gEnemyBullets[i].y+gEnemyBullets[i].dy;
				break;
			case HIT:
				break;
			case DEAD:
				break;
		}
	}
	//Update rocks
	for(i = 0; i < MAX_ROCKS; i++) {
		switch(gRocks[i].status) {
			case ALIVE:		//Only update visible rocks.
				HWREGBITW(&gFlags, LEVEL_COMPLETE) = False;
				//Update rock position
				if(gRocks[i].dx < 0.1 && gRocks[i].dy < 0.1) {
					gRocks[i].dx = (randRange(32,64)*-1+randRange(32,64)*1)/64.;
					gRocks[i].dy = randRange(0,256)/256;
				}
				gRocks[i].x = floatMod(gRocks[i].x+gRocks[i].dx, 128);
				gRocks[i].y = floatMod(gRocks[i].y+gRocks[i].dy, 96);
				//Check collisions with enemies, players and bullets.
				//Player collision
				for(j = 0; j < 5; j++) {
					if(pointInRock(makePoint(((int)gRocks[i].x),
																	 ((int)gRocks[i].y)),
												 gRocks[i].rockType,
												 gRocks[i].rockSize,
												 playerShip[j])) {
						gPlayer.status = HIT;
						return;
					}
				}
				//Bullet collision
				for(j = 0; j < MAX_PLAYER_BULLETS; j++) {
					if(gPlayerBullets[j].status == ALIVE) {
						if(pointInRock(makePoint(((int)gRocks[i].x),
																		 ((int)gRocks[i].y)),
													 gRocks[i].rockType,
													 gRocks[i].rockSize,
													 makePoint(((int)gPlayerBullets[j].x),
																		 ((int)gPlayerBullets[j].y)))) {
							score += 1;
							addExplosion(makePoint(gPlayerBullets[j].x,
																		 gPlayerBullets[j].y), 2);
							gRocks[i].status = HIT;
							gPlayerBullets[j].status = DEAD;
						}
					}
				}/*
				for(j = 0; j < MAX_ENEMY_BULLETS; j++) {
					if(gEnemyBullets[i].status == ALIVE) {
						if(pointInRock(makePoint(((int)gRocks[i].x),
																		 ((int)gRocks[i].y)),
													 gRocks[i].rockType,
													 gRocks[i].rockSize,
													 makePoint(((int)gEnemyBullets[j].x)%128,
																		 ((int)gEnemyBullets[j].y)%96))) {
							gRocks[i].status = HIT;
							addExplosion(makePoint(gEnemyBullets[j].x,
																		 gEnemyBullets[j].y), 2);																	 
							gEnemyBullets[j].status = DEAD;
						}
					}
				}*/
				if(gRocks[i].status == ALIVE) { break; }
			case HIT:
				if(gRocks[i].rockSize > 1) {
					addRock(makePoint((int)gRocks[i].x+1, (int)gRocks[i].y+1),
									randRange(24, 64)/-64.,
									randRange(24, 64)/-64.,
									gRocks[i].rockSize-1);
					addRock(makePoint((int)gRocks[i].x-1, (int)gRocks[i].y-1),
									randRange(64, 24)/64.,
									randRange(64, 24)/64.,
									gRocks[i].rockSize-1);
				}
				gRocks[i].status = DEAD;
				break;
			case DEAD:
				break;
		}
	}
	//Update UFOs
	for(i = 0; i < MAX_UFOS; i++) {
		switch(gUFOs[i].status) {
			case ALIVE:		//Only update visible rocks.
				HWREGBITW(&gFlags, LEVEL_COMPLETE) = False;
				//Update rock position
				if(gUFOs[i].dx < 0.1 && gUFOs[i].dy < 0.1) {
					gUFOs[i].dx = (randRange(32,64)*-1+randRange(32,64)*1)/64.;
					gUFOs[i].dy = randRange(0,256)/256;
				}
				gUFOs[i].pos.x = floatMod(gUFOs[i].pos.x+gUFOs[i].dx, 128);
				gUFOs[i].pos.y = floatMod(gUFOs[i].pos.y+gUFOs[i].dy, 96);
				
				if(gUFOs[i].status == ALIVE) { break; }
			case HIT:
				gUFOs[i].status = DEAD;
				break;
			case DEAD:
				break;
		}
	}
	//Update explosions
	for(i = 0; i < MAX_EXPLOSIONS; i++) {
		if(gExplosions[i].status == ALIVE) {
			HWREGBITW(&gFlags, LEVEL_COMPLETE) = False;
			if(gExplosions[i].current++ > gExplosions[i].lifetime) {
				gExplosions[i].status = DEAD;
				continue;
			}
		}
	}
}