Hello
Im having some issues manipulating the matrix of my Live2D model in cocos2d-x. Let me explain what I want to achieve :
- I want to be able to position my Live2D model using Cocos2D X and Y coordinates.
- I want the model to scale from one screen size to another
For example, when im working in my design resolution (1024*768) I'll specify that my model is drawn at X=350 and Y=768 (that's just an example with random value).
So, I want the render on smaller and bigger resolution to be the same as what I see when Im in 1024*768.
What I have so far :
float scx = (2 / live2DModel->getCanvasWidth()); //Rate of magnification of x axis
float scy = (-2 / live2DModel->getCanvasWidth()); //Rate of magnification of y axis
float x = 0; //X from 0 to 1024 (design resolution width)
float y = 200; //Y from 0 to 768 (design resolution height)
float rto = (float)w / h;
float posx = (scx * x); //Tying to scale X
float posy = (scy * y); //Trying to scale Y
float matrix[] = {
scx , 0 , 0 , 0 ,
0 , scy , 0 , 0 ,
0, 0, rto, 0,
posx, posy, 0, rto
};
((Live2DModelOpenGL*)live2DModel)->setMatrix(ModelMatrix.getArray());
All my game scaling is defined by CC_CONTENT_SCALE_FACTOR(), which is calculated by cocos2d.
How can I achieve the desired behaviour ?
Im not sure I understand correctly why we need to set scx and scy to those value, why do we use 2 and -2 ? shouldn't we use the scale factor ?
Thanks you