April 19, 2024, 10:24:42 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Zumwalts Blast A Mech Code

Started by J B Wood (Zumwalt), July 29, 2006, 07:20:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

OK in reference to your machine gun.  The meshes center of rotation is not the middle of the gun.  So to correct for it you use the transform node as I had suggested.

- Offset the transfrom using the Postion method so it as at the center of where you want the gun to rotate.
- Make the gun a child of the transform and offset it using the Position method so the point on the mesh where you want it to rotate is over the center of the transform.
- You rotate the transform then, not the gun.

After a few minutes of playing this was close:


//#include "ode.inc"
declare import,timeGetTime(),int;

global sub main()
{
// setup or variables
C3DScreen s;
C3DCamera c;
C3DMesh m;
C3DObject scene,trans;
C3DLight light;
CDirectInput di;
// tank stuff
VECTOR3 myMesh,myTerrain,mySprite;
VECTOR3 tankDIR, tankPOS;

// turret stuff
VECTOR3 turretDIR, turretPOS;

// barrel stuff
VECTOR3 barrelDIR, barrelPOS;

// mgun stuff
VECTOR3 mgunDIR, mgunPOS;

float tankAdjust;
float fadjust,fTarget;
//target 60FPS for camera movement
fTarget = 1.0f / /*FPS*/60.0f * 1000.0f;
fAdjust = 1.0f;

//Zumwalts FUN stuff!!!
C3DMesh z,sp,m1,tp1,tp2,w,zt,zb,mgun,mholder;

// create our window to handle our scene
s.CreateWindowed(0,0,1024,768,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE,0,"Zumwalts 3D Test - ESC exits",NULL,false);
di.Init(s);
s.CenterWindow();
c.Create(s);
c.Position(1,1,1);
c.Rotate(0,0,0);
c.Orient(0,0,1,0,10,0);
//c.Orient(0,0,1,0,100,0);
c.SetBackPlane(500);
trans.createtransform(s);

// load our tank
zt.Load3DS(s,GetStartPath() + "media\\TankTurret.3ds",false);
zb.Load3DS(s,GetStartPath() + "media\\TankBarrel.3ds",false);
mgun.Load3DS(s,GetStartPath() + "media\\tankmgun.3ds",false);
mholder.Load3DS(s,GetStartPath() + "media\\tankmgun1.3ds",false);
//mgun.LoadX(s,GetStartPath() + "media\\mgun.x");
z.Load3DS(s,GetStartPath() + "media\\TankBody.3ds",false);
z.Scale(1,1,1);
z.Position(-79,-7.45,50); // hit is at -7.5, need to look into mesh later
z.Rotate(0,0,0);
z.EnableLighting(false);
z.UseVertexColor(false);
// add turret as a child to tank
z.addchild(zt);
zt.addchild(trans);
trans.addchild(mgun);
trans.position(.5,0,-.3);
mgun.position(-.4,0,.4);
//zt.addchild(mgun);

// add barrel as child to turret
zt.addchild(zb);

// Load our terrain
m.LoadX(s,GetStartPath() + "media\\terrain.x");
m.Scale(1,1,1);
m.Position(0,-7.5,0);
m.Rotate(0,180,0);
m.EnableLighting(true);
m.UseVertexColor(true);

// load our water
w.LoadX(s,GetStartPath() + "media\\water0.x");
w.Scale(1,1,1);
w.Position(0,-8,0);
w.Rotate(0,180,0);
w.EnableLighting(true);
w.UseVertexColor(true);

// load our sprite for above tank
sp.LoadX(s,GetStartPath() + "media\\sprite.x");
sp.Scale(1,1,1);
sp.Position(-104,0,40);
sp.Rotate(0,0,0);
sp.EnableLighting(false);
sp.UseVertexColor(false);

// load our mech
m1.LoadX(s,GetStartPath() + "media\\mech.x");
m1.Scale(1,1,1);
m1.Position(-89,-7.5,45);
m1.Rotate(0,0,0);
m1.EnableLighting(false);
m1.UseVertexColor(false);

// create our lighting
light.Create(s,LIGHT_POINT,1);
light.Position(110,110,150);
light.SetAttenuation(0,1/500.0,0);
light.SetSpecular(.5,.5,.5,1);
light.SetAmbient(1,1,1,1);
light.SetRange(1000);

// add children to scene
scene.CreateScene(s);
scene.AddChild(light);
scene.AddChild(m);
scene.AddChild(z);
scene.AddChild(sp);
scene.AddChild(m1);
scene.AddChild(w);


// set inital collision
z.initcollision(false);
m.initcollision(false);
m1.initcollision(false);

int fps = 0;
int startTime;
float angle = 0.0;    // Tank direction speed
float angleT = 0.0;  // Turret Direction speed
float angleB = 0.0;  // Barrel Direction speed
float angleG = 0.0;  // Gun Direction speed

float speed=0.0;      // travel speed
float maxspeed=1.0; // max travel speed
float minspeed=-0.5; // min travel speed
float inertia=0.0005; // Inertia balance factor
float camDMin=-5,camDMax=-40,camDCurrent=-20;  // Camera adjustments
float barMin=0.100,barMax=-0.100; // Barrel angle minimum and maximum

// obtain initial tank position
myMesh=z.GetPosition(0);


do
{
startTime = timeGetTime();
tankPOS = z.GetPosition(0);
tankDIR = z.GetDirection();
myMesh = z.GetPosition(0);
myTerrain = m.GetPosition(0);
turretDIR = zt.getPosition(0);
barrelDIR = zb.getPosition(0);
mgunDIR = mgun.getPosition(0);


// Home Position for the tank, simulate spawn
if di.KeyDown(DIK_H)
{
myMesh.x=-79;
myMesh.y=-7.45;
myMesh.z=50;
z.Position(myMesh.x,myMesh.y,myMesh.z);
}

//check for keys and move mech and camera accordingly
IF di.KeyDown(DIK_UP)
{
z.Position(myMesh.x+tankDIR.x*speed,myMesh.y,myMesh.z+tankDIR.z*speed);
}
else
{
//Assume inertia resistance on motion
if(speed > inertia) & !di.KeyDown(DIK_A) & !di.KeyDown(DIK_Z)
{
speed=speed-inertia;
}
else if (speed < inertia-0.001) & (!di.KeyDown(DIK_A) & !di.KeyDown(DIK_Z))
{
speed=speed+inertia;
}
else if (!di.KeyDown(DIK_A) & !di.KeyDown(DIK_Z))
{
speed=0;
}
z.Position(myMesh.x+tankDIR.x*speed,myMesh.y,myMesh.z+tankDIR.z*speed);
}

// apply brakes to stop the tank
IF di.KeyDown(DIK_DOWN)
{
if (speed < 0)
{
speed=speed+inertia*3;
}
else if (speed > .003)
{
speed=speed-inertia*3;
}
else if (speed <> 0)
{
speed=speed-inertia;
}
else
{
speed=0;
}
}

// increase speed
IF di.KeyDown(DIK_A)
{
if(speed<maxspeed)
{
speed+=.001;
}
else
{
speed=maxspeed;
}
}

// decrease speed
IF di.KeyDown(DIK_Z)
{
if(speed>minspeed)
{
speed-=.001;
}
else
{
speed=minspeed;
}
}

// turn right
if( di.KeyDown(DIK_RIGHT))
{
angle += .025 * fAdjust;
}

// turn left
IF di.KeyDown(DIK_LEFT)
{
angle -= .025 * fAdjust;
}

// rotate Turret Left
if (di.KeyDown(DIK_Q))
{
angleT -= .025 * fAdjust;
}

// rotate Turret Right
if (di.KeyDown(DIK_W))
{
angleT += .025 * fAdjust;
}

// rotate Turret Left
if (di.KeyDown(DIK_3))
{
angleG -= .025 * fAdjust;
}

// rotate Turret Right
if (di.KeyDown(DIK_4))
{
angleG += .025 * fAdjust;
}

// rotate Barrel Up
if (di.KeyDown(DIK_1))
{
if (angleB > barMax)
{
angleB -= .0025 * fAdjust;
}
else
{
angleB = barMax;
}
}

// rotate Barrel down
if (di.KeyDown(DIK_2))
{
if (angleB < barMin)
{
angleB += .0025 * fAdjust;
}
}

// physically rotate tank
z.Rotate(0.0f, angle,0.0f);
zT.rotate(0.0f,angleT,0.0f);
zB.rotate(angleB,0.0f,0.0f);

trans.rotate(0.0f,angleG,0.0f);

s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
scene.Draw();

// setup weapons keys, just show text for now
if di.KeyDown(DIK_PERIOD) & !di.KeyDown(DIK_COMMA)
{
s.RenderText(0,70,"Fired: Missle",RGBA(255,255,0,255));
}
else
{
s.RenderText(0,70,"Fired: ",RGBA(255,255,0,255));
}

if di.KeyDown(DIK_PERIOD) & di.KeyDown(DIK_COMMA)
{
s.RenderText(0,70,"Fired: Ejection Seat",RGBA(255,255,0,255));
}
else
{
s.RenderText(0,70,"Fired: ",RGBA(255,255,0,255));
}

if di.KeyDown(DIK_COMMA) & !di.KeyDown(DIK_PERIOD)
{
s.RenderText(0,70,"Fired: Machine Gun",RGBA(255,255,0,255));
}
else
{
s.RenderText(0,70,"Fired: ",RGBA(255,255,0,255));
}

// alter camera position
if di.KeyDown(DIK_S)
{
if (camDCurrent>camDMax)
{
camDCurrent-=.01;
}
else
{
camDCurrent=camDMax;
}
}

if di.KeyDown(DIK_D)
{
if (camDCurrent<camDMin)
{
camDCurrent+=.01;
}
else
{
camDCurrent=camDMin;
}
}

// render information to screen about what to do
//s.RenderText(0,0,"\xC9",RGBA(255,255,0,255));
s.RenderText(0,10,"FPS:"+NumToStr(fps),RGBA(255,255,0,255));
s.RenderText(0,32,"X:"+NumToStr(myMesh.x,2),RGBA(255,255,0,255));
s.RenderText(0,44,"Y:"+NumToStr(myMesh.y,2),RGBA(255,255,0,255));
s.RenderText(0,56,"Z:"+NumToStr(myMesh.z,2),RGBA(255,255,0,255));
s.RenderText(200,0,"Controls: Comma=Machine Gun, Period=Missle, Comma+Period=Eject",RGBA(255,255,0,255));
s.RenderText(200,15,"Arrow Up=Move **** Arrow Down=Brakes **** Arrow Left & Arrow Right = Steer",RGBA(255,255,0,255));
s.RenderText(200,28,"A: Forward Throttle",RGBA(255,255,0,255));
s.RenderText(200,42,"Z: Reverse Throttle",RGBA(255,255,0,255));
s.RenderText(200,54,"H: Respawn at Home",RGBA(255,255,0,255));
s.RenderText(200,66,"S: Zoom Camera Out",RGBA(255,255,0,255));
s.RenderText(200,78,"D: Zoom Camera In",RGBA(255,255,0,255));

s.RenderText(400,28,"Q: Rotate Turret Left",RGBA(255,255,0,255));
s.RenderText(400,42,"W: Rotate Turret Right",RGBA(255,255,0,255));
s.RenderText(400,54,"1: Raise Barrel",RGBA(255,255,0,255));
s.RenderText(400,66,"2: Lower Barrel",RGBA(255,255,0,255));
s.RenderText(400,78,"3: Rotate Gun Left",RGBA(255,255,0,255));
s.RenderText(400,90,"4: Rotate Gun Right",RGBA(255,255,0,255));

s.RenderText(800,0,"Tank Speed:"+NumToStr(speed,3),RGBA(255,255,0,255));
s.RenderText(800,20,"Tank Barrel:"+NumToStr(angleB,3),RGBA(255,255,0,255));

// position camera
c.Position(myMesh.x,myMesh.y+10,myMesh.z+camDCurrent);
c.Rotate(0,0,0);
c.Orient(0,0,1,0,10,0);
c.LookAt(myMesh.x,myMesh.y,myMesh.z);
sp.Position(myMesh.x+tankDir.x,myMesh.y+tankDir.y+4,myMesh.z+tankDir.z);
sp.Rotate(0,0,0);

// check for and annouce collision
if(m.ObjectCollided(z, true))
{
s.RenderText(0,90,"Hit Terrain",RGBA(255,255,0,255));
}

if(m.ObjectCollided(m1, true))
{
s.RenderText(0,90,"Hit Mech Dummy",RGBA(255,255,0,255));
}

// render the scene and loop
fps = s.RenderScene();
fAdjust = (timeGetTime() - startTime) / fTarget;
}until di.KeyDown(DIK_ESCAPE);
Scene.Free();
}
Ionic Wind Support Team

J B Wood (Zumwalt)

THANKS!
This is definately going to help, I was creating the tank class while on the airplane today, and this is going to help with the other problem I have with the other weapon mounts......


Steven Picard

Zumwalts, you've made some nice progress on this.  I look forward to your future versions.

J B Wood (Zumwalt)

I hope to have another release update this weekend, I have created a few classes and am starting to seperate everything out into them, including a V3 class I am working on to hold a type of radar system. putting all the math I need for calculations into that class, the tank class is coming along pretty nicely, so hopefully all a person has to do is create a new instance of the class or inherit the class if building a new class based on the tank properties and methods.

That will eventually be thinned down to a vehicle base class that the tank class will inherit from itself, which is smarter actually.
Anyway, if I am lucky the next release will have the first H.U.D. done (well started anyway).

I am also working out the details on paper for the weapon class and what all would a weapon contain. I know I talked about it earlier but hadn't really gotten around to designing it the way I wanted it to be. That and I am trying to totally understand the trans effect.

Hopefully this demo is helping others.

kryton9

That will be sweet to see. Good luck, looking forward to the next update!!

J B Wood (Zumwalt)

Minor update before the weekend, this is now in a project format (although I don't know how to add an icon to the application yet)

The stuff on paper at the house is not in the code yet, but take a look, now I can keep track of targets, right now it has a static target of the mech, gun tracking not enabled in this build, that will come over the weekend for the machine gun and a key to turn it on and off for the turret / barrel.

I got to figure out in the next week or so how to use the mouse in 3d space in this engine....
Haven't even looked to see if its available yet either.

kryton9

Great, I am going to work on making an animated mech and will place it into the models folder when it is finished.

J B Wood (Zumwalt)

Thanks Kryton9, much appreciated.

John S

looks neat Z.
the machine gun turns, can the turret turn too?
what did you use to create the models?
John Siino, Advanced Engineering Services and Software

J B Wood (Zumwalt)

August 12, 2006, 08:42:42 AM #34 Last Edit: August 12, 2006, 09:05:44 AM by zumwalt
Yes, the keys for the turret are listed at the top with the key list.
I have found that the engine limits the number of keys you can have held down, so you can rotate the turret and gun, or the body and gun, or the barrel and turret, but only 2 things at a time, which is wierd, but the gun, turret, barrel and body move.

I have remarked out the border in this latest update so to speed it up like 4 fold.
I use Caligari's Truespace to do my work in, this is why I am so exicted about the OBJ format support, that is the native format to Truespace / gamespace.

EDIT: This build has the first attempt to the machine gun auto tracking in it, so the machine gun goes nuts, bear with me on that, but you can change the following lines:

//trans.rotate(0.0f,angleG,0.0f);
gunResult = dist.hdngtotarget(transpos.x,transpos.z,mechpos.x,mechpos.z);
trans.rotate(0.0f,gunresult,0.0f);

to match
trans.rotate(0.0f,angleG,0.0f);
//gunResult = dist.hdngtotarget(transpos.x,transpos.z,mechpos.x,mechpos.z);
//trans.rotate(0.0f,gunresult,0.0f);

This will let you manually control the rotation of the gun.

kryton9

Wow, that is really coming along. That is wild about the machine gun. Looks neat though, a mind of its own. This is going to be fun :)

J B Wood (Zumwalt)

August 16, 2006, 11:10:56 AM #36 Last Edit: August 16, 2006, 11:26:11 AM by zumwalt
Teaser post and a bump.. FYI I have a generic gravity in place..... coming soon.... eta today I pray.

sweet, thats just fun..
Ok, basic gravity in place, not physics level, this is just a very basic level.
Only applied to tank at the moment while Kryton9 works on his mech to replace mine with.
New update on the link, with basic machinegun tracking that Kryton and I am trying to figure out...

J B Wood (Zumwalt)

Just updated, has new terrain (under construction, testing the refresh rate and such)
Both mech and tank now have my gravity component attached to them, tank result for collision with mech now works successfully, so I can work on that in a bit for damage, etc.

kryton9

Zumwalt, wow you really got this going. Lots of fun and lots of stuff you are making work. Sliding collision was daunting me, now will have good code to study, great job!!

J B Wood (Zumwalt)

This is highly basic and is calculated on every game loop, very processor intensive if you ask me.
This solution I am using will NOT work for massive collision detection processes on moving objects.
On my laptop I loose around 5fps per object I add to the list in this type of check system.
I am trying to theorize better ways to accomplish this without a dynamic physics system.

Rock Ridge Farm (Larry)

Wow - finally got a chance to play with the tank. Cool.
Now make the treads rotate with the tank movement  :)
I am looking forward to you completion of this game.
This is so cool to be done in Aurora.

