void CTextureDx9::RenderWithoutTransform(LPD3DXSPRITE _lpDSpriteHandle, D3DXVECTOR2 position, D3DXVECTOR2 Center, D3DXVECTOR2 scale, float angle, D3DCOLOR color, RECT *srcRect, float deep)
{
	D3DXVECTOR2 CamTransDistance;
	CamTransDistance.x = -Camera::getInstance()->GetMatrixTranslate()._41;
	CamTransDistance.y = Camera::getInstance()->GetMatrixTranslate()._42;

	position.y += Camera::getInstance()->getBound().bottom;
	Center.y += Camera::getInstance()->getBound().bottom;
	D3DXVECTOR3 currentPosition(position.x + CamTransDistance.x, position.y, deep); //toa do trong the gioi thuc

	D3DXMATRIX oldMatrix; //ma tran luu lai phep transform cua SpriteBatch

	_lpDSpriteHandle->GetTransform(&oldMatrix);
	
	D3DXVECTOR2 centerScale = D3DXVECTOR2(position.x, position.y);//lay vi tri cua vat the lam tam xoay(vi vi tri cua vat la vi tri chinh giua cua vat)

	D3DXMATRIX matrixScalingRotate; //ma tran rotate, scale

	D3DXMatrixTransformation2D(&matrixScalingRotate, &centerScale, 0.0f, &scale, &Center, D3DXToRadian(angle), 0);

	D3DXMATRIX finalMatrix = matrixScalingRotate * oldMatrix;

	_lpDSpriteHandle->SetTransform(&finalMatrix); //ma tran chuyen toa do vi tri cua vat the tu the gioi thuc sang toa do trong directX de ve

	_lpDSpriteHandle->Draw(
		this->m_lpTexture,
		srcRect,
		&D3DXVECTOR3((float)(srcRect->right - srcRect->left)/2, (float)(srcRect->bottom - srcRect->top)/2, 0),
		&currentPosition,
		color);

	_lpDSpriteHandle->SetTransform(&oldMatrix);
}
Esempio n. 2
0
int OpticSprite::draw(LPD3DXSPRITE sprite, double time, D3DXCOLOR colour, double offsetX, double offsetY) {
	if(!this->animate) {
		sprite->Draw(texture, NULL, NULL, NULL, colour);
		return 1;
	}

	if(animation.lifetime() > time) {
		animation.updateState(aniState, time);
		colour = D3DXCOLOR(aniState.red, aniState.green, aniState.blue, colour.a < aniState.alpha? colour.a : aniState.alpha);
		float rotation = 6.28318531f * aniState.rotation;
		D3DXMATRIX mat, current;
		D3DXVECTOR2 scaling(aniState.scale_x, aniState.scale_y);
		D3DXVECTOR2 position(floor(((pResolution->width * aniState.position_x) - translateCentre.x) + offsetX),
							 floor(((pResolution->height * aniState.position_y) - translateCentre.y) + offsetY));
		D3DXMatrixTransformation2D(&mat, &transformCentre, 0.0f, &scaling, &transformCentre, rotation, &position);
		sprite->GetTransform(&current);
		mat *= current;
		sprite->SetTransform(&mat);
		
		HRESULT res;

		//Spritesheet rect calculations are slightly iffy thanks to the texture scaling (rounding errors)
		if(this->spritesheet) {
			int x = (width * currFrame) % surfaceDesc.Width;
			
			//Hacky workaround
			int diff = x - surfaceDesc.Width;

			if(abs(diff) <= 10) {
				x = 0;
			}
			//End of hacky workaround

			int y = height * currRow;
			RECT source;
			source.top = y;
			source.left = x;
			source.right = x + width;
			source.bottom = y + height;
			res = sprite->Draw(texture, &source, NULL, NULL, colour);
			sprite->SetTransform(&current);

			if(!advanceFrame(time, x, y)) {
				return 0;
			}
		} else {
			res = sprite->Draw(texture, NULL, NULL, NULL, colour);
			sprite->SetTransform(&current);
		}

		if(res != S_OK) {
			throw OpticSpriteException("Rendering sprite failed!");
		}

		return 1;
	}

	return 0;
}
Esempio n. 3
0
bool OpticMedal::draw(LPD3DXSPRITE sprite) {
	double time;

	if(tickTimer) {
		time = timer.current();
	} else {
		tickTimer = true;
		timer.start();
		time = 0;	
	}
	
	D3DXMATRIX aniMat, currMat;
	sprite->GetTransform(&currMat);
	D3DXMatrixIdentity(&aniMat);

	D3DXCOLOR colour = -1;

	if(this->animate) {
		if(this->animation.lifetime() > time) {
			animation.updateState(aniState, time);
			colour = D3DXCOLOR(aniState.red, aniState.green, aniState.blue, aniState.alpha);
			float rotation = 6.28318531f * aniState.rotation;
			D3DXVECTOR2 scaling(aniState.scale_x, aniState.scale_y);
			D3DXVECTOR2 position(floor(((pResolution->width * aniState.position_x) - translateCentre.x)),
							   	 floor(((pResolution->height * aniState.position_y) - translateCentre.y)));
			D3DXMatrixTransformation2D(&aniMat, &transformCentre, 0.0f, &scaling, &transformCentre, rotation, &position);
		} else {
			return false;
		}
	}

	aniMat *= currMat;

	double offset_x = spawnOffsetX;
	double offset_y = spawnOffsetY;

	for(auto i = sliders.begin(); i != sliders.end(); ++i) {
		OpticAnimation& animation = std::get<0>(*i);
		AnimationState& state = std::get<1>(*i);
		double time = std::get<2>(*i).current();
		animation.updateState(state, time);
		offset_x += this->_dimensions.first  * state.position_x;
		offset_y += this->_dimensions.second * state.position_y;
	}

	if(_endTime > 0 && time > _endTime) {
		if(!_ending) {
			endSlideAnimation = defaultEndSlideAnimation(offset_x, offset_y);
			_ending = true;
			endTimer.start();
		}

		endSlideAnimation.updateState(endState, endTimer.current());
		offset_x = endState.position_x;
		offset_y = endState.position_y;
	}
	
	sprite->SetTransform(&aniMat);

	int keepDrawing = 0;

	/* Faster to erase all of the sprites at once rather than one
	   by one when they've finished drawing */
	for(auto i = sprites.begin(); i != sprites.end(); ++i) {
		keepDrawing |= i->draw(sprite, time, colour, offset_x, offset_y);
	}

	sprite->SetTransform(&currMat);

	return keepDrawing == 1;
}
Esempio n. 4
0
// called after clear_text_texture
void zz_font_d3d::draw_text_prim (const zz_font_text& text_item)
{
	if (!text_item.msg.get()) return;

	size_t length;
	length = text_item.msg.size();

	if (length <= 0) return; // draw nothing
	
	assert(_d3d_font);
	if (!_d3d_font)
		return;
	
	zz_renderer_d3d * r = static_cast<zz_renderer_d3d*>(znzin->renderer);
	LPD3DXSPRITE sprite = r->get_sprite();
	assert(sprite);

	if (!text_item.use_sprite) { // begin sprite
		
		zz_assert(!r->sprite_began());
		r->begin_sprite(ZZ_SPRITE_ALPHABLEND, "draw_text_prim");  //조성현 2006 04 25 Text출력..
		// we assumes that identity matrix transform is the default
	   D3DXMATRIX mat, mat2;
	   D3DXMatrixIdentity(&mat2);
	   sprite->GetTransform(&mat);
	   
	   mat2._41 = mat._41;
	   mat2._42 = mat._42;
	   mat2._43 = mat._43;
	
	   sprite->SetTransform(&mat2);

	    
	}
	else {
		zz_assert(r->sprite_began());
	  
	}

	HRESULT hr;

	if (text_item.to_texture) { // render to texture stage
		r->enable_zbuffer(false);
		r->enable_zwrite(false);

		zz_rect new_rect;
		int width, height;
		width = text_item.rect.right - text_item.rect.left;
		height = text_item.rect.bottom - text_item.rect.top;
		SetRect(&new_rect, text_item.tex_rect.left, text_item.tex_rect.top,
			text_item.tex_rect.left + width, text_item.tex_rect.top + height);

		assert((text_item.tex_rect.top != 0) || (text_item.tex_rect.bottom != 0));

		//ZZ_LOG("font: draw_text_prim(%s), [%d, %d]\n", text_item.msg.get(),	text_item.tex_rect.top, text_item.tex_rect.top + height);
		//ZZ_LOG("font: draw_text_prim(%s), [%d, %d, %d, %d]\n",
		//	text_item.msg.get(),
		//	new_rect.left, new_rect.top, new_rect.right, new_rect.bottom);

		DWORD frontcolor = 0xFFFFFFFF;

		if (FAILED(hr = _draw_text(
			sprite,
			text_item.msg.get(), -1,
			&new_rect, 
			text_item.format,
			frontcolor )))
		{
			ZZ_LOG("font_d3d: DrawText() failed\n", zz_renderer_d3d::get_hresult_string(hr));
		}
		
		// restore states
		r->enable_zbuffer(true);
		r->enable_zwrite(true);
	}
	else {
		RECT rect = text_item.rect;
		if (FAILED(hr = _draw_text(
			sprite,
			text_item.msg.get(), -1,
			&rect, 
			text_item.format,
			text_item.color )))
		{
			ZZ_LOG("font_d3d: DrawText() failed\n", zz_renderer_d3d::get_hresult_string(hr));
		}
	}

	if (!text_item.use_sprite) { // end sprite
		r->end_sprite();
	}
}