Hassan,
So I was testing what you gave and I have ran into some problems. First off in my project I am already scaling some of my objects when I create them. My constructor kind of looks like this:
Box::Box (int Xpos,int Ypos,float SpriteScale,int BoxID,int SpriteID,b2World* world,Camera* GameCamera)
I have it take a reference to the camera and every time I create a box it adds it to the render list. Now as you can see I have a sprite scale there already and a good majority of my sprites are using this scale in order to scale correctly. Here is my box class and its update with your code. a few things that I had to change to get it to work with a zoom of 0.
Now where I am confused is this line:
m_xOffset = (m_BaseWidth - m_SpriteWidth)/2;
m_yOffset = (m_BaseHeight - m_SpriteHeight)/2;
I had to add m_SpriteWidth and Height because for some reason when I used dbSpriteWidth and height it was giving me some crazy numbers like in the thousands. So I set it ahead of time. If you could just look through some of the code and maybe see something that I am doing wrong I would greatly appreciate it.
#include "Box.h"
Box::Box (int Xpos,int Ypos,float SpriteScale,int BoxID,int SpriteID,b2World* world,Camera* GameCamera)
{
m_posX = Xpos;
m_posY = Ypos;
m_SpriteID = SpriteID;
m_BoxID = BoxID;
m_scale = SpriteScale/100;
bIsAlive = true;
bCanDelete = true;
m_FilterID = 0x0001;
dbSprite(m_BoxID,0,0,m_SpriteID);
m_SpriteWidth = dbSpriteWidth(m_BoxID);
m_SpriteHeight = dbSpriteHeight(m_BoxID);
m_BaseWidth = dbSpriteWidth(m_BoxID);
m_BaseHeight = dbSpriteHeight(m_BoxID);
dbSizeSprite(m_BoxID,m_BaseWidth * m_scale,m_BaseHeight * m_scale);
dbOffsetSprite(m_BoxID,dbSpriteWidth(m_BoxID)/2,dbSpriteHeight(m_BoxID)/2);
p_bodyDef.userData = this;
p_bodyDef.position.Set(m_posX /b2PixelRatio, m_posY /b2PixelRatio);
p_body = world->CreateBody(&p_bodyDef);
p_shapeDef.SetAsBox((dbSpriteWidth(m_BoxID)/b2PixelRatio)/2.0f, (dbSpriteHeight(m_BoxID)/b2PixelRatio)/2.0f);
p_shapeDef.filter.categoryBits = m_FilterID;
p_body->CreateShape(&p_shapeDef);
GameCamera->RenderList.push_back(this);
}
void GameObject::Update(b2World* world,Camera* GameCamera,CKeyboard* keyboard, CMouse* mouse)
{
if (bIsAlive)
{
m_angle = p_body->GetAngle();
m_position = p_body->GetPosition();
m_position.x *= b2PixelRatio;
m_position.y *= b2PixelRatio;
m_xOffset = (m_BaseWidth - m_SpriteWidth)/2;
m_yOffset = (m_BaseHeight - m_SpriteHeight)/2;
float drawX = m_position.x + ((800/2)- GameCamera->GetPosition().x) + m_xOffset;
float drawY = m_position.y + ((600/2)- GameCamera->GetPosition().y) + m_yOffset;
m_angle *= (180.0 / 3.141592653589793238);
dbSprite(m_BoxID,drawX,drawY,m_SpriteID);
dbSizeSprite(m_BoxID,(m_BaseWidth+ GameCamera->ZoomValue)*m_scale,(m_BaseHeight+ GameCamera->ZoomValue)*m_scale);
dbRotateSprite(m_BoxID, m_angle);
}
else
{
this->Delete(world,GameCamera);
}
}
As I said before it works when my zoom amount is just zero but when you start to put in a zoom amount it doesn't work.