IrrNewt irrlicht\newton framework >> SVN access
Just my note to point 7. Imho declaring locals near the place they are used instead of at the beginning of a function is actually better.
By far the most often made programming errors are assignment errors. Thus it is good to keep the scope of each variable small and use const wherever appropriate. You can only use const for a local, if you initialise it immediatly, if the variable is to hold derived values, this is not possible at the beginning of the function. Also you can't possibly misassign a value to the variable before you declare it, so you are less likely to make this error when you declare the variable further down in the code.
And it is good for readability, since you have declaration and use in immediate vicinity.
By far the most often made programming errors are assignment errors. Thus it is good to keep the scope of each variable small and use const wherever appropriate. You can only use const for a local, if you initialise it immediatly, if the variable is to hold derived values, this is not possible at the beginning of the function. Also you can't possibly misassign a value to the variable before you declare it, so you are less likely to make this error when you declare the variable further down in the code.
And it is good for readability, since you have declaration and use in immediate vicinity.
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
when i saied "there is not a class to" I wanted to say "there is not a class in the standard c++ library wich contain a method to". But I don't see what's wrong using c functions. c++ is backward compatible5)I use C function 1 or 2 times altogether and only in the examples. For example I use a c function to convert a const char* to a w_chart*. There is not ANY class to do this, only this c function.
irrlicht's examples use printf to print a text out. printf is a c function and there isn't class to print out a text (printf("Please select the driver you want for this example:\n"\-- quake 3 map example)
@RapchikProgrammer: maybe you would like a structure for every thing? for example in addTire you would like to pass a structure wich contains tire info and not pass variables directy to the function? for example something like this:
Code: Select all
STireInfo i;
i.node=tire_scene_node;
i.sus_spring=tire_suspension_spring;
ITirePhysicsNode* t=car->addTire(i)
Code: Select all
ITirePhysicsNode* t=car->addTire(tire_scene_node,tire_suspension_spring)
If yes I think that have two thing
(a structure to define tire info (called 'i' in the example) and a class to management the tire (called 't'))
is not the best. But the advantage is that you define only some variables and leaves the other to default. But functions have also got default parameters. Set the parameters wich you need and leave the other to default. However I will set a default value for most possible parameters. Currently I don't know if the next release will use first solution or second solution...
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
Yea something like that is what i am thinking about! Like:
Its hassle free, i dont create many many variables to make one car, its not difficult for me to make several cars, i can make a quick car if i want to and its easy to handle this kind of coding!
Code: Select all
SCar car;
car.chasis.mass = 10f;
car.chasis.size = 2;
car.chasis.node = smgr->addCubeSceneNode();
car.tires.wheelRadius = 0.114f;
car.tires.wheelwidth = 0.1;
car.tires.mass = 1;
car.FLTire.node = smgr->addSphereSceneNode();
car.FRTire.node = smgr->addSphereSceneNode();
car.RLTire.node = smgr->addSphereSceneNode();
car.RRTire.node = smgr->addSphereSceneNode();
physics->addCar(car);
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
Another thing, instead of this, in the main loop;
How bout calling a function inside camera_body on each event?? Like in the beginning of the onevent code we can do like: camera_body->updateCamera instead of rotate_mouse ! And why have ab argument for mouse sensitivity when you call rotateFromMouse, instead of having a function, setSensitivity or something!
BTW I am also waiting to see changes in your program as i am currently trying to update iphysics features bymyself but it wont have the amount of features ur library has in a vry long time if it goes on like this! So will love to use your library for my game after its simple enough to be easily used tho!
Code: Select all
core::vector3df velocity;
if(up)
velocity+=camera_body->getDirectionPositionXY(core::vector3df(0,0,camera_speed));
if(down)
velocity+=camera_body->getDirectionPositionXY(core::vector3df(0,0,-camera_speed));
if(left)
velocity+=camera_body->getDirectionPositionXY(core::vector3df(-camera_speed,0,0));
if(right)
velocity+=camera_body->getDirectionPositionXY(core::vector3df(camera_speed,0,0));
camera_body->setVelocity(velocity);
BTW I am also waiting to see changes in your program as i am currently trying to update iphysics features bymyself but it wont have the amount of features ur library has in a vry long time if it goes on like this! So will love to use your library for my game after its simple enough to be easily used tho!
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
here are online full documentation. The documentation prived with irrnewt sdk is not full. I also include examples in the documentation (e.g. in the function CharacterController::getPositionDirectionY() i teach how all character controlling work on irrnewt and i integrate it with lots of examples)
In the documentation there are the follow functions\classes wich are not implemented yet in the current release, but will be implemented in the next release (maybe *, surely +)
new functions in the joint class +
body::set parent and getParent +
rotation constraint joint +
RagDoll and RagDollBone * (untested currently)
@RapchikProgrammer:
but you can write by yourself a struct (called STire) wich contain all parameters of addTire() function (see the documentation) and simply write a function like that:
you want a function that move and rotate the camera at the same time?
In the documentation there are the follow functions\classes wich are not implemented yet in the current release, but will be implemented in the next release (maybe *, surely +)
new functions in the joint class +
body::set parent and getParent +
rotation constraint joint +
RagDoll and RagDollBone * (untested currently)
@RapchikProgrammer:
probably I will insert both solution in the next release (struct that contain data, pass the struct to the function and passing variables directly to the function). who support the first solution?Its hassle free, i dont create many many variables to make one car, its not difficult for me to make several cars, i can make a quick car if i want to and its easy to handle this kind of coding!
but you can write by yourself a struct (called STire) wich contain all parameters of addTire() function (see the documentation) and simply write a function like that:
Code: Select all
newton::VehicleTire* myAddTire(newton::Vehicle* vehicle, STire tire) {
return vehicle->addTire(tire.scene_node,tire.offset,tire.suspension_spring);
}
thanksSo will love to use your library for my game after its simple enough to be easily used tho!
I don't understand. rotateFromMouse is a function wich take the SEvent struct and the mouse sensitive, so rotate the body based on the mouse movement.How bout calling a function inside camera_body on each event?? Like in the beginning of the onevent code we can do like: camera_body->updateCamera instead of rotate_mouse
you want a function that move and rotate the camera at the same time?
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
Ya, i can create but would it be easier if i dont have to make a structure and another layer over your physics library to have a better interfrace then having it all in the library! And about the mouse, i mean i have to do setvelocity on each keypress, why not just make one function thats called in OnEvent, which sets the movement and rotation of camera!
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
Next release will include:
-every class interface has the 'I' after its name and every struct the 'S'
-pass a struct wich contain data instead of pass data directly to the functions (for example a STire struct, SVehicleSimple)
-a dedicated interface for car (only a interface for vehicle simple currently)
-new functions ported from newton
-defines more short
-simpler examples
-a setMouseSensitive function in ICharacterController
-new functions in the joint class
-body::set parent and getParent
-rotation constraint joint
any other feature request?
-every class interface has the 'I' after its name and every struct the 'S'
-pass a struct wich contain data instead of pass data directly to the functions (for example a STire struct, SVehicleSimple)
-a dedicated interface for car (only a interface for vehicle simple currently)
-new functions ported from newton
-defines more short
-simpler examples
-a setMouseSensitive function in ICharacterController
-new functions in the joint class
-body::set parent and getParent
-rotation constraint joint
any other feature request?
a function wich set at the same time movement and the rotation? Wich takes a struct for define the keys (for example up key, down key)?And about the mouse, i mean i have to do setvelocity on each keypress, why not just make one function thats called in OnEvent, which sets the movement and rotation of camera!
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
hi. I would like to know if this code is simple for build a car or it can be simpler. If it can be simpler please tell me where. Thanks
Code: Select all
//create a car
void createCar() {
//STEP 1:CREATE CHASSIS BODY
chassis_p_node=p_world->createBodyAuto(chassis_node);
//set mass
chassis_p_node->setMass(chassis_mass);
//re calculate moment of inertia because we change the mass
chassis_p_node->autoCalcInertia();
//add gravity force (recursive)
chassis_p_node->addForceContinuous(core::vector3df(0,chassis_gravity_y_force,0));
//STEP 2: CREATE ALL TIRES SCENE NODE (don't positiong their)
irr::scene::ISceneNode* fr_wheel_node=createWheel();
irr::scene::ISceneNode* fl_wheel_node=createWheel();
irr::scene::ISceneNode* br_wheel_node=createWheel();
irr::scene::ISceneNode* bl_wheel_node=createWheel();
//STEP 3:BUILD CAR DATA
irr::newton::SCar car_data;
car_data.chassis_body=chassis_p_node;
car_data.fr_tire_node=fr_wheel_node;
car_data.fl_tire_node=fl_wheel_node;
car_data.br_tire_node=br_wheel_node;
car_data.bl_tire_node=bl_wheel_node;
//because in my wheel model file, the model is rotated of 90 degrees on X. Generally you don't need to do this
car_data.tires_body_scene_node_offset.rotation.X=-90;
//STEP 4: POSITIONG TIRES
p_world->getUtils()->calculateCarTiresPosition(
car_data,//the SCar struct
tire_offset//a vector3df wich is the position offset of the tires from chassis body
);
//STEP 5:CALCULATE TIRES WIDTH AND RADIUS
p_world->getUtils()->calculateTireWidthAndRadius(car_data);
//STEP 6: CRATE CAR
car_p_node=p_world->createCar(car_data);
//STEP 7:GET TIRES (OPTIONAL)
br_tire=car_p_node->getBRTire();
bl_tire=car_p_node->getBLTire();
fr_tire=car_p_node->getFRTire();
fl_tire=car_p_node->getFLTire();
}
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
Its a lot better, but a few things! Firstly how about no _'s cause they make the code more complex, like instead of car_data, carData! And u use _ in your built in structure too, without that it could be simpler! Secondly, how bout putting this
chassis_p_node->autoCalcInertia();
inside setMass?? And have another function setMass which can take Inertia if the user wants to have that diff!
And how bout instead of always setting the force recursive for gravity, the library shud set it by default, that way the user wont have to do this step all the time!
And instead of these two:
you could just input the tireOffset value in the SCar struct and pass it on! You should also be able to pass width and radius too! If a person wants automatic calculation of that, he shud be able to call a function like calculateTireWidth and calculateTireRadius! Then we loose these two steps too making it simple!
And instead of fr_wheel_node these declarations how bout tireFR?? and instead of this in the SCarStruct, fr_tire_node, how bout tireFR?? or FRTireNode?
and instead of this tires_body_scene_node_offset it will be automatically much better for the eyes!
chassis_p_node->autoCalcInertia();
inside setMass?? And have another function setMass which can take Inertia if the user wants to have that diff!
And how bout instead of always setting the force recursive for gravity, the library shud set it by default, that way the user wont have to do this step all the time!
And instead of these two:
Code: Select all
//STEP 4: POSITIONG TIRES
p_world->getUtils()->calculateCarTiresPosition(
car_data,//the SCar struct
tire_offset//a vector3df wich is the position offset of the tires from chassis body
);
//STEP 5:CALCULATE TIRES WIDTH AND RADIUS
p_world->getUtils()->calculateTireWidthAndRadius(car_data);
And instead of fr_wheel_node these declarations how bout tireFR?? and instead of this in the SCarStruct, fr_tire_node, how bout tireFR?? or FRTireNode?
and instead of this tires_body_scene_node_offset it will be automatically much better for the eyes!
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
only two things:
2)split calculateTireWidthAndRadius in two functions is not more complicated for the user?
1) calculateCarTiresPosition() get tire_offset only for calculate all tires position. after calculating it,the function set the tires position properly. and tire_offset is not needed in any other part of the library. Insert it in SCar only for calculateCarTiresPosition() is not a memory waste?you could just input the tireOffset value in the SCar struct and pass it on
2)split calculateTireWidthAndRadius in two functions is not more complicated for the user?
-
- Posts: 279
- Joined: Fri Dec 24, 2004 6:37 pm
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
2)great idea!!!
1)carData is allocated in the stack and not in the heap. it can't be dealoccated when you want, but only when its scope finish.
Yes, you can write "SCar carData=new SCar();" (or malloc if you prefer C) and "delete carData;" after "p_world->createCar()", but this isn't a good solution in my hopinion. There is another solution, put a "{" before "Scar car_data" and a "}" after "p_world->createCar()". In this case the scope of carData finish at "}", but insert {s is not a good solution (already in my hopinion).
1)carData is allocated in the stack and not in the heap. it can't be dealoccated when you want, but only when its scope finish.
Yes, you can write "SCar carData=new SCar();" (or malloc if you prefer C) and "delete carData;" after "p_world->createCar()", but this isn't a good solution in my hopinion. There is another solution, put a "{" before "Scar car_data" and a "}" after "p_world->createCar()". In this case the scope of carData finish at "}", but insert {s is not a good solution (already in my hopinion).
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
here are new createCar code. How about it?
Code: Select all
//STEP 1:CREATE CHASSIS BODY
irr::newton::SBody chassisData;
chassisData.Node=chassis_node;
chassisData.Mass=chassis_mass;
chassis_p_node=p_world->createBody(chassisData);
//add gravity force (recursive)
chassis_p_node->addForceContinuous(core::vector3df(0,chassis_gravity_y_force,0));
//create CAR!!!!
//STEP 2: CREATE ALL TIRES SCENE NODE
irr::scene::ISceneNode* fr_wheel_node=createWheel();
irr::scene::ISceneNode* fl_wheel_node=createWheel();
irr::scene::ISceneNode* br_wheel_node=createWheel();
irr::scene::ISceneNode* bl_wheel_node=createWheel();
//STEP 3:BUILD CAR DATA
irr::newton::SCar car_data;
car_data.TiresMass=tire_mass;
car_data.ChassisBody=chassis_p_node;
car_data.TireNodeFR=fr_wheel_node;
car_data.TireNodeFL=fl_wheel_node;
car_data.TireNodeBR=br_wheel_node;
car_data.TireNodeBL=bl_wheel_node;
//auto calculate tires position. if don't set TiresOffsetFromChassis the tires position will be not modify
//tire_offset is a vector3df
car_data.TiresOffsetFromChassis=tire_offset;
//only bacause in the wheel model file the model is rotated on X on 90 degrees.
//Generally you don't need to do this
car_data.TiresBodyOffsetFromSceneNode.Rotation.X=-90;
//STEP 5: CERATE CAR
car_p_node=p_world->createCar(car_data);
//STEP 6:GET TIRES (OPTIONAL)
br_tire=car_p_node->getBRTire();
bl_tire=car_p_node->getBLTire();
fr_tire=car_p_node->getFRTire();
fl_tire=car_p_node->getFLTire();