RF and physics

Programming Reality Factory and Genesis3D.
Post Reply
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

Very strange...
You placed the new genesis lib + dll under the RF directory?
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

I re-started from scratch. This time commented out all the block you've added. The result is the same. 38 warnings 0 error executable exp lib and ilk created and moved in te proper directory. I've got this error on execution:

Code: Select all

Program: RealityFactory.exe
file: afxwin.inl 
line: 22
Then, using your genesis.h, I re-build the genesis.lib and the genesis.dll and I re-compiled the RF. Nothing to do.
Don't think about it. I only tried to play with your entities but I didn't have mind to do anything serious. When I saw myself finding some difficulties I though: :) hey! I can make something useful, helping the other newbies to build the source. ehm...
Now stop, this thread seems to go off-topic: from physic to compile... :wink:
User avatar
animatrix
Posts: 134
Joined: Thu Jul 07, 2005 10:51 pm

Post by animatrix »

Might be in the wrong place but the physics demo was AWSOME, just got it and tried it :D
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

I've added a few more script commands to:
- do world ray collision testing => very nice to eg slow down a UFO when landing...
- get physics body name linked to an entity
- get entity name linked to a physics body
With these last commands you can use the physics script commands AND the entity script commands and apply them on 1 real object in your world.
So all the goodies you had for pawns are now also usable on a physics body, eg like attaching a flame, starting a sound, use triggers etc...
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

Testing the physic I always had problems with the EntityName so I always used the RigidBodyEntity linked to a pawn (using the Pawn zEntitytyName instead of the act filename). I don't have no more zEntityName problems because the physic entity name is the Pawn name and I can use the AttachCamera() command, for example. All the GetDistanceTo.. etc... commands works fine but none of the movement command (as anyone could expect).

the problem for me is still to have some dimple command to completely rotate (bbox, object...) the entity. I have to admit that the physicsVehicle algorithm to steer the whell is non-understandable for me :oops: . I have some method in my head but "why re-inventing the wheel?" (in all sense...)
Some idea by you (even mixing pawn and physics script)?

Post Scriptum: the phApplyImpulse doesn't work.. .(unknow method)
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

The Alpha release of RF with Physics still suffers from a rotation bug.
In the new release (which I will post in a few days) this is resolved !

To let a physics object rotate, you can simply use the ApplyTwist command or you use a motor command (the speed is then depending on the torque)
This PhysicsVehicle entity offers you a body you can stear, separate wheels (linked to a body) you can stear left and right and that stay fixed to the body. Notice that you can set the steer angles (now +/-45degC, but you could also change this into +/-180degC)

Is this not doing what you want?
If not, better send me a drawing of what movements you try to achieve
My Email is Aarnout@gmail.com

PS: the RayCollission is more then just measuring distance. It can intersect with water, an solid brush, and empth brush, a model, an actor etc... all free choosable :-)
Very nice eg. to detect you are over a see and want to continue flying rather then already landing...
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

Is this not doing what you want?
If not, better send me a drawing of what movements you try to achieve
My Email is Aarnout@gmail.com
:
yes it's just what i want the problem is that i don't know exactly how : my fault, the physics is good, no doubt. Now i'm curious about your tutorials about motor and sensor. I want to try to build some machine, even a vehicle with 6 wheels or something...
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

As a starting point, put this scipt into a PhysicsScript + run it
This demo activates the motor property and shows how to use hinge

The actors used where part of the RF with physics alpha release

