Start Newton on the iPhone

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Start Newton on the iPhone

Postby winstrol » Fri Jul 24, 2009 10:21 pm

Could please somebody send me the running demo of iPhone project with some basic newton objects and collisions ?

Im new on that platform and have big problems to understand whole thing, because, all tutorials are based on visual c and c++ and even simply functions doesn't work in Xcode on demo which is in SDK
Is there any place with some tutorials or basic knowledge how to start with newton on iPhone ?
User avatar
winstrol
 
Posts: 30
Joined: Fri Jul 24, 2009 9:57 pm

Re: Start Newton on the iPhone

Postby Julio Jerez » Sat Jul 25, 2009 11:00 pm

It was my plan to do teh demo but I under stimate the complexity of objective C.
I am sorry for misleading people, I was under the impresion that it will be easier to comver the same Mac demos to the Iphone,
but all of external libraries I am using make it too hard to work with objective C.
I decided to make a series of simpler tutorials tha are simpler to port ot other engines tah do no use too many external libaries.
http://www.newtondynamics.com/downloads/NewtonTutorials.rar

Now the I have the basic one ccompleted I am converting them to Native Objective C for the IPot and IPhone,
I almost have Tutorial 101 running.
I stimate the maybe by the end of the weekend will be able to publish tutorial 101 and 102 with the Mac SDK.

The entire Iphone Project will be in Object tive C so you will no have to wrestle teh demos to figure out what is going on.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Start Newton on the iPhone

Postby winstrol » Wed Jul 29, 2009 6:17 am

WOW it works :) THANK YOU!

is there a simple way to port RigidBodyUtil.cpp to iNewtonRigidBody.mm ?

BTW Julio, when we can expect rest of the tutorials ? :)


anyway, I wanted to implement InputControl by using the way which I've used before in GL ES::
Code: Select all
#define WALK_SPEED 0.005
#define TURN_SPEED 0.01

GLfloat eye[3];// Where we are viewing from
GLfloat center[3];// Where we are looking towards

typedef enum __MOVMENT_TYPE {
   MTNone = 0,
   MTWalkForward,
   MTWAlkBackward,
   MTTurnLeft,
   MTTurnRight
} MovementType;

MovementType currentMovement;


//in - (void)drawView
gluLookAt(eye[0], eye[1], eye[2], center[0], center[1], center[2], 0.0, 1.0, 0.0);

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   
    UITouch *t = [[touches allObjects] objectAtIndex:0];
    CGPoint touchPos = [t locationInView:t.view];
   
    // Determine the location on the screen. We are interested in iPhone 
    // Screen co-ordinates only, not the world co-ordinates
    //  because we are just trying to handle movement.
    //
    // (0, 0)
    //  +-----------+
    //  |           |
    //  |    160    |
    //  |-----------| 160
    //  |     |     |
    //  |     |     |
    //  |-----------| 320
    //  |           |
    //  |           |
    //  +-----------+ (320, 480)
    //
   
    if (touchPos.y < 160) {
        // We are moving forward
        currentMovement = MTWalkForward;
       
    } else if (touchPos.y > 320) {
        // We are moving backward
        currentMovement = MTWAlkBackward;
       
    } else if (touchPos.x < 160) {
        // Turn left
        currentMovement = MTTurnLeft;
    } else {
        // Turn Right
        currentMovement = MTTurnRight;
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   
    currentMovement = MTNone;
}

