IrrNewt irrlicht\newton framework >> SVN access

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

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.
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

5)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)
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 compatible

@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)
and not:

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...
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

Yea something like that is what i am thinking about! Like:

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);
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!
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

Another thing, instead of this, in the main loop;

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);
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!
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

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:
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!
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?

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);

}
So will love to use your library for my game after its simple enough to be easily used tho!
thanks :D
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
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.

you want a function that move and rotate the camera at the same time?
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

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!
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

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?
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!
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)?
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

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)?
If this function is called inside onevent, then why shud the user pass a struct! Instead you can just do it by using onevents inside the library!
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

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();	
}
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

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:

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);
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!
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

only two things:
you could just input the tireOffset value in the SCar struct and pass it on
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?

2)split calculateTireWidthAndRadius in two functions is not more complicated for the user?
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

1) Arent we dumping carData after creating the car???

2) Just got a better idea, put calculateTireWidth and radius in createcar, if the user does not input a tirewidth and tireRadius, then use it to calculate width and radius!
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

2)great idea!!! :D

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).
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

You declared car_data inside createCar so when createCar ends so shud car_data shudnt it???

BTW Cant wait to have my hands on the code! The examples have already started to look simpler!
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

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();
	
Post Reply