About Store Forum Documentation Contact



Post Reply 
[SOLVED] Scale resets from custom in WE to 1/1/1 in Game
Author Message
Fluxor Offline
Member

Post: #1
[SOLVED] Scale resets from custom in WE to 1/1/1 in Game
Hey there.

The Objects are manually scaled larger in the World Editor.
When I run the game, they are all scaled back to 1/1/1 default.

When I do the scaling in the Object editor, this works.
I just wonder if it is possible to get the individual scales from the World
Editor to be used in game.

Can anyone tell me what I do wrong here?


Code:
class StaticGeo : public Game.Static
{

public:  
  
   StaticGeo ::StaticGeo(){};
   virtual StaticGeo::~StaticGeo(){};
  
   virtual void create(Object &obj);
   virtual void drawShadow();
   virtual Bool update();
   virtual UInt drawPrepare();
  
   virtual Vec    pos      ()                      {return _matrix.pos;}
   virtual void   pos      (C Vec &pos)      {_matrix.pos = pos; _scaledMatrix.pos = pos;}
   virtual Matrix matrix ()                      {return _matrix;}
   virtual void   matrix(C Matrix &matrix){_matrix = matrix; _scaledMatrix=matrix;

private:
  
   Matrix         _matrix,  _scaledMatrix;
   MeshPtr        mesh;
   MaterialPtr    material;
   Actor          actor;
   PhysBodyPtr    phys;
   PathObstacle   obstacle;
  
   Vec            position;  
   Vec            scale;
   Vec2           texScale;
}


void StaticGeo::create(Object &obj)
{
   super.create(obj);

   scale = obj.scale3();
   mesh = obj.mesh();
   phys = obj.phys();
   phys->density=0;
   _matrix = obj.matrixFinal().normalize();
   _scaledMatrix = _matrix;
   _scaledMatrix.scaleOrnL(scale);
  
   if(phys)
   {
      actor.create(*phys, 1, true).matrix(_matrix);
      actor.obj(this);
      actor.matrix(_scaledMatrix);
   }
   mesh->texScale(texScale);
}


Bool StaticGeo::update()
{
   return 1;
}

UInt StaticGeo::drawPrepare()
{
   actor.draw();
   if(mesh)
   {
      SetVariation(1);
      mesh->draw(actor.matrix());
      T.pos(actor.matrix().pos);
   }
   return 1;
}


void StaticGeo::drawShadow()
{
   if(mesh)
   {
      mesh->drawShadow(actor.matrix());
   }
}
(This post was last modified: 08-29-2021 06:26 PM by Fluxor.)
08-26-2021 03:40 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #2
RE: Scale resets from custom in WE to 1/1/1 in Game
yes its because you call the object and not the instance on the map.

the logical ways to get the one generated on the map is through the loading of the world. if this is not something you want, there might be another way, but lets assume you do

Creating the game world detail before loading it
Code:
Game.World.mode(Game.WORLD_STREAM).activeRange(D.viewRange()).setObjType(YourCla​ss, OBJ_CLASS_YOUREDITOROBJCLASS);

Your map with all object from the map with the create virtual function
Code:
Game.ObjMap<YourClass> YourNameInstance;
class YourClass: Game.Static
{
   virtual void create(Object &obj)
   {
      super.create(obj);
   }
}

That should work
08-26-2021 07:24 PM
Find all posts by this user Quote this message in a reply
Fluxor Offline
Member

Post: #3
RE: Scale resets from custom in WE to 1/1/1 in Game
Hmm... But I have this kinda already... always...
So I do it exactly how you described it, no?
Anything I am missing here?


Code:
Game.ObjMap<     Player> player;
Game.ObjMap<Game.ObjLightPoint> lights;
Game.ObjMap<StaticGeo> staticGeo;

---------------------------------------------------

   Game.World.activeRange(D.viewRange())

