Example #1
0
void HexMapTest::SetModelMatrix() {
	s_ModelMatrix.SetIdentity();
	CIwVec3 vectCenter = getWorldCoords(IwGxGetScreenWidth()/2, IwGxGetScreenHeight()/2);
	s_ModelMatrix.t.x = vectCenter.x;
	s_ModelMatrix.t.y = vectCenter.y;

	//Zoom
	s_ModelMatrix.Scale(IW_FIXED_FROM_FLOAT(zoom));
	CIwVec3 vect = getWorldCoords(0, 0);
	CIwVec3 vect2 = getWorldCoords(screenTranslationX, screenTranslationY);

	int32 dx = int32((vect2.x-vect.x) * zoom);
	int32 dy = int32((vect2.y-vect.y) * zoom);

	//s_ModelMatrix.t.x = -dx;
	//s_ModelMatrix.t.y = -dy;

	iwfixed sinTheta = IwGeomSin(IW_ANGLE_FROM_DEGREES(-rotation));
	iwfixed cosTheta = IwGeomCos(IW_ANGLE_FROM_DEGREES(-rotation));

	s_ModelMatrix.t.x = -vectCenter.x-(IW_FIXED_MUL(dx, cosTheta) - IW_FIXED_MUL(dy, sinTheta));
	s_ModelMatrix.t.y = -vectCenter.y-(IW_FIXED_MUL(dx, sinTheta) + IW_FIXED_MUL(dy, cosTheta));
	//Rotate
	CIwMat rotationMat = CIwMat::g_Identity;
	rotationMat.SetRotZ(IW_ANGLE_FROM_DEGREES(rotation), true, true);
	s_ModelMatrix *= rotationMat;

}
Example #2
0
void HexMapTest::SetTranslation()
{
	int16 sprite1_pos_x,sprite1_pos_y,sprite1_pos_x_initial,sprite1_pos_y_initial;
	if (g_Input.finger1MovedTo(sprite1_pos_x, sprite1_pos_y)) {
		g_Input.finger1Initial(sprite1_pos_x_initial, sprite1_pos_y_initial);
	}
	iwfixed sinTheta = IwGeomSin(IW_ANGLE_FROM_DEGREES(rotation));
	iwfixed cosTheta = IwGeomCos(IW_ANGLE_FROM_DEGREES(rotation));

	int odx = sprite1_pos_x_initial - sprite1_pos_x;
	int ody = sprite1_pos_y_initial - sprite1_pos_y;

	int dx = (IW_FIXED_MUL(odx, cosTheta) - IW_FIXED_MUL(ody, sinTheta));
	int dy = (IW_FIXED_MUL(odx, sinTheta) + IW_FIXED_MUL(ody, cosTheta));

	screenTranslationX = screenTranslationX_initial + dx;
	screenTranslationY = screenTranslationY_initial + dy;
	SetModelMatrix();
}
void RotationTransformation::ApplyTransformation(TransformationState& state)
{
    if(rotationSource != null)
    {
        rotation = IW_ANGLE_FROM_DEGREES(rotationSource->GetFloat(state.gameTime));
    }

    if(direction == CounterClockwise)
    {
        state.orientation = -rotation;
        state.tangent = state.orientation;
        state.normal = ANGLE_SUBTRACTION(state.orientation, ANGLE_90_DEGREES);
    }
    else
    {
        state.orientation = rotation;
        state.tangent = state.orientation;
        state.normal = ANGLE_ADDITION(state.orientation, ANGLE_90_DEGREES);
    }
}
Example #4
0
void TileSet::Render(int index,CIwSVec2 topLeft,int rotation)
{
	int ind=index-m_firstGid;
	if(ind<0)
		return;
	int index_X=ind%_tilesPerRow;
	int index_Y=ind/_tilesPerRow;
	CIwSVec2 pos = CIwSVec2(index_X * _tilewidth,index_Y * _tileheight);
	if(rotation!=0)
	{
		iwangle  angle =90*rotation;//90 degrees
		CIwSVec2 centre=CIwSVec2(iwsfixed(topLeft.x+(float)_tilewidth/2.0f),iwsfixed(topLeft.y+(float)_tileheight/2.0f));
		CIwMat2D rot;
    
		rot.SetRot(IW_ANGLE_FROM_DEGREES(angle), CIwVec2(centre));

		Iw2DSetTransformMatrix(rot);
	}
	Iw2DDrawImageRegion(_image, topLeft, pos, _tileSize);
	Iw2DSetTransformMatrix(CIwMat2D::g_Identity);
}
Example #5
0
CIwVec3 HexMapTest::getWorldCoords(int x, int y) {
// Generate a ray pointing to the view plane from the camera
	CIwVec3 dir(x - IwGxGetScreenWidth()/2, 
		y - IwGxGetScreenHeight()/2, 
		IwGxGetPerspMul());
	CIwVec3 origin = s_viewMatrix.t;
    
	// Rotate into camera space
	dir = s_viewMatrix.RotateVec(dir);

//		dir.NormaliseSlow();
	CIwVec3 inter = getIntersectionNew(origin, dir);
	inter = inter - s_ModelMatrix.t;
	iwfixed z = IW_FIXED_FROM_FLOAT(1.0f/zoom);
	inter.x = IW_FIXED_MUL(inter.x, z);
	inter.y = IW_FIXED_MUL(inter.y, z);
	inter.z = IW_FIXED_MUL(inter.z, z);

	CIwMat rotationMat = CIwMat::g_Identity;
	rotationMat.SetRotZ(IW_ANGLE_FROM_DEGREES(-rotation), true, true);
	inter = rotationMat.RotateVec(inter);
	return inter;
}
Example #6
0
bool HexMapTest::UpdateKey() {
	CIwMat   rotation;
    CIwVec3  lookFrom(0,0,0);

	if (KeyPressed(s3eKeyPageUp)) {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.RotateVec(s_left),
				IW_ANGLE_FROM_DEGREES(0));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[2] -= 0x010;
			if (s_cameraPos.z<-0x40)
				s_cameraPos.z += 0x40;
		}
	}

	if (KeyPressed(s3eKeyPageDown))
	{
		if (KeyAltDown()) {
			s_cameraPos.z -= 0x40;
			rotation.SetAxisAngle(
				s_viewMatrix.RotateVec(s_left),
				IW_ANGLE_FROM_DEGREES(0));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[2] += 0x010;
		}
	}

    // Up, Down, Left, Right keys
    //

    if (KeyPressed(s3eKeyUp))
    {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.RotateVec(s_left),
				IW_ANGLE_FROM_DEGREES(-5));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[1] -= 0x010;
		}
    }

    if (KeyPressed(s3eKeyDown))
    {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.RotateVec(s_left),
				IW_ANGLE_FROM_DEGREES(5));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[1] += 0x010;
		}
    }

    if (KeyPressed(s3eKeyRight))
    {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.TransformVec(s_up),
				IW_ANGLE_FROM_DEGREES(5));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[0] += 0x010;
		}
    }

	if (KeyPressed(s3eKeyLeft))
    {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.TransformVec(s_up),
				IW_ANGLE_FROM_DEGREES(-5));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[0] -= 0x010;
		}
    }
	return true;
}
void RotationTransformation::Initialize(float _rotationDegrees, RotationDirection _direction)
{
    rotation = IW_ANGLE_FROM_DEGREES(_rotationDegrees);
    direction = _direction;
    rotationSource = null;
}