- (void)handleTouches {
   
    if (currentMovement == MTNone) {
        // We're going nowhere, nothing to do here
        return;
    }
   GLfloat vector[3];
   
    vector[0] = center[0] - eye[0];
    vector[1] = center[1] - eye[1];
    vector[2] = center[2] - eye[2];
   
   switch (currentMovement) {
        case MTWalkForward:
            eye[0] += vector[0] * WALK_SPEED;
            eye[2] += vector[2] * WALK_SPEED;
            center[0] += vector[0] * WALK_SPEED;
            center[2] += vector[2] * WALK_SPEED;
            break;
           
        case MTWAlkBackward:
            eye[0] -= vector[0] * WALK_SPEED;
            eye[2] -= vector[2] * WALK_SPEED;
            center[0] -= vector[0] * WALK_SPEED;
            center[2] -= vector[2] * WALK_SPEED;
            break;
           
        case MTTurnLeft:
            center[0] = eye[0] + cos(-TURN_SPEED)*vector[0] -
         sin(-TURN_SPEED)*vector[2];
            center[2] = eye[2] + sin(-TURN_SPEED)*vector[0] +
         cos(-TURN_SPEED)*vector[2];
            break;
           
        case MTTurnRight:
            center[0] = eye[0] + cos(TURN_SPEED)*vector[0] - sin(TURN_SPEED)*vector[2];
            center[2] = eye[2] + sin(TURN_SPEED)*vector[0] + cos(TURN_SPEED)*vector[2];
            break;
    }
}


//THAT WAY BASED ON:
#pragma mark SGI Copyright Functions

/*
 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice including the dates of first publication and
 * either this permission notice or a reference to
 * http://oss.sgi.com/projects/FreeB/
 * shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Except as contained in this notice, the name of Silicon Graphics, Inc.
 * shall not be used in advertising or otherwise to promote the sale, use or
 * other dealings in this Software without prior written authorization from
 * Silicon Graphics, Inc.
 */

static void normalize(float v[3])
{
    float r;
   
    r = sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] );
    if (r == 0.0) return;
   
    v[0] /= r;
    v[1] /= r;
    v[2] /= r;
}

static void __gluMakeIdentityf(GLfloat m[16])
{
    m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
    m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
    m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
    m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
}

static void cross(float v1[3], float v2[3], float result[3])
{
    result[0] = v1[1]*v2[2] - v1[2]*v2[1];
    result[1] = v1[2]*v2[0] - v1[0]*v2[2];
    result[2] = v1[0]*v2[1] - v1[1]*v2[0];
}

void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx,
            GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy,
            GLfloat upz)
{
    float forward[3], side[3], up[3];
    GLfloat m[4][4];
   
    forward[0] = centerx - eyex;
    forward[1] = centery - eyey;
    forward[2] = centerz - eyez;
   
    up[0] = upx;
    up[1] = upy;
    up[2] = upz;
   
    normalize(forward);
   
    /* Side = forward x up */
    cross(forward, up, side);
    normalize(side);
   
    /* Recompute up as: up = side x forward */
    cross(side, forward, up);
   
    __gluMakeIdentityf(&m[0][0]);
    m[0][0] = side[0];
    m[1][0] = side[1];
    m[2][0] = side[2];
   
    m[0][1] = up[0];
    m[1][1] = up[1];
    m[2][1] = up[2];
   
    m[0][2] = -forward[0];
    m[1][2] = -forward[1];
    m[2][2] = -forward[2];
   
    glMultMatrixf(&m[0][0]);
    glTranslatef(-eyex, -eyey, -eyez);
}




but, can I use gluLookAt(eye.m_x, eye.m_y, eye.m_z, target.m_x, target.m_y, target.m_z, 0.0, 1.0, 0.0); instead of this:
Code: Select all
// compatibility with GL ES, build the camera matrix by hand for
   struct dMatrix camera = GetIdentityMatrix();
   struct dVector front = SubVector (&eye, &target);

   camera.m_right = Scale (&front, 1.0f / sqrt (DotProduct (&front, &front)));
   camera.m_front = CrossProduct (&camera.m_up, &camera.m_right);
   camera.m_front = Scale (&camera.m_front, 1.0f / sqrt (DotProduct (&camera.m_front, &camera.m_front)));
   camera.m_up    = CrossProduct (&camera.m_right, &camera.m_front);
   camera = Transpose(&camera);
   struct dVector posit = RotateVector (&camera, &eye);
   camera.m_posit = SubVector (&camera.m_posit, &posit);
   camera.m_posit.m_w = 1.0f;

in update camera?
If so, where is the best place to put this InputControl obj-c methods?
User avatar
winstrol
 
