Moderators: Sascha Willems, walaber
#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);
}
// 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;
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 ?
winstrol wrote:I can't wait for the rest of the tutorials
winstrol wrote:^^edit^^ I don't know what happened, but today when I ran the same project problem about unnatural boxes visible disapeared
Julio Jerez wrote: GlutCamera function is the same I implemented, it just need to add the navagation commnad.
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.
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 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.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.
Julio Jerez wrote:I hear that the IPot/Iphone supports SIMD but I have not found any Docs about that.
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.
martinsm wrote:Note that in the new iPhone 3GS using VFP leads actually to worse performance
Julio Jerez wrote:and I right thinking that xcode will make a univerval binary tah will work on all ARM CPUs?
Users browsing this forum: No registered users and 2 guests