EzDevInfo.com

cocos3d

Cocos3D is a sophisticated, yet intuitive and easy-to-use, 3D application development framework for the iOS platform. With Cocos3D, you can build sophisticated, dynamic 3D games and applications using Objective-C.

How to register touch event cocos3d

I have tried to find a way of registering a touch event in cocos3d such as TOUCHESBEGAN but that does not exist, only

    -(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {
    NSLog(@"hello");
    }

Bu that does not log "hello". How can this be done?


Source: (StackOverflow)

Texture coordinate Cocos3d [closed]

Here is how I put my texture on my object :

_obj = (CC3MeshNode *)[_world getNodeNamed:@"s0"];
_obj.material.texture = [CC3Texture textureFromFile:@"objTextureLayout.png"];

My object is loaded from 3DMAX and I don't understand why my texture coordinate (from 3DMax) is lost...

An other problem, I don't understand why my normals is flipped on a simple polygon. What could I've forgotten ?

Any suggestion ? I can post some screenshot or even the model with texture for a best comprehension for anybody who can help me.


Source: (StackOverflow)

Advertisements

How to import 3dmax model in cocos3d Example iphone

I am working with cocos3d Game development I have to import 3dmax model in my application can anyone suggest how to work with cocos3d??


Source: (StackOverflow)

Collision detection in 3d world

I am creating an 3d car racing game and till now i have integrated accelerometer and i can move the car through the city the only thing now remaining in my game is collision detection ... i want to stop my car when it bangs on wall etc ...

how can i do that ? i know boundingVolume property ,but i am having an city(3d world as a single node ) and car so how can detect when it collides wall etc ?

please can you tell me what should be my approach ? any sample code? please help as i am new to this and don't have any experience in it ...

Thanks Amrut


Source: (StackOverflow)

OpenGL ES object rotation around Z axis

I have an object on my screen which is presented rotated and panned, But i have 2 problems regarding the z axis rotations. It's a bit tricky to explain so i uploaded 2 videos to describe each problem.

1) Reverse rotation : After rotating the object around the x axis, the z rotations are being reversed and as it should be.

2) Wrong Z axis rotation : Again, After rotating the object around the x axis, i'm trying to rotate the object around the z axis and the rotation results in a different axis rotations.

I do believe the video's describe the problems well.

EDIT: UPDATE #1

Ok, i thought i found the solution, which was rotating only the camera around the Z axis, And perform X and Y rotations on the model itself. This seemed to be good, But of course it led to a new problem described in this VIDEO (it's in the 23'd second, the rest is to show how it is being done).

The reason this is happening is the axis system of the object is being rotated and when i am doing a Z axis rotation followed by a X or Y axis rotations, The results are wrong.

I just don't know how to rotate the object alone from the axis system, so that the rotations will be done correctly.

Now, for the code part:

The rendering function:

- (void)render:(CADisplayLink*)displayLink {
    ...

    CC3GLMatrix *projection = [CC3GLMatrix matrix];
    float h = 4.0f * self.frame.size.height / self.frame.size.width;
    [projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:100];
    glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix);

    [modelView populateFromTranslation:_currentPan];
    [modelView rotateBy:_currentRotation];
    [modelView rotateByZ:zRotationEnd];

    glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix);
    ...        
}

X and Y rotations:

- (void) rotateAroundX:(float) x andY:(float) y newRotate:(BOOL) isNewRotate
{
    if (isNewRotate) {
        rotationStart = CC3VectorMake(0.0, 0.0, 0.0);
    }

    int rotationDirection = ceil(zRotationEnd/90);
    if (rotationDirection % 4 == 2 || rotationDirection % 4 == 3) {
        rotationEnd.x = rotationEnd.x - (x-rotationStart.x);
        rotationEnd.y = rotationEnd.y - (y-rotationStart.y);
    } else {
        rotationEnd.x = rotationEnd.x + (x-rotationStart.x);
        rotationEnd.y = rotationEnd.y + (y-rotationStart.y);
    }

    rotationStart.x = x;
    rotationStart.y = y;

    _currentRotation = CC3VectorMake(rotationEnd.y, rotationEnd.x, 0);
    NSLog(@"Current x is: %f y is: %f z is: %f",_currentRotation.x,_currentRotation.y,zRotationEnd);
}

And the relevant calling part:

if(sender.numberOfTouches == 1)
    {
        BOOL started = false;
        CGPoint rotation = [sender translationInView:sender.view];
        float x = rotation.x;
        float y = rotation.y;
        if (sender.state == UIGestureRecognizerStateBegan)
        {
            started = true;
        }
        [self.glView rotateAroundX:x andY:y newRotate:started];
    }

