Exemplo n.º 1
0
CIwVec3 HexMapTest::getIntersectionNew(CIwVec3 &o, CIwVec3 &dir) {
	CIwVec3 &l = dir;
	CIwVec3 &l0 = o;
	CIwVec3 n(0,0,IW_FIXED(1));
	int demoninator = l.Dot(n);
	if (demoninator == 0)
		return CIwVec3::g_Zero;
	CIwVec3 p0(IW_FIXED(1),IW_FIXED(1),0);
	int numerator=(p0-l0).Dot(n);
	float f = float(1.0*numerator/demoninator);
	return IW_FIXED_FROM_FLOAT(f)*l+l0;
}
Exemplo n.º 2
0
void renderImageWorldSpace(CIwFVec2& position, float angle, float scaleFactor,
                        int textureSize, float worldRot, int frameNumber, int numFrames, float z) {
	
	static CIwSVec3 vertices[4];
	static CIwSVec2 UVs[4];
	
	//set up model space vertices
	
	int vertexDist = scaleFactor*textureSize/2;
	
	vertices[0] = CIwSVec3(-1*vertexDist, -1*vertexDist, z);
	vertices[2] = CIwSVec3(vertexDist, -1*vertexDist,    z);
	vertices[3] = CIwSVec3(vertexDist, vertexDist,       z);
	vertices[1] = CIwSVec3(-1*vertexDist, vertexDist,    z);
	
	CIwMat modelTransform = CIwMat::g_Identity;
	modelTransform.SetRotZ(IW_ANGLE_FROM_RADIANS(angle));
	modelTransform.SetTrans(CIwVec3(position.x, -position.y, 0));
	    
	CIwMat rot = CIwMat::g_Identity;
 	rot.SetRotZ(IW_ANGLE_FROM_RADIANS(worldRot));
	modelTransform = modelTransform*rot;
	
	IwGxSetModelMatrix(&modelTransform, false);
	
	float frameRatio = 1.0/numFrames;
	
	//set up sprite UV's
    
    iwfixed cf = IW_FIXED((float)frameNumber  / numFrames);
    iwfixed nf = IW_FIXED((frameNumber + 1.0) / numFrames);
    
	UVs[0] = CIwSVec2(cf, 0);
	UVs[2] = CIwSVec2(nf, 0);
	UVs[3] = CIwSVec2(nf, IW_GEOM_ONE);
	UVs[1] = CIwSVec2(cf, IW_GEOM_ONE);
		
	//render the unit in model space
	IwGxSetUVStream(UVs);
	
	IwGxSetZDepthFixed(8);	
	
	IwGxSetVertStreamModelSpace(vertices, 4);
	IwGxDrawPrims(IW_GX_QUAD_STRIP, NULL, 4);
	
    IwGxFlush();
}
Exemplo n.º 3
0
void Unit::displayOnScreen(int x, int y){    
    
    CIwMaterial *mat = new CIwMaterial();
	mat->SetTexture((CIwTexture*)game->getSprites()->GetResHashed(getTextureName(), IW_GX_RESTYPE_TEXTURE));
    mat->SetModulateMode(CIwMaterial::MODULATE_NONE);
    mat->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT);
    IwGxSetMaterial(mat);
    
	CIwSVec2 xy(x-45, y-45);
    CIwSVec2 duv(IW_FIXED(1.0/numFrames), IW_GEOM_ONE);
    
	static CIwSVec2 wh(90, 90);
	static CIwSVec2 uv(IW_FIXED(0), IW_FIXED(0));	
    
    IwGxSetScreenSpaceSlot(1);
    IwGxDrawRectScreenSpace(&xy, &wh, &uv, &duv);
    
    delete mat;
}
Exemplo n.º 4
0
void CGame::Render()
{
    // game render goes here

    // for example, clear to black (the order of components is ABGR)
    Iw2DSurfaceClear(0xff000000);

    // draw a red square
    Iw2DSetColour(0xff0000ff);
    
    // note conversion to pixel coordinates
    Iw2DFillRect(CIwSVec2((iwsfixed)m_Position.x, (iwsfixed)m_Position.y) - m_Size/IW_FIXED(2), m_Size);

    // show the surface
    Iw2DSurfaceShow();
}
Exemplo n.º 5
0
void IGDistorter::set(float _designWidth, float _designHeight) {
	designWidth = _designWidth;
	designHeight = _designHeight;

	// make sure we're dealing with portrait or landscape
	if(designWidth > designHeight) {
		if(screenHeight > screenWidth) {
			float tmp = screenWidth;
			screenWidth = screenHeight;
			screenHeight = tmp;
		}
	} else {
		if(screenWidth > screenHeight) {
			float tmp = screenWidth;
			screenWidth = screenHeight;
			screenHeight = tmp;
		}
	}
	
	float designAspectRatio = designWidth / designHeight;
	float screenAspectRation = screenWidth / screenHeight;
	if(designAspectRatio == screenAspectRation) {
		multiply = screenHeight / designHeight;
		offsetX = 0;
		offsetY = 0;
	} else if(designAspectRatio < screenAspectRation) {
		multiply = screenHeight / designHeight;
		offsetX = ((screenWidth/multiply) - designWidth) / 2;
		offsetY = 0;
	} else {
		multiply = screenWidth / designWidth;
		offsetX = 0;
		offsetY = ((screenHeight/multiply) - designHeight) / 2;
	}

	char debugStr[200];
	sprintf(debugStr, "design width: %i, height: %i", (int)designWidth, (int)designHeight);
	IGLog(debugStr);
	sprintf(debugStr, "offsetX: %.2f, offsetY: %.2f, multiply: %.2f", offsetX, offsetY, multiply);
	IGLog(debugStr);
	
	// set the scaling matrix
	matrix = new CIwMat2D();
	matrix->SetIdentity();
	matrix->Scale(IW_FIXED(multiply));
	Iw2DSetTransformMatrix(*matrix);
}
Exemplo n.º 6
0
CIwHorizon::CIwHorizon()
{
    IW_CALLSTACK("CIwHorizon::CIwHorizon")

    m_InvYScale = IW_FIXED(1.0);
    if (g_IwHorizon == NULL)
        g_IwHorizon = this;
    m_Spin = 0;
    m_SpinSpeed = 0;
    m_NumWraps = 1;
    m_FillAbove = 0;
    m_FillBelow = 0;
    m_Flags = 0;
    m_XOffset = 0;

    m_AboveMaterial = new CIwMaterial;
    m_AboveMaterial->SetShadeMode(CIwMaterial::SHADE_FLAT);
    m_AboveMaterial->SetColEmissive(0);

    m_BelowMaterial = new CIwMaterial;
    m_BelowMaterial->SetShadeMode(CIwMaterial::SHADE_FLAT);
    m_BelowMaterial->SetColEmissive(0);
}