Optimiz away3d for android

Software: Away3D 4.x

John Brookes, Moderator
Posted: 24 February 2013 12:14 PM   Total Posts: 732   [ # 16 ]

Did you manage to do the swc with flascc?

 

   

Avatar
loth, Sr. Member
Posted: 24 February 2013 12:20 PM   Total Posts: 236   [ # 17 ]

no i don’t use deltatime for the moment
can you send swc in a zip file and your deltatime process i use
if (_isDeltaTimeMode){
  _itime = getTimer();
  _dt = (_itime - _prevTime) * 0.001;
  _physicsWorld.step(_dt, 4);
  _prevTime = _itime;
}

i have to test some track (specialy one made for Jam game contest)

 

   

John Brookes, Moderator
Posted: 24 February 2013 12:26 PM   Total Posts: 732   [ # 18 ]

AwayPhysics Alpha SWC with wheels deltaTime fix

 

File Attachments
AwayPhysics.zip  (File Size: 587KB - Downloads: 427)
   

Avatar
Luca, Sr. Member
Posted: 24 February 2013 12:32 PM   Total Posts: 230   [ # 19 ]

We want to see the demo Loth smile

Like this wink

http://www.estiva2.altervista.org/SiteGames/Kart/Kart.php

At this moment i need to improve the AI for the Kart…

I must decide to use control point or have a track mesh ( both idden ) access the vertex data and/or add ray to check/prevent collision and so on…

  //——————————————————————————————————————————————————————-
  //
  //——————————————————————————————————————————————————————-
  private function NavigateTowardsWaypoint()
  {

  // Now we just find the relative position of the waypoint from the car transform,
  // that way we can determine how far to the left and right the waypoint is.
  // Calculate the target position relative to the this transforms coordinate system.
  // eg. a positive x value means the target is to the right of the car,
  // a positive z means the target is in front of the car
  relativeTarget = car.getRigidBody().skin.inverseSceneTransform.transformVector( waypoints[currentWaypoint] );
  relativeTarget1 = car.getRigidBody().skin.inverseSceneTransform.transformVector( waypoints[currentWaypoint+1] );
  // Above solution only works if the item/ball is directly on the stage. If it isnt, you should use ball.scenePosition!
  //item.position = targetContainer.inverseSceneTransform.transformVector(item.scenePosition);
 
 
  // By dividing the horizontal position by the magnitude, we get a decimal percentage of
  // the turn angle that we can use to drive the wheels
  // Calculate the target angle for the wheels, so they point towards the target
  // targetAngle = Math.atan2( relativeTarget.x, relativeTarget.z );
  // targetAngle1 = Math.atan2( relativeTarget1.x, relativeTarget1.z );
 
  // The wheels have a maximum rotation angle
  targetAngle = Clamp( Math.atan2( relativeTarget.x, relativeTarget.z ), -MaxSteeringAngle, MaxSteeringAngle );
  // The wheels have a maximum rotation angle
  targetAngle1 = Clamp( Math.atan2( relativeTarget1.x, relativeTarget1.z ), -MaxSteeringAngle, MaxSteeringAngle );

 
  //
  if( DebugAI )
  {
  //
  Gizmos.position = waypoints[currentWaypoint];
 
  ConnectionLine.start = car.getRigidBody().skin.position;
  ConnectionLine.end = waypoints[currentWaypoint];
  // trace( waypoints[currentWaypoint] + ” - ” + car.getRigidBody().transform.position );
 
  ConnectionLine.startColor = ConnectionLine.endColor = 0xFFFFFF;
  ConnectionLine.thickness = 2;
 
  // trace( waypoints[currentWaypoint] + ” ” + car.getRigidBody().position );
  // trace( Dx + ” ” + Dz );

  // GVector2.start = new Vector3D();
  // GVector2.end = DTV; 
  // GVector1.startColor = GVector1.endColor = 0x0000FF;
  // GVector2.startColor = GVector2.endColor = 0xFFFFFF;
  // GVector1.thickness = GVector2.thickness = 2;
  //
  //trace( targetAngle );
  //
  GVector1.start = car.getRigidBody().skin.sceneTransform.position;
  //
  var Pe:Vector3D = new Vector3D(
    car.getRigidBody().skin.sceneTransform.position.x + 300 * ( Math.sin( targetAngle ) ),
    car.getRigidBody().skin.sceneTransform.position.y,
    car.getRigidBody().skin.sceneTransform.position.z + 300 * ( Math.cos( targetAngle ) ) );
  GVector1.end = Pe;
 
  }

  // This just checks if the car’s position is near enough to a waypoint to count as passing it,
  // if it is, then change the target waypoint to the next in the list.
  if ( relativeTarget.length < 700 )
  {
  //
  currentWaypoint++;
  //
  if( currentWaypoint >= waypoints.length )
  {
    currentWaypoint = 0;
  }
  }

  }

Or export something by using XML…
Anywher demo, demo, demo…. and challenge if you think to make a multiplayer vesion of the game smile

 

   

John Brookes, Moderator
Posted: 24 February 2013 12:59 PM   Total Posts: 732   [ # 20 ]

Go with way points.
Theres a couple of cars in this demo that follow some way points.
It uses the same code as that Unity stuff you keep posting wink

Its an old thing I did with BroomStick just testing what was possible.
So dosent look pretty and weird things may happen.

http://www.shrewballooba.co.uk/pre2/

 

   

Avatar
Luca, Sr. Member
Posted: 24 February 2013 01:57 PM   Total Posts: 230   [ # 21 ]

But if you prefer ( happy sharing smile ) - Angle between two vectors with Dotproducts…

This is the code used in this demo:
http://www.estiva2.altervista.org/SiteGames/Natale.php
made with alternativa3D raspberry

The path are a polyline:

  //
  tn = modelContainer.getChildByName(“PATH1”) as Mesh;
  //
  if( tn != null)
  {
  nv = tn.geometry.numVertices;
  pos = tn.geometry.getAttributeValues( VertexAttributes.POSITION );
  PupazzoContainer.x = pos[uint(0)];
  PupazzoContainer.y = pos[uint(1)];
  tn.setMaterialToAllSurfaces( colors[“green”] );
  tn.visible = true;
  }
  else
  trace( “PATH NON TROVATO” );

 

   

Avatar
Luca, Sr. Member
Posted: 24 February 2013 02:05 PM   Total Posts: 230   [ # 22 ]

ANIMAZIONE PUPAZZO

//
if( !PupazzoStart )
{

PupazzoPosIndex = 0;
PupazzoNextPosIndex = 1;

//
PupazzoDir = new Vector3D( 0.0, 1.0, 0.0 );
//
Attuale = new Vector3D( pos[ uint( 3 * PupazzoPosIndex ) ], pos[ uint( 3 * PupazzoPosIndex ) + 1 ],
  pos[ uint( 3 * PupazzoPosIndex ) + 2 ] );
//
Prossima = new Vector3D( pos[ uint( 3 * PupazzoNextPosIndex ) ], pos[ uint( 3 * PupazzoNextPosIndex ) + 1 ],
  pos[ uint( 3 * PupazzoNextPosIndex ) + 2 ] );

//
LocalAttuale = modelContainer.getChildByName(“PATH1”).localToGlobal( Attuale );
LocalProssima = modelContainer.getChildByName(“PATH1”).localToGlobal( Prossima );

//
Dx1 = ( Prossima.x - Attuale.x );
Dy1 = ( Prossima.y - Attuale.y );

N1 = vNorm( Dx1, Dy1 );
N2 = vNorm( PupazzoDir.x, PupazzoDir.y );
Dx1A = Dx1 / N1;
Dy1A = Dy1 / N1;
Dx2A = PupazzoDir.x / N2;
Dy2A = PupazzoDir.y / N2;
DP = DotProduct( Dx1A, Dy1A, Dx2A, Dy2A );

//
if( Dx1 >= 0 )
{
  Angolo = Math.acos( DP ) / DEGREES_TO_RADIANS;
  PupazzoContainer.rotationZ = -Math.acos( DP );
}
else
{
  Angolo = -Math.acos( DP ) / DEGREES_TO_RADIANS;
  PupazzoContainer.rotationZ = Math.acos( DP );
}

//
PupazzoContainer.x = LocalAttuale.x;
PupazzoContainer.y = LocalAttuale.y;

//
sLight1.x = LocalAttuale.x;
sLight1.y = LocalAttuale.y;

//
dx = LocalProssima.x - PupazzoContainer.x;
dy = LocalProssima.y - PupazzoContainer.y;

//
PupazzoStart = true;

}

dista = distanceTo( PupazzoContainer.x, PupazzoContainer.y, modelContainer1.x, modelContainer1.y );

//  fpsText.text = “PX: ” + PupazzoContainer.x.toPrecision(3) + ” PY: ” + PupazzoContainer.y.toPrecision(3) +
//  ” MX: ” + modelContainer1.x.toPrecision(3) + ” MY: ” + modelContainer1.y.toPrecision(3) +
//  ” Dx1a: ” + Dx1a.toPrecision(3) + ” Dy1a: ” + Dy1a.toPrecision(3) + ” Dist: ” + dista.toPrecision(3);

 

   

Avatar
Luca, Sr. Member
Posted: 24 February 2013 02:14 PM   Total Posts: 230   [ # 23 ]

For the audio pitch i have used:

public class CarSound extends Sound
{
 
  private var ba:ByteArray = new ByteArray();
  //
  private var byteArray:ByteArray = new ByteArray();
  //
  private var _loadedMP3Samples:ByteArray;
  //
  private var _dynamicSound:Sound;
  //
  private var _loadedWavSamples:ByteArray;
  //
  private var _dynamicSound1:Sound;
  //
  private var _phase:Number;
  //
  private var _numSamples:Number;
  //
  public var _playbackSpeed:Number = 0.0;
  //
  private var BufferPos:Number = 0;
  //
  private var scMotore:SoundChannel;

  //———————————————————————————————————————————————————-
  //
  //———————————————————————————————————————————————————-
  public function CarSound()
  {

 
  //
  transGomme = new SoundTransform( 1.0, 0.0 );
 
  //
  scMotore = new SoundChannel();
  //
  _playbackSpeed = 0.6;
  //
  motore_mp3.addEventListener( Event.COMPLETE, EngineCompleteSoundLoaded );
  //
  EngineSoundStart( motore_mp3 );
  //
  transMotore = new SoundTransform( 0.1, 0.0 );
  }


 
  //———————————————————————————————————————————————————-
  //
  //———————————————————————————————————————————————————-

  //——————————————————————————————————————————————————————-
  // Buffer audio
  //——————————————————————————————————————————————————————-
  public function EngineSoundStart( s:Sound ):void
  {
  //
  var bytes:ByteArray = new ByteArray();
  //
  s.extract( bytes, int( s.bytesTotal ), 690 ); //4096
  //
  EngineStart( bytes );
  }
 
  //——————————————————————————————————————————————————————-
  //
  //——————————————————————————————————————————————————————-
  public function stop():void
  {
  //
  if ( _dynamicSound )
  {
  //
  _dynamicSound.removeEventListener( SampleDataEvent.SAMPLE_DATA, onSampleData );
  //
  _dynamicSound = null;
  }
  }
 
  //——————————————————————————————————————————————————————-
  //
  //——————————————————————————————————————————————————————-
  private function EngineCompleteSoundLoaded( event:Event ):void
  {
  //
  EngineSoundStart( motore_mp3 );
  }
 
  //——————————————————————————————————————————————————————-
  //
  //——————————————————————————————————————————————————————-
  private function EngineStart( bytes:ByteArray ):void
  {
  //
  stop();
  //
  _dynamicSound = new Sound();
  //
  _dynamicSound.addEventListener( SampleDataEvent.SAMPLE_DATA, onSampleData );
  //
  _loadedMP3Samples = bytes;
  //
  _numSamples = ( bytes.length / 16 );
  //
  _phase = 0;
  //
  _loadedMP3Samples.position = 0;
  //
  _dynamicSound.play();
  }
 
  //——————————————————————————————————————————————————————-
  //
  //——————————————————————————————————————————————————————- 
  private function rep( event:Event ):void
  {
  //
  _loadedMP3Samples.position = 0;
  //
  _dynamicSound.play();
  //
  _dynamicSound.addEventListener( Event.COMPLETE, rep );
  }
 
  //——————————————————————————————————————————————————————-
  //
  //——————————————————————————————————————————————————————-
  private function onSampleData( event:SampleDataEvent ):void
  {
 
  var l:Number;
  var r:Number;
  var outputLength:int = 0;
 
  //
  while( outputLength < 2048 )
  {
  // until we have filled up enough output buffer
 
  // move to the correct location in our loaded samples ByteArray
  // 4 bytes per float and two channels so the actual position in
  // the ByteArray is a factor of 8 bigger than the phase   _loadedMP3Samples.positi _phase ) * 16;
 
  // read out the left and right channels at this position
  l = _loadedMP3Samples.readFloat();
  r = _loadedMP3Samples.readFloat();
  // write the samples to our output buffer
  event.data.writeFloat( l );
  event.data.writeFloat( r );
  outputLength++;
 
  // Advance the phase by the VelocitaMS…
  _phase += _playbackSpeed;
 
  // and deal with looping ( including looping back past the beginning when playing in reverse )
  if( _phase < 0 )
    _phase += _numSamples;
  else if( _phase >= _numSamples )
    _phase -= _numSamples;
  }
  }
But this library seems to be also good…. :
http://code.google.com/p/alf/

 

   

Avatar
Luca, Sr. Member
Posted: 24 February 2013 02:16 PM   Total Posts: 230   [ # 24 ]

I can’t drive the truck why ??????????????????????????? smile

Anyway good FPS > 60 - NVidia 8600GT !

GO AWAY GOOOOO HOW MANY FEATURES !!!

I LIKE IT ( but i don’t know how many they are raspberry )

What format have you used to export the models ?
What is the version of the library Graphisc and Physics ?

 

   

John Brookes, Moderator
Posted: 24 February 2013 03:14 PM   Total Posts: 732   [ # 25 ]

Should just drive with arrow keys.
I think that one uses either broomstick or pre 4.0 realease and Bullet Physics.
Models are the old AWD version.

If Merge class worked in 4.1 I could use 4.1 and have better mirrors.

 

   

Avatar
Luca, Sr. Member
Posted: 24 February 2013 03:44 PM   Total Posts: 230   [ # 26 ]

Thx for the reply John.
Ops… i have not read the first line raspberry i have tryed to use AWSD smile

To enhance playability i have used this

  //
  public var MaxSteeringAngle:Number;
  private var SteerStep:Number;
  private var SteerStepReturn:Number;
  private var LogSteer:Number = 0.0;

  //
  MaxSteeringAngle = 15 * DEGREES_TO_RADIANS;
  //
  SteerStep = MaxSteeringAngle / 8;
  SteerStepReturn = MaxSteeringAngle / 4;

and finally:

  // _vehicleSteering = Math.abs( targetAngle ) / car.getRigidBody().linearVelocity.length;
  CarSpeed = car.getRigidBody().linearVelocity.length;
 

 
  //
  if( keyLeft )
  {
  //
  if( ( LogSteer - SteerStep ) > -MaxSteeringAngle ) LogSteer -= SteerStep;
  }
  else if( keyRight )
  {
  //
  if( ( LogSteer + SteerStep ) < MaxSteeringAngle ) LogSteer += SteerStep;
  }
  else
  {
  //
  if( LogSteer > 0.0 )
  {
    if( ( LogSteer - SteerStepReturn ) >= 0.0 )
    LogSteer -= SteerStepReturn;
    else
    {
    LogSteer = 0.0;
    }
  }
 
  //
  if( LogSteer < 0.0 )
  {
    if( ( LogSteer + SteerStepReturn ) <= 0.0 )
    LogSteer += SteerStepReturn;
    else
    {
    LogSteer = 0.0;
    }
  }
  }
 

 
  _vehicleSteering = Clamp( LogSteer / CarSpeed, -MaxSteeringAngle, MaxSteeringAngle );

otherwise the vehicle is undriveable… also more optimisation are needed !

This is the simple “under development and test - i need to implement and test pieces of code to make sure that everything is working properly” demo:

http://www.estiva2.altervista.org/SiteGames/Kart/Kart.php

So at higher speed the steering speed are reduced to compensate the car speed angular velocity ( wath ? )

( I have no idea what I wrote the last line, hm, hm speed, speed velocity ) smile

 

   

John Brookes, Moderator
Posted: 24 February 2013 04:00 PM   Total Posts: 732   [ # 27 ]

Yeah did similar for another version.
Another way is to just reduce the amount of wheel friction. Although prefer reducing steer input relative to speed.

ps you need a Github account then you can share wink

 

   

Avatar
Luca, Sr. Member
Posted: 24 February 2013 04:43 PM   Total Posts: 230   [ # 28 ]

Simple smile but i need also a new WORKSTATIOOOOOOOOOOON !

with quadro or gtx 690 smile smile

or a TITAN:
http://www.nvidia.it/titan-graphics-card
https://www.youtube.com/watch?v=zkjBNnKr6z4

WOW !

PS: Sorry if it’s not the right post :( but smile

 

   

Avatar
loth, Sr. Member
Posted: 25 February 2013 01:06 AM   Total Posts: 236   [ # 29 ]

well good here the first test is apk compress in a zip for download
thank’s for swc

track and wall are not optimised (8000 face each)
i’m happy to see how fast that run

have to make new track to see full 60 speed

another good point is nexus stay relatively cold

 

File Attachments
LothPhy.zip  (File Size: 1124KB - Downloads: 394)
   

Avatar
Luca, Sr. Member
Posted: 25 February 2013 07:12 AM   Total Posts: 230   [ # 30 ]

Ok, i need a virtual machine smile

https://www.virtualbox.org/wiki/Downloads
http://www.vmlite.com/index.php?option=com_content&view=article&id=68:android&catid=17:vmlitenewsrotator

and, just to know:
http://www.android-x86.org/download

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X