The Z rotation function:

- (void) rotateAroundZ:(float) z newRotate:(BOOL) isNewRotate
{
    if (isNewRotate) {
        zRotationStart = 0;
    }
    zRotationEnd = zRotationEnd - (z - zRotationStart);
    zRotationStart = z;
}

And the relevant calling part:

- (IBAction)rotation:(UIRotationGestureRecognizer *)sender {
    BOOL started = false;
    float rotation = RadiansToDegrees([sender rotation]);
    if (sender.state == UIGestureRecognizerStateBegan)
    {
        started = true;
    }
    [self.glView rotateAroundZ:rotation newRotate:started];
    NSLog(@"Rotation %f", rotation);
}

The shader:

attribute vec4 Position;
attribute vec4 SourceColor;

varying vec4 DestinationColor;

uniform mat4 Projection;
uniform mat4 Modelview;

attribute vec2 TexCoordIn;
varying vec2 TexCoordOut;

void main(void) {
    DestinationColor = SourceColor;
    gl_Position = Projection * Modelview * Position;
    TexCoordOut = TexCoordIn;
}

Would really appreciate any help.

Cheers!


Source: (StackOverflow)

Call an action at specific intervals in iOS

I am trying to invoke a function that contains ccactioninterval in Cocos3d. I want to call that function at specific time intervals.When I tried NSTimer , i found that it works sometimes and sometimes not.

      NSTimer makeTarget=[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(createTargets) userInfo:nil repeats:YES];

Here createTargets is the function that contains action events. when i run the function straightit works fine for single time. Problem comes when i try to schedule it. I ve tried different methods already explained for related questions . But nothing worked for me. . . .

Here is the code

-(void) addTargets {      
    NSTimer *makeTarget = [NSTimer scheduledTimerWithTimeInterval:2.0
              target:self selector:@selector(createTargets) userInfo:nil repeats:YES]; 
}

-(void)createTargets {
    CC3MeshNode *target = (CC3MeshNode*)[self getNodeNamed: @"obj1"];    
    int minVal=-5;
    int maxVal=5;    
    float avgVal; 
    avgVal = maxVal- minVal;      
    float Value = ((float)arc4random()/ARC4RANDOM_MAX)*avgVal+minVal ;          
    [target setLocation:cc3v(Value, 5.0, 0.0)];    
    CCActionInterval *moveTarget = [CC3MoveBy actionWithDuration:7.0 moveBy:cc3v(0.0, -10.0, 0.0)];     
    CCActionInterval *removeTarget = [CCCallFuncN actionWithTarget:self selector:@selector(removeTarget:)];       
    [target runAction:[CCSequence actionOne:moveTarget two:removeTarget]];   
}

-(void)removeTarget:(CC3MeshNode*)targ {  
    [self removeChild:targ];  
    targ=nil; 
}

Source: (StackOverflow)

How to correctly display 3d model in Cocos3d using makehuman, blender and PVRShaman?

I have created a human model using makehuman and blender and when I used this model to display in app it looks like this

enter image description here

and in Blender it looks like this

enter image description here

and PVRShaman it looks like this

enter image description here

While opening in PVRShaman it shows some error similar to this

enter image description here

and the code I am using to display this

CC3Camera* cam = [CC3Camera nodeWithName: @"Camera"];
    cam.location = cc3v( 0.0, 0.0, 50.0 );
    [self addChild: cam];
CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"];
    lamp.location = cc3v( -2.0, 0.0, 0.0 );
    lamp.isDirectionalOnly = NO;
    [cam addChild: lamp];
CC3ResourceNode* rezNode = [CC3PODResourceNode nodeFromFile: @"man.pod"];
    [self addChild: rezNode];
self.opacity = kCCOpacityFull;
[self selectShaders];
[self createBoundingVolumes];
[self createGLBuffers];
    [self releaseRedundantContent];
CC3MeshNode* helloTxt = (CC3MeshNode*)[self getNodeNamed: @"man"];
    [helloTxt runAction: [CC3ActionRotateForever actionWithRotationRate: cc3v(0, 0, 20)]];

