Page 1 of 1

Crazy Calculations ... why?

Posted: Sun Feb 15, 2015 3:04 am
by Thade

Code: Select all

    GroundMesh=LoadMesh(-1, "terrain0101gr.mesh")
    GroundEntity=CreateEntity(-1, MeshID(GroundMesh), MaterialID(GroundMaterial), 0,0,0,1)
    SizeX.f=(EntityBoundingBox(GroundEntity, #PB_Entity_MaxBoundingBoxX | #PB_Entity_LocalBoundingBox) - EntityBoundingBox(GroundEntity, #PB_Entity_MinBoundingBoxX | #PB_Entity_LocalBoundingBox))
    SizeXA.f=(EntityBoundingBox(GroundEntity, #PB_Entity_MaxBoundingBoxX) - EntityBoundingBox(GroundEntity, #PB_Entity_MinBoundingBoxX))
    ScaleX.f=1024.0 / SizeX
    Debug SizeX
    Debug SizeXA
    Debug ScaleX
    ScaleEntity(GroundEntity, ScaleX, ScaleX, ScaleX)
    SizeX.f=(EntityBoundingBox(GroundEntity, #PB_Entity_MaxBoundingBoxX | #PB_Entity_LocalBoundingBox) - EntityBoundingBox(GroundEntity, #PB_Entity_MinBoundingBoxX | #PB_Entity_LocalBoundingBox))
    SizeXA.f=(EntityBoundingBox(GroundEntity, #PB_Entity_MaxBoundingBoxX) - EntityBoundingBox(GroundEntity, #PB_Entity_MinBoundingBoxX))
    Debug SizeX
    Debug SizeXA
Debug Results:
510.10809326171875
1.0
2.00741767883301
510.10809326171875
1.0

Code: Select all

      Debug "X="+StrF(EntityX(TRexEntity),2)+"  Y="+StrF(EntityY(TRexEntity),2)+"  Z="+StrF(EntityZ(TRexEntity),2)
    SizeX.f=(EntityBoundingBox(GroundEntity, #PB_Entity_MaxBoundingBoxX | #PB_Entity_LocalBoundingBox) - EntityBoundingBox(GroundEntity, #PB_Entity_MinBoundingBoxX | #PB_Entity_LocalBoundingBox))
    SizeXA.f=(EntityBoundingBox(GroundEntity, #PB_Entity_MaxBoundingBoxX) - EntityBoundingBox(GroundEntity, #PB_Entity_MinBoundingBoxX))
    Debug SizeX
    Debug SizeXA
This Code is repeated after RenderWorld

Debug Results
X=499.43 Y=9.00 Z=-501.21
510.10809326171875
1024.0

But the Corners are exact 500, 500 -500,500 etc.
They should be 512, 512 etc.
When I move the Model further than 502 (ModelBoundingBox 4x12 in meters) at the edges lets say to 511.9, 511.9 it falls down into the deep of virtual space

The point is: I made an Array where I placed Trees and Plants - but they did not fit exactly with my calcutated Positions. they are some Meters away as further they are placed to the edges

Actually the World Positions are 512,512 but it needs another Function to get them ...

Code: Select all

      ConvertLocalToWorldPosition(EntityID(TRexEntity), EntityX(TRexEntity), EntityY(TRexEntity), EntityZ(TRexEntity))
      Debug GetX()
      Debug GetY()
      Debug GetZ()
Debug Result (combined with the *Local/Absolute* Positions) XYZ added manually:

X=501.04 Y=72.15 Z=-501.51
P=0.00 Y=-22.00 R=0.00
X = 519.8310546875
Y = 74.22801208496094
Z = -509.49676513671875

And even that is not the last word as seen ... there must be at least another calculation to calculate Model and LandscapeMesh (No Terrain) Position that they fit ...

Was there really no way to solve this more elegant?


http://www.rrsoftware.net/uploads/Forum ... 035702.jpg
........................
PS to Forum Admin:
Is it not wanted to see images? As you can see, the link to the image works. When I add the img /img tags I get the message that the dimensions of the image could not be determined and I cannot submit this post.
No difference if its png or jpg

Re: Crazy Calculations ... why?

Posted: Sun Feb 15, 2015 10:13 am
by Bananenfreak
You should write an small introduction what you want to do before naming it "Crazy Calculations ... why?".

What I think you want to do is a borderline for physical objects, so they can´t fall off your world?
Just in time, I have to take the same decision.

Solutions:
- Make world round (Only a joke :D)
- A giant static cuboid round the world. Standard is x=1, y=1 and z=1, so you can scale it easy for your world. This giant static cube is hidden, so the physicsbody works, but the cube itself isn´t rendered.
- Every cycle you have to go through all of your physical entities and get the Position where they are.

So, I think solution no.2 is the right solution. But I think it doesn´t work properly, because whenever the bordercube goes to sleep, entities will fall through it. If anyone knows an easier way to get worldborders, please write it down. Thanks :)

Local-World-positions:
I think for worldpositions, x=0, y=0 and z=0 is your origin.
For localpositions, the origin of your object is the origin.
What you get is a vector from the actual origin to the Point you name (for example: #PB_Entity_MaxBoundingBoxX)

Re: Crazy Calculations ... why?

Posted: Sun Feb 15, 2015 6:47 pm
by Thade
Bananenfreak wrote:You should write an small introduction what you want to do before naming it "Crazy Calculations ... why?".
No I should not.
Bananenfreak wrote:What I think you want to do is a borderline for physical objects, so they can´t fall off your world?
No. You misunderstood completely what its about. :)

Actually I had a very long reply written already. I deleted it. It wouldn't be helpful anyway.
So I let it stand as it was meant: Don't rely while you work with PB3D (coming from other engines) on what you think you have calculated concerning World- and Local- and Absolute-Positions ... without checking you will in most cases be surprised about the results.

Is it not crazy that all functions concerning entity movement positioning and scaling working with absolute values are different from world values? When a mesh has an absolute size of 1000 Units its size is 1024 in World Units? But world units are never used with these functions ... And absolute is not absolute in PB
It is like saying our earth has a diameter of 20000 kilometers but we calculate with 12742 kilometers ... your absolute value may be 20000 but my absolute value is 12742 ...

Re: Crazy Calculations ... why?

Posted: Sun Feb 15, 2015 7:45 pm
by Little John
Repeat
Thade wrote:
Bananenfreak wrote:You should write an small introduction what you want to do before naming it "Crazy Calculations ... why?".
No I should not.
Thade wrote:
Bananenfreak wrote:What I think you want to do is a borderline for physical objects, so they can´t fall off your world?
No. You misunderstood completely what its about. :)
ForEver


:lol: