Here's my test. I removed all the commented lines of unsatisfying tests... Can you help me with the magical mathematical lines?
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="Capture" CameraPosition="0 0 0" FileVersion="2">
<OnLoaded>
<SpawnModel Model="ModelViewer" Position="0 0 -20"/>
</OnLoaded>
<Content>
<Model Name="ModelViewer">
<Definitions>
<Variable Name="ViewerVelocity" Type="6"/>
<Variable Name="ButtonUp" Type="4"/>
<Variable Name="ButtonDown" Type="4"/>
<Variable Name="ButtonLeft" Type="4"/>
<Variable Name="ButtonRight" Type="4"/>
</Definitions>
<OnSpawn>
<ZExpression>
<Expression>
<![CDATA[CurrentModel.Rotation.X = 0.15;
CurrentModel.Rotation.Y = 0;
CurrentModel.Rotation.Z = 0;
CurrentModel.RotationVelocity = 0;]]>
</Expression>
</ZExpression>
</OnSpawn>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[ButtonUp = 0;
ButtonDown = 0;
ButtonLeft = 0;
ButtonRight = 0;]]>
</Expression>
</ZExpression>
<KeyPress Comment="UP" Keys="^8wW">
<OnPressed>
<ZExpression Expression="ButtonUp = 1;"/>
</OnPressed>
</KeyPress>
<KeyPress Comment="DOWN" Keys="_2sS">
<OnPressed>
<ZExpression Expression="ButtonDown = 1;"/>
</OnPressed>
</KeyPress>
<KeyPress Comment="LEFT" Keys="<4aA">
<OnPressed>
<ZExpression Expression="ButtonLeft = 1;"/>
</OnPressed>
</KeyPress>
<KeyPress Comment="RIGHT" Keys=">6dD">
<OnPressed>
<ZExpression Expression="ButtonRight = 1;"/>
</OnPressed>
</KeyPress>
<ZExpression>
<Expression>
<![CDATA[if(ButtonUp && ViewerVelocity.X < 1) ViewerVelocity.X += 0.6 * App.DeltaTime;
if(ButtonDown && ViewerVelocity.X > -1) ViewerVelocity.X -= 0.6 * App.DeltaTime;
if(ButtonLeft && ViewerVelocity.Y > -1) ViewerVelocity.Y -= 0.6 * App.DeltaTime;
if(ButtonRight && ViewerVelocity.Y < 1) ViewerVelocity.Y += 0.6 * App.DeltaTime;
if(!ButtonUp && !ButtonDown && !ButtonLeft && !ButtonRight){
if (ViewerVelocity.X < 0) ViewerVelocity.X += 0.6 * App.DeltaTime;
if (ViewerVelocity.X > 0) ViewerVelocity.X -= 0.6 * App.DeltaTime;
if (ViewerVelocity.Y < 0) ViewerVelocity.Y += 0.6 * App.DeltaTime;
if (ViewerVelocity.Y > 0) ViewerVelocity.Y -= 0.6 * App.DeltaTime;
if (ViewerVelocity.X > -0.01 && ViewerVelocity.X < 0.01) ViewerVelocity.X = 0;
if (ViewerVelocity.Y > -0.01 && ViewerVelocity.Y < 0.01) ViewerVelocity.Y = 0;
}
// Local Rotation
CurrentModel.RotationVelocity.X = -1*ViewerVelocity.X;
CurrentModel.RotationVelocity.Y = -1*ViewerVelocity.Y;
// Global Rotation
float cosAngle = cos(ViewerVelocity.X);
float sinAngle = sin(ViewerVelocity.Y);]]>
</Expression>
</ZExpression>
</OnUpdate>
<OnRender>
<RenderMesh Mesh="MissileMesh"/>
</OnRender>
</Model>
<Mesh Name="MissileMesh">
<Producers>
<MeshBox Scale="0.3 0.3 3"/>
<MeshExpression VertexColors="255">
<Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
c.R=0.8;
c.G=0.8;
c.B=0.8;]]>
</Expression>
</MeshExpression>
<MeshBox Comment="flaps right" Scale="0.1 1 1"/>
<MeshExpression VertexColors="255">
<Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
c.R=1;
c.G=0.2;
c.B=0.2;]]>
</Expression>
</MeshExpression>
<MeshTransform Position="0 0 1.5" Rotation="0.88 0 0"/>
<MeshCombine/>
<MeshBox Comment="flaps left" Scale="0.1 1 1"/>
<MeshExpression VertexColors="255">
<Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
c.R=1;
c.G=0.2;
c.B=0.2;]]>
</Expression>
</MeshExpression>
<MeshTransform Position="0 0 1.5" Rotation="0.88 0 0.25"/>
<MeshCombine/>
<MeshSphere Scale="0.4 0.4 0.8" ZSamples="3" RadialSamples="4"/>
<MeshExpression VertexColors="255">
<Expression>
<![CDATA[//V : current vertex
//N : current normal (turn off AutoNormals when modifying normals)
//C : current color (turn on VertexColors)
//TexCoord : current texture coordinate (turn on HasTexCoords)
c.R=1;
c.G=0.2;
c.B=0.2;]]>
</Expression>
</MeshExpression>
<MeshTransform Scale="1 1 2" Position="0 0 -3" Rotation="0 0 0.125"/>
<MeshCombine/>
</Producers>
</Mesh>
</Content>
</ZApplication>