EDIT : Problem :

  1. As it appear why model is not looking as it is looking in blender after render in simulator(texture and skull ?

  2. Why Model has no texture detail in blender without rendering it ?

  3. Why there is an error file not found in PVRShaman ?


Source: (StackOverflow)

Display 3D-Object with COCOS3D on top of AR-View

I work on an app, which scans an image and shows you a 3D-Object or a video on top of the image target. Normal AR-App. For that AR stuff I usw the Vuforia SDK. The problem is, that the Vuforia SDK don't support animated 3D-Objects and for that I use cocos3d.

So I created a basic cocos3d app and included my vuforia stuff for the AR. This works good and the app displays normal 3D-Objects and videos. This was the background, now the problem.

The first view I have is my camera view, which scans the images. If I scan now a specified target, I want to show an animated 3D-Object. For that, I display the cocos3d view on top of the AR-View. The cocos3d view is transparent and is displayed on top of the AR-View (tested this with a simple button in the cocos3d view).

The problem is, that I'am not able to display a animated 3D-Object. I tested some options but none of them worked because I don't really have an idea how to do that. My current code:

CCDirector *director = CCDirector.sharedDirector;
EAGLViewCC *glView = [EAGLViewCC viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGBA8 depthFormat:GL_DEPTH_COMPONENT16_OES];

[director setOpenGLView:glView];

[window addSubview:director.openGLView];

After that I have a layer and add the test scene to my layer (Standard from the example). But than I don't know how to display it. It tried this:

[director pushScene:scene];

but no luck. In the example, they use this code to show the object (viewController is of type "CC3DeviceCameraOverlayUIViewController").

[viewController runSceneOnNode: mainLayer];

Why don't I use the viewController? Because I couldn't get the view transparent. So how do I get the 3D-Object displayed in my view? What do I have to do? Am I completely wrong?


Source: (StackOverflow)

Mesh node location not updated, in cocos3d

I am developing a board game using Ball, in cocos3d. In that I've given an action in touchevent. I'm printing the location to the console using NSLog().

Here is the code

-(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {     

CCActionInterval *BounceAction1=[CC3MoveTo actionWithDuration:0.1 moveTo:cc3v(0.0, -5.0, -0.7)];

switch (touchType) {

    case kCCTouchBegan:

        [Ball runAction:BounceAction1];

         NSLog(@"Location of x=%f and y=%f", Ball.globalLocation.x, Ball.globalLocation.y );

    break;
}

Here, 'Ball' is a MeshNode. It's location is at origin cc3v(0.0, 0.0, 0.0).

When I run and touch, I find the ball moving to the specified position. But I get the Ball's location as:

Location of x=0.000000 and y=0.000000

When i touch again, i find the ball is not moving (as it has already moved to the specified location). But then it shows Ball's location as:

Location of x=0.000000 and y=-6.000000

Why I can't find the location the first time?


Source: (StackOverflow)

Simple polygon in cocos3d

I am trying to implement a simple 3d object on the cocos3d template.

Usually you get the object from a POD file or similar.

But what i need is to make it by code in the application.

I have tried CC3BoxNode with CC3BoundingBox. But it isn't what I am looking for.

I need to create something similar to that. enter image description here


Source: (StackOverflow)

Cocos 3D POD file format for iphone developing

I am new in cocos 3d developing.

I have used cocos-2d for iphone and ipad, in which we have to used .png file for UI.
But in this Cocos-3d programming, .POD file format have been used. I don't know about POD file format and how to access that node name from .POD file?


Source: (StackOverflow)

Any good tutorials for the open source 3d frameworks like cocos3d? [closed]

Is there any good tutorial for the 3d game free frameworks like cocos3d? the isgl3d has more detailed tutorials and samples than cocos3d, is there any good stuff for either?

Thanks,

PS. even the StackOverflow has too many unanswered question under the cocos3d tag.


Source: (StackOverflow)

How can I Install Cocos3D for iPhone/iPad?

How can I Install Cocos3D for iPhone/iPad?


Source: (StackOverflow)

Add Cocos3D to existing XCode/iOS project

So I've recently successfully installed Cocos3D on my computer and I am able to create new "iOS" projects in xCode using the Cocos3D starter template. However, I currently don't need to start a new project. I just need to be able to integrate Cocos3D into an existing "iOS" project I am developing, the reason mostly being that the app for the most part will be a "typical" iOS app but only a handful of views/view controllers need to be able to handle 3D graphics.

So does anybody here know an easy way to do this or can point me in the direction of an (easy to follow) tutorial?


Source: (StackOverflow)

How to create a simple 3d sphere for cocos3d using blender and PowerVR SDK

I am a fresher in cocos3d. I want to create a simple project - a 3d sphere rotating. i have designed a 3d sphere using blender. So i want help in creating collada file and pod file. What all are the things should be taken care while creating this simple 3d object using blender and PowerVR SDK. Thanks


Source: (StackOverflow)