J B Wood (Zumwalt)

Thanks Larry.
As soon as I figure out animation, I'll have the treads moving :)
There is alot I still want to do with it before I call it a complete demo, atleast at the moment if you fall off the map you respawn at home point.
I am kind of tweaking it while I wait for the next release of the engine, doing some client / server stuff at the moment.

ExMember001

new update looks very good !
now i've to learn 3d ;)

J B Wood (Zumwalt)

WARNING!!! TEASER NIGHT ATTACK!!!

kryton9

Cool night shot, I like the widescreen shot.

J B Wood (Zumwalt)

I just uploaded the latest code / build, so the link is updated.
Only added the light to the tank, and you can turn on and off the global light with the L and RSHIFT-L

I seem to have lost my targeting image though.. Got to chase that one down..
Going to work on this some more tomorrow night when I get home from work to test out the new LookAt commands.

This update can give people ideas on how to handle the new light orientation.
Pretty cool.

kryton9

L and RSHIFT+L are not working for me. Will look at the code. Glad you are back on it. Good luck!!

J B Wood (Zumwalt)

September 01, 2006, 06:19:20 AM #47 Last Edit: September 01, 2006, 06:40:30 AM by zumwalt
Hmm... Anyone else having this same problem?

Kryton, twords the bottom of the loop, does your code have this in it?


if di.KeyDown(DIK_RSHIFT) & di.KeyDown(DIK_L)
{
if (lightState=1)
{
lightState=0;
light.Disable();
}
}

if di.KeyDown(DIK_L) & !di.KeyDown(DIK_RSHIFT)
{
if (lightState=0)
{
lightState=1;
light.Enable();
}
}



In the initialization, you should also have a:

int lightState = 1;     // determine if global light is on or off



Most importantly, is the infinate light still on or is it night time?

kryton9

Need to run errands for my Dad today, will look later tonight. Got sleepy after I played with it some and never got to looking at the code. It looks straightforward from your snippet, so I probably ran the wrong file while sleepy :)

J B Wood (Zumwalt)

Well bugger, back to the drawing board, the PointAt is only good for the INITIAL point at target, my mgun sits on the turret so it has a trans location, it points ok on init, basically the first and only time it point at the right location, then as I move the tank around its way off, which has always been my problem, so now I am concentrating on learning 3d math. I'll get this figured out, I have to, its core to what I am going to do next, guided missiles.