Posts: 30
Joined: Fri Jul 24, 2009 9:57 pm

Re: Start Newton on the iPhone

Postby Julio Jerez » Thu Jul 30, 2009 11:52 pm

winstrol wrote:WOW it works :) THANK YOU!

is there a simple way to port RigidBodyUtil.cpp to iNewtonRigidBody.mm ?

BTW Julio, when we can expect rest of the tutorials ? :)


RigidBodyUtil.cpp you said, I am glad you mention that. :shock:
Take a look at this, sopme Iphone Pawaaaaaaaaaaaaa, in native Objective C
http://www.newtondynamics.com/downloads/iPhoneTutorials.zip
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Start Newton on the iPhone

Postby winstrol » Fri Jul 31, 2009 12:03 pm

yeaaahhh, nice, THANK YOU a lot !

you don't even know how you are making me happy :)

I can't wait for the rest of the tutorials


^^edit^^ I don't know what happened, but today when I ran the same project problem about unnatural boxes visible disapeared :)
User avatar
winstrol
 
Posts: 30
Joined: Fri Jul 24, 2009 9:57 pm

Re: Start Newton on the iPhone

Postby winstrol » Sat Aug 01, 2009 10:49 am

can somebody please tell me, because I didn't find it on board:
1> how can I turn on the shadows ?
2> how can I add the *.3ds models from "RayCast/ConvexCast Car Preview" to the scene ?
User avatar
winstrol
 
Posts: 30
Joined: Fri Jul 24, 2009 9:57 pm

Re: Start Newton on the iPhone

Postby JernejL » Sat Aug 01, 2009 12:45 pm

You don't just.. "turn on the shadows", you are definetly showing lack of understanding of current 3d graphics, please go read some article on rendering, because your questions are not related to newton.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Start Newton on the iPhone

Postby Julio Jerez » Sat Aug 01, 2009 2:53 pm

winstrol wrote:I can't wait for the rest of the tutorials

Joint Pawaaaaaaaaa are in know.

winstrol wrote:^^edit^^ I don't know what happened, but today when I ran the same project problem about unnatural boxes visible disapeared :)

I get that some time, teh onle way to get to workl is by deleting teh application form teh Organizer in xCode

I saw you demo, I guess that the GlutCamera function is the same I implemented, it just need to add the navagation commnad.
I will do that leter, BTW your idea to rotate the perpective view for a panoramic view is very cool, I added that to the toturials now.

I have a qwestion I see to stack many boxes in your demo, how is the performance in your device?
In my iPot Touch is very slow. I am curiuos as if the iPhones are fasters that the IPots.
I hear that the IPot/Iphone supports SIMD but I have not found any Docs about that.
I will post on the Mac forum to see what I can find.

I appears that In the Mac forum there are some users that do no liek taht I am compiling Newton for IPhone and react
hostile to my questions, and I do no know why since they do not knwo me and I do not know them.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Start Newton on the iPhone

Postby winstrol » Tue Aug 04, 2009 10:02 am

Julio Jerez wrote: GlutCamera function is the same I implemented, it just need to add the navagation commnad.

I did add the navigation command in demo which I sent you, but it works differently, because, when I push "rotate right" it only rotate cameraDir moving point, but not the view like in gluLookAt :(

Julio Jerez wrote:I have a qwestion I see to stack many boxes in your demo, how is the performance in your device?
In my iPot Touch is very slow. I am curiuos as if the iPhones are fasters that the IPots.

I am going to have device, but now I'am only testing in simulator, but I heard, iPod is little bit stronger. than 2G iPhone

Julio Jerez wrote:I hear that the IPot/Iphone supports SIMD but I have not found any Docs about that.
I will post on the Mac forum to see what I can find.

I don't know much about SIMD

Delfi wrote:You don't just.. "turn on the shadows", you are definetly showing lack of understanding of current 3d graphics, please go read some article on rendering, because your questions are not related to newton.
:) I thaught if in Newton are things like glLighting, shadows could be to :) Basically I wanted to know where can I apply code to dynamic moving things which are not draw in drawView function, but now I know that and sad me lack of stencil buffer in OpenGl ES 1.1.


Can somebody please tell me how can I add the *.3ds models from "RayCast/ConvexCast Car Preview" to the scene ? (example of 3ds loader which is used there to create mesh data)
I can't wait to play with cars in iPhone :)
User avatar
winstrol
 
Posts: 30
Joined: Fri Jul 24, 2009 9:57 pm

Re: Start Newton on the iPhone

Postby martinsm » Tue Aug 04, 2009 12:24 pm

Julio Jerez wrote:I hear that the IPot/Iphone supports SIMD but I have not found any Docs about that.

Yes, iPhone supports SIMD with VFP instructions: http://en.wikipedia.org/wiki/ARM_architecture#VFP

Note that in the new iPhone 3GS using VFP leads actually to worse performance. But there is some new SIMD instructions for ARM processor - called Neon - that performs much better: http://diaryofagraphicsprogrammer.blogs ... -code.html
Some timings for matrix multiplication:
Code: Select all
iPhone 2G C: 15401 microseconds
iPhone 2G VFP: 4094 microseconds

iPhone 3GS C: 9444 microseconds
iPhone 3GS VFP: 19485 microseconds
iPhone 3GS Neon: 2134 microseconds.


Here is some math routines (Matrix Multiply by other Matrix or Vector) from Oolong engine that uses VFP or Neon: http://code.google.com/p/oolongengine/s ... e%3Dclosed
martinsm
 
Posts: 86
Joined: Mon Dec 19, 2005 3:15 pm
Location: Latvia

Re: Start Newton on the iPhone

Postby Julio Jerez » Tue Aug 04, 2009 12:51 pm

martinsm wrote:Note that in the new iPhone 3GS using VFP leads actually to worse performance

I guess I will go wit this.

I find too extreme, having to program in assembly just the to teh simd instrutions.
I was hopping Apple add some sort of intrisic to eh complier.
I guess than until them we will nedd to settle wi the copiler job.

It is a chame they did not add intrisics to teh SDK, it seem suc simple tack with GGCC..
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Start Newton on the iPhone

Postby martinsm » Thu Aug 06, 2009 11:03 am

Actually today I found out that there is intrinsics for NEON similar as there is for SSE.
http://gcc.gnu.org/onlinedocs/gcc/ARM-N ... nsics.html
So iPhone port can be optimized without assembly. This of course will work only for 3GS devices.

Here some info about Neon instructions:
http://monkeystylegames.com/?p=89
http://monkeystylegames.com/?p=82
martinsm
 
Posts: 86
Joined: Mon Dec 19, 2005 3:15 pm
Location: Latvia

Re: Start Newton on the iPhone

Postby Julio Jerez » Thu Aug 06, 2009 1:59 pm

This is absolutly awesome.
http://monkeystylegames.com/?p=82

and I right thinking that xcode will make a univerval binary tah will work on all ARM CPUs?
I can no way to try this out this weekened

Man oh man so much work and so litel time.
I think some new Pawaaaaaaa just have arrive to the iNewton for the Iphone.

Thank you man .
You have really being very helpful to me.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Start Newton on the iPhone

Postby martinsm » Thu Aug 06, 2009 4:02 pm

Julio Jerez wrote:and I right thinking that xcode will make a univerval binary tah will work on all ARM CPUs?

hm.. what "all ARM CPUs"?
Afaik xcode can compile ARM code only for iPodTouch/iPhone cpu's.
martinsm
 
Posts: 86
Joined: Mon Dec 19, 2005 3:15 pm
Location: Latvia

Re: Start Newton on the iPhone

Postby Julio Jerez » Thu Aug 06, 2009 5:33 pm

I thonk The ARM7 is the CPU inside teh Iphone an dIpot
Cortex-A8 and VFP are math coprossesors
I think the that Cortex-A8 is the Neo stuff which think to be better than VFP.

It is like the the old days whn ethe Intel 386 and the motorola 68020 had external Math coprosseror for the floating point stuff. now they are vectors units.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 11 guests

cron