             .setObjType(staticGeo, OBJ_BLOCKS)
             .setObjType(player,  OBJ_PLAYER)
             .setObjType(lights,  OBJ_LIGHT_POINT);
   Game.World.New(UID(xxx-xxx-xxx));
   if(Game.World.settings().environment)Game.World.settings().environment->set();
08-26-2021 08:46 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #4
RE: Scale resets from custom in WE to 1/1/1 in Game
that seems right ye, is your object set as OBJ_BLOCKS under the Class parameters of the obj ?

it might be this as well : scale = obj.scale3();

try to use the matrix scale instead, might because obj.scale3(); mightfrom the obj directly, which might not be the world scale
(This post was last modified: 08-26-2021 10:49 PM by RedcrowProd.)
08-26-2021 09:32 PM
Find all posts by this user Quote this message in a reply
Fluxor Offline
Member

Post: #5
RE: Scale resets from custom in WE to 1/1/1 in Game
Hmm. I thought that was it. But still, no dice...

Even if I put in some random numbers into the scale variable, it does nothing.

So I think something else is wrong here... Not sure though.





Ok, so when:
Code:
scale = 3;
_scaledMatrix.scaleOrnL(scale)

logging _scaledMatrix.scale() indeed returns 3.
but actor.matrix(_scaledMatrix) still returns 1.

And because I do this:
Code:
mesh->draw(actor.matrix());
The mesh doesn't scale to anything other than 1.
So why is actor.matrix still 1, if it takes the _scaledMatrix, which is 3?

That isolates the problem, now I just need to figure out why that is... smile

I think I've read somewhere that actors can't be scaled, but I thought this is only true at runtime, not at creation, right?
(This post was last modified: 08-26-2021 10:19 PM by Fluxor.)
08-26-2021 10:05 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #6
RE: Scale resets from custom in WE to 1/1/1 in Game
oh i see,

no actor cannot be scaled outside of the .create() function.

so you should do this instead:

obj.actor.create(*obj.base()->phys(), 1, scale);

if you want to edit the scale later on, you need to delete the actor and re-create it i believe.

the other thing you could do is not use actor.matrix() but obj.matrix() ?
(This post was last modified: 08-26-2021 10:55 PM by RedcrowProd.)
08-26-2021 10:49 PM
Find all posts by this user Quote this message in a reply
Fluxor Offline
Member

Post: #7
RE: Scale resets from custom in WE to 1/1/1 in Game
Tested all variations now I believe.
No matter what they are always in the same scale.
It's either all 1 or all to the set "scale". No individual sizes from the WE.

Never crossed my mind that this could be so darn tricky...
08-26-2021 11:36 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #8
RE: Scale resets from custom in WE to 1/1/1 in Game
Matrix orn ?
08-26-2021 11:56 PM
Find all posts by this user Quote this message in a reply
Fluxor Offline
Member

Post: #9
RE: Scale resets from custom in WE to 1/1/1 in Game
Can try this too, however I think this goes deeper...
I have applied a checker-texture to the base object and
scaled the UVs differently via per-instance parameter and code
Code:
if(Param *p=obj.findParam("TexScale")) texScale=p.asVec2();
mesh->texScale(texScale);

and all end up the same... But still different as if I do
Code:
if(Param *p=base->findParam("TexScale")) texScale=p.asVec2();
mesh->texScale(texScale);
which also makes all of them look the same, but exactly like they should
based on the parameters in the base object params.

I logged the output of each individual texScale. They are all different,
however they all still look identical as if they are set to the exact same parameter values,
but they aren't and in my mind they shouldn't.



EDIT: The first original problem seems solved.
It came down to a combination of things you mentioned.
I need to declutter the code first to get a better overview ...
but basically it came down to this:

Code:
_matrix = obj.matrixFinal().normalize();
_scaledMatrix = _matrix;
_scaledMatrix.scaleOrnL(scale);
actor.create(*phys, 1, scale);
actor.matrix(_scaledMatrix);
mesh->draw(_scaledMatrix);

Seems a bit convoluted, but seems to work.
Funny thing is when I draw actor.matrix() everything still is the same size,
but the collisions still are correct (individual sizes) with the solution above.
Not sure how that works, but hey.

And I think I will open up an extra thread for this UV-texture scaling-thing
when I can't find a solution for this tomorrow.
(This post was last modified: 08-27-2021 01:24 AM by Fluxor.)
08-27-2021 12:22 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #10
RE: Scale resets from custom in WE to 1/1/1 in Game
actor.matrix(_scaledMatrix);
only normalized matrices should be passed to actor (no scale)
08-27-2021 03:11 AM
Find all posts by this user Quote this message in a reply
Post Reply