The rotations will do crazy, but in the coming release (it's progressing well, need still a few days) this rotation is solved

{

PosX [0]
PosY [-50]
PosZ [0]
Dx [0]
Dy [0]
Dz [0]
Mass [0.5]
Scale [1]
ALPHA [255]
MyBodyId [-1]
SenId1 [-1]
RocketId [-1]
KeyReleased [true]
Depth [0.0]

Body
{
Body0 [0]
Body1 [0]
Body2 [0]
Body3 [0]
Body4 [0]
Body5 [0]
Body6 [0]
Body7 [0]
Body8 [0]
Body9 [0]
Body10 [0]
Body11 [0]
Body12 [0]
Body13 [0]
Body14 [0]
Body15 [0]
Body16 [0]
Body17 [0]
Body18 [0]
Body19 [0]
Body20 [0]
}

Init[ () //Is excecuted only once.
{
Console(true);
PosX = 200;
PosY = -70;
PosZ = -200;
DefineMaterial(1, 0.2, 0.5);
Body[0] = CreateRigidBody("Body0", "box_centered.act",2,0.5,1, 255, PosX, PosY, PosZ, 0,0,0, 0,0,0 , true, ALPHA, "Box 0", 1, 0,0,0,0, Mass);
Dx = GetBodyBBox(Body[0], 0);
Dy = GetBodyBBox(Body[0], 1);
Dz = GetBodyBBox(Body[0], 2);
Body[1] = CreateRigidBody("Body1", "box_centered.act", 1,1,0.25, 255, PosX+Dx*0.4, PosY-Dy*0.3, PosZ+Dz*0.55,0,0,0, 0,0,0, true, ALPHA, "Box 0", 0, 0,0,0,0, Mass);
Body[2] = CreateRigidBody("Body1", "box_centered.act", 1,1,0.25, 255, PosX+Dx*0.4, PosY-Dy*0.3, PosZ-Dz*0.55,0,0,0, 0,0,0, true, ALPHA, "Box 0", 0, 0,0,0,0, Mass);
Body[3] = CreateRigidBody("Body1", "box_centered.act", 1,1,0.25, 255, PosX-Dx*0.4, PosY-Dy*0.3, PosZ+Dz*0.55,0,0,0, 0,0,0, true, ALPHA, "Box 0", 0, 0,0,0,0, Mass);
Body[4] = CreateRigidBody("Body1", "box_centered.act", 1,1,0.25, 255, PosX-Dx*0.4, PosY-Dy*0.3, PosZ-Dz*0.55,0,0,0, 0,0,0, true, ALPHA, "Box 0", 0, 0,0,0,0, Mass);
CreateHingeJoint(Body[0], Body[1], PosX+Dx*0.4, PosY-Dy*0.3, PosZ+Dz*0.55, -180, 180, -180, 180, Dx, 0, 1, 50);
CreateHingeJoint(Body[0], Body[2], PosX+Dx*0.4, PosY-Dy*0.3, PosZ-Dz*0.55, -180, 180, -180, 180, Dx, 0, 1, 50);
CreateHingeJoint(Body[0], Body[3], PosX-Dx*0.4, PosY-Dy*0.3, PosZ+Dz*0.55, -180, 180, -180, 180, Dx, 0, 1, 50);
CreateHingeJoint(Body[0], Body[4], PosX-Dx*0.4, PosY-Dy*0.3, PosZ-Dz*0.55, -180, 180, -180, 180, Dx, 0, 1, 50);
} ]

For understanding all the parameters used, please refer to the docu in an earlier post in this thread
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

Post Scriptum: the phApplyImpulse doesn't work.. .(unknow method)
Try phApplyImpulseForce
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

All the GetDistanceTo.. etc... commands works fine but none of the movement command (as anyone could expect).
Above message gave me an idea...
We can use all pawn commands, when physics are not used...
I've added a script command that can remove 1 pawn at a time form the physics engine, and later you can put it back => this allows pwans to still use the normal pawn movement commands, and afterwards place them back into the physics system

I tried it, and indeed, it works, except for 1 problem: the origin of a pawn in RF is different then the origin in physics... (but should be solvable)
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

've added a script command that can remove 1 pawn at a time form the physics engine, and later you can put it back => this allows pwans to still use the normal pawn movement commands, and afterwards place them back into the physics system
Yeah! 8)
____
To let a physics object rotate, you can simply use the ApplyTwist command or you use a motor command (the speed is then depending on the torque)
This PhysicsVehicle entity offers you a body you can stear, separate wheels (linked to a body) you can stear left and right and that stay fixed to the body. Notice that you can set the steer angles (now +/-45degC, but you could also change this into +/-180degC)

Is this not doing what you want?
If not, better send me a drawing of what movements you try to achieve
I'll try to explain myself better in future: I don't want exactly to "rotate an object" I want to simply tell an object to rotate in order to "face another direction". Simply the pawn low level self.ideal_yaw self.current_yaw self.ideal_yaw self.yaw_speed Changeyaw() commands. If you use this commands to rotate a pawn (for example self.ideal_yaw= 30 degrees) and then you apply a ForceForward command, the pawn will go forward in the reached direction, that is self.current_yaw (in the example 30 degrees if he has reached that yaw). actually the physicsforces in the physics system are applied using "absolute coordinates". I want to find a way to have "relative coordinates" in respect of the actual object facing direction.
The physicsvehicle instead use a "relative coordinates" method 'cause it let the wheels rotate from 0 to 45° degrees (left and right) in respect of the chassis actual direction and the force is applied accordingly to the current direction of the wheels and the chassis.

I have some idea to simulate this process, storing manually that variables in a script (current_yaw, ideal_yaw, yaw_speed) but I don't think this is the best way to do it, so I ask you.
Anyway the best method is alway to test the questions with examples so i'll try to create something to show you. I hope that this time I was able to let you understand me :wink: .
________
the script example works just great! Thanks nout!
The documentation is still incomplete, I know, but:
CreateHingeJoint(BodyId1, BodyId2, Pos, MinLim1, MaxLim1, MinLim2, MaxLim2, JointLength)
A Hinge joint is a joint that works like the door of a car. Body1 is the car and body 2 is the car door and the joint is in between. Joints are "calculated" restrictions in movement, and are maintained as good as possible, but not guaranteed. Joints therefore should never be used to glue 2 bodies into a new more complex body. For this use the ExtendRigidBody or ExtendStaticBody command.

BodyId1: The IdNr of the body to apply the joint to. This IdNr requires to be filled in and to exists
BodyId2: If BodyId2 < 0 then a joint is made between the Body BodyId1 and a fictive point in world space defined by Pos. If BodyId2 >= 0, then a joint is made between the 2 bodies BodyId1 and BodyId2.
Pos: the position of the origin of rotation axis of the joint, in world coordinates
MinRot, MaxRot: minimum and maximum rotation angles you allow the joint to rotate around the joint axis expressed in degrees
MinTwis, MaxTwist: minimum and maximum twist you allow the joint expressed in degrees
JointLength: the length of the joint
MotorType: An integer that defines the motor type. if 0, a velocity motor is assigned. If 1, a TBD motor is assigned. Any other value disables the motor.
DesiredValue: The wanted speed of the motor
MaxForce: The maximum force applied to reach the desired value
It could be:
CreateHingeJoint(BodyId1, BodyId2, Pos, MinLim1, MaxLim1, MinLim2, MaxLim2, JointLength,MotorType,DesiredValue,MaxForce)

some questions: I don't nderstand at all the mix/max limits 1 and 2 Min/MaxTwinst Min/Max Rot.
TBD motor?
Is possible to use a command to apply to start/stop applying the torque? Because it will solve most of the rotation/torque direcion problems we discussed in this topic...
Great work Nout, as always!
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

federico,

Yes, the documentation is behind on the real implementation, and you are right about the syntax for the Hinge command

The min and max limits restrict the rotation of the hinge joint
Min can be -180deg, Max goes up to +180deg
The second min and max are as far as I know not yet used, and might be used in future releases of Tokamak. For some joints, 2 restrictions are needed

Try this script and play with the min and max values of the hinge and all will be suddenly clear. I've in this example used restrictions for the angle to 15deg, which makes it impossible for the chain of boxes to stretch. Try also the shoot on the chain, and you see the restrictions taking place.
Also check what happens if you un-comment the last hinge. The -1 instead of a body name connect the joint to the position in the world.

{

PosX [0]
PosY [-50]
PosZ [0]
Dx [0]
Dy [0]
Dz [0]
Mass [0.5]
Scale [1]
ALPHA [255]
MyBodyId [-1]
SenId1 [-1]
RocketId [-1]
KeyReleased [true]
Depth [0.0]

Body
{
Body0 [0]
Body1 [0]
Body2 [0]
Body3 [0]
Body4 [0]
Body5 [0]
Body6 [0]
Body7 [0]
Body8 [0]
Body9 [0]
Body10 [0]
Body11 [0]
Body12 [0]
Body13 [0]
Body14 [0]
Body15 [0]
Body16 [0]
Body17 [0]
Body18 [0]
Body19 [0]
Body20 [0]
}

Init[ () //Is excecuted only once. We calls 4 orders and initialize them
{
Console(true);
Chain();
} ]


Chain[ ()
{
PosX = 0;
PosY = 100;
PosZ = 0;
DefineMaterial(1, 0.2, 0.5);
Body[0] = CreateRigidBody("B0", "box_centered.act",1,0.3,1, 255, PosX, PosY, PosZ, 0,0,0, 0,0,0, true, ALPHA, "Box 0", 1, 0,0,0,0, Mass);
Dx = GetBodyBBox(Body[0], 0);
CreateHingeJoint(Body[0], -1, PosX-(Dx*0.5), PosY, PosZ, -15, 15, -15, 15, Dx, -1, 0, 0);
for i=1 to 5
{
Body = CreateRigidBody("B"#i, "box_centered.act",1,0.3,1, 255, PosX+(Dx*i), PosY, PosZ, 0,0,0, 0,0,0, true, ALPHA, "Box 0", 1, 0,0,0,0, Mass);
CreateHingeJoint(Body[i-1], Body, PosX+(Dx*(i-0.5)), PosY, PosZ, -15, 15, -15, 15, Dx, -1, 0, 0);
}
//CreateHingeJoint(Body, -1, PosX+(Dx*(i+0.5)), PosY, PosZ, -15, 15, -15, 15, Dx, -1, 0, 0);
} ]

}

The motor is faily new. I'm not much further then you are on playing with this feature + the docs in Tokamak are close to zero...
Experimenting or looking up data form other engines will be the way to go

The "rotation" you talk about:
All rigid bodies you make are using absolute coordinates and are fully controlled by the physics. So if you want them to make a certain movement, you need put the correct forces and troques on the body to realize this. You can do this with scripting, or with coding (you can do a lot more here, eg. like for the vehicle control)
Any exteded body you connect to a body is always in releative coordinates, relative to the main body. You can let extended parts move or rotate by scripting or coding
I don't know if this answers your question and an example or drawing is welcome
MakerOfGames
Posts: 866
Joined: Fri Jul 08, 2005 4:27 am
Location: PA, USA

Post by MakerOfGames »

I have not downloaded the current test of the physics system and I have a question. Can the physics system work with joints already placed on objects? For example, if I made a box with a hinge on one side that has preset limitations on rotation in my 3D modeling program. Can the physics system detect this and give proper attributes to the joint with some simple code on my part? or will I have to program the box to create a joint at the position I want and then give the joint limitations? I need to know how I will have to go about making all my multiple object actors(such as humans for rag doll, and car doors and stuff. None of the actors are solid meshes, they will consist of chunks like in early Nintendo 64 and playstation games. The best example of this charactor constuction is in super smash brothers from the N64)
Think outside the box.
To go on an adventure, one must discard the comforts and safety of the known and trusted.
User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR »

i dont believe that would be possible currently, according to my knowledge of how stuff carries over... it would be with a semi-simple change to the .act file format and all related loaders, exporters, etc. though.
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

Today no automatic properties for joints etc are calculated
Today you need to define hinges etc... by scripting
The scripting is "simplified" by using coordinates relative to the body + by using Dx, Dy and Dz with scale factors
Dx, Dy and Dz can be requested from each body and represent the dimensions of the bounding box for that body. This makes it a lot easier.
An example: you want to connect an arm at the corps at 75% height of the corpse and at the extreem of the width of the corps.
This is pseudo-scripted as

Define the corps "body" at psotion PosX, PosY, PosZ (this point is always in the center of the body)
Ask Dx, Dy and Dz from the corps
Define the arm "body"
Place a hinge at the cops (PosX-0.5*Dx, PosY+0.375*Dy, PosZ)
Define the limits of the hinge

Have a look to the script examples earlier in this thread and you will recognize back what I write here
Post Reply