Esempio n. 1
0
internal Vector3 getRotatedVec3(Vector3 pos, FacingSide side, WorldDims dims, WorldDims sizes) {
    if (side == Front) {
    } else if (side == Left){
        return Vector3Make(pos.y, (dims.x * sizes.x) - pos.x, pos.z);
    } else if (side == Right){
        return Vector3Make(( (dims.y * sizes.y) - pos.y) + sizes.y, pos.x, pos.z);
    }
    return Vector3Make(pos.x, pos.y, pos.z);
}
Esempio n. 2
0
void GameAsteroid::CalculateParameters(bool moveToCenter, Vector3 direction, float randomMuliplier)
{
    Vector2 toCenter = Vector2Make(0, 0);
    Vector2 center = _delegate->FieldCenter();
    if (moveToCenter) {
        Vector2 position = GetPosition();
        toCenter = Vector2Subtract(center, position);
        toCenter = Vector2Normalize(toCenter);
    }
    Vector2 random = Vector2Make(cosf(_random), sinf(_random));
    
    
    _moveVector = Vector3Make(toCenter.x * 2.0 + random.x *randomMuliplier + direction.x  , toCenter.y * 2.0 + random.y * randomMuliplier + direction.y, 0);
    
    float timex = center.x / _moveVector.x;
    float timey = center.y / _moveVector.y;
    float time = ____max(timey, timex) / 7;
    _existTimer = new MAXAnimationWait(time);
    _existTimer->_delegate = this;
    MAXAnimationManager::SharedAnimationManager()->AddAnimation(_existTimer);
    
}
Esempio n. 3
0
internal void initialize_memory( PermanentState *permanent, Node16Arena *node16, RenderState *renderer, Memory* memory) {
    permanent->dynamic_blocks     = (StaticBlock*) PUSH_ARRAY(&permanent->arena, (16384), StaticBlock);
    permanent->static_blocks      = (StaticBlock*) PUSH_ARRAY(&permanent->arena, (16384), StaticBlock);
    permanent->transparent_blocks = (StaticBlock*) PUSH_ARRAY(&permanent->arena, (16384), StaticBlock);
    permanent->actors             = (Actor*) PUSH_ARRAY(&permanent->arena, (16384*4), Actor);
    permanent->paths              = (ActorPath*) PUSH_ARRAY(&permanent->arena, (16384*4), ActorPath);
    permanent->steer_data         = (ActorSteerData*) PUSH_ARRAY(&permanent->arena, (16384*4), ActorSteerData);
    for (int i = 0; i < 16384*4; i++) {
        permanent->steer_data[i].mass      = 1.0f;
        permanent->steer_data[i].max_force = 10;
        permanent->steer_data[i].max_speed = 50 + rand_float() * 80;
    }
    permanent->anim_data = (ActorAnimData*) PUSH_ARRAY(&permanent->arena, (16384*4), ActorAnimData);

    for (int i = 0; i < 16384*4; i++) {
        permanent->anim_data[i].frame = 4;
    }
    for (int i = 0; i < 16384*4; i++) {
        Node16 *Sentinel = (Node16 *) PUSH_STRUCT(&node16->arena, Node16);
        permanent->paths[i].Sentinel            = Sentinel;
        permanent->paths[i].Sentinel->Next      = Sentinel;
        permanent->paths[i].Sentinel->Prev      = Sentinel;
        permanent->actors[i].index              = i;
        permanent->paths[i].Sentinel->path.node = Vector3Make(-999,-999,-999);
    }

    node16->Free = PUSH_STRUCT(&node16->arena, Node16);
    node16->Free->Next = node16->Free;
    node16->Free->Prev = node16->Free;

    permanent->glyphs = (Glyph*) PUSH_ARRAY(&permanent->arena, (16384), Glyph);
    permanent->colored_lines = (ColoredLine*) PUSH_ARRAY(&permanent->arena, (16384), ColoredLine);

    BlockTextureAtlasPosition texture_atlas_data[BlockTotal];
    fill_generated_values(generated_frames);
    fill_generated_complex_values(generated_body_frames);

    texture_atlas_data[Floor]        = convertSimpleFrameToBlockTexturePos(generated_frames[BL_floor_000], 0, 0);
    texture_atlas_data[WallBlock]    = convertSimpleFrameToBlockTexturePos(generated_frames[BL_wall_000], 0, 0);
    texture_atlas_data[WindowBlock]  = convertSimpleFrameToBlockTexturePos(generated_frames[BL_window_000], 0, 0);
    texture_atlas_data[LadderUp]     = convertSimpleFrameToBlockTexturePos(generated_frames[BL_ladder_up_000], 0, 0);
    texture_atlas_data[LadderUpDown] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_ladder_up_down_000], 0, 0);
    texture_atlas_data[LadderDown]   = convertSimpleFrameToBlockTexturePos(generated_frames[BL_ladder_down_000], 0, 0);

    texture_atlas_data[EscalatorDown1S] = texture_atlas_data[EscalatorUp1S] = texture_atlas_data[Stairs1S] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_south_up_000], 0, 0);
    texture_atlas_data[EscalatorDown2S] = texture_atlas_data[EscalatorUp2S] = texture_atlas_data[Stairs2S] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_south_up_000], 0, 24);
    texture_atlas_data[EscalatorDown3S] = texture_atlas_data[EscalatorUp3S] = texture_atlas_data[Stairs3S] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_south_up_000], 0, 48);
    texture_atlas_data[EscalatorDown4S] = texture_atlas_data[EscalatorUp4S] = texture_atlas_data[Stairs4S] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_south_up_000], 0, 72);

    texture_atlas_data[EscalatorDown1N] = texture_atlas_data[EscalatorUp1N] = texture_atlas_data[Stairs1N] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_north_up_000], 0, 0);
    texture_atlas_data[EscalatorDown2N] = texture_atlas_data[EscalatorUp2N] = texture_atlas_data[Stairs2N] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_north_up_000], 0, 24);
    texture_atlas_data[EscalatorDown3N] = texture_atlas_data[EscalatorUp3N] = texture_atlas_data[Stairs3N] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_north_up_000], 0, 48);
    texture_atlas_data[EscalatorDown4N] = texture_atlas_data[EscalatorUp4N] = texture_atlas_data[Stairs4N] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_north_up_000], 0, 72);

    texture_atlas_data[EscalatorDown1W] = texture_atlas_data[EscalatorUp1W] = texture_atlas_data[Stairs1W] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_west_up_000], 0, 0);
    texture_atlas_data[EscalatorDown2W] = texture_atlas_data[EscalatorUp2W] = texture_atlas_data[Stairs2W] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_west_up_000], 0, 24);
    texture_atlas_data[EscalatorDown3W] = texture_atlas_data[EscalatorUp3W] = texture_atlas_data[Stairs3W] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_west_up_000], 0, 48);
    texture_atlas_data[EscalatorDown4W] = texture_atlas_data[EscalatorUp4W] = texture_atlas_data[Stairs4W] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_west_up_000], 0, 72);

    texture_atlas_data[EscalatorDown1E] = texture_atlas_data[EscalatorUp1E] = texture_atlas_data[Stairs1E] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_east_up_000], 0, 0  );
    texture_atlas_data[EscalatorDown2E] = texture_atlas_data[EscalatorUp2E] = texture_atlas_data[Stairs2E] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_east_up_000], 0, 24 );
    texture_atlas_data[EscalatorDown3E] = texture_atlas_data[EscalatorUp3E] = texture_atlas_data[Stairs3E] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_east_up_000], 0, 48 );
    texture_atlas_data[EscalatorDown4E] = texture_atlas_data[EscalatorUp4E] = texture_atlas_data[Stairs4E] = convertSimpleFrameToBlockTexturePos(generated_frames[BL_escalator_east_up_000], 0, 72 );

    int used_static_block_count = 0;
    int used_dynamic_block_count = 0;
    int used_transparent_block_count = 0;

    for (u32 z = 0; z < permanent->dims.z_level ; z++){
        for (u32 y = 0; y< permanent->dims.y; y++){
            for (u32 x = 0; x< permanent->dims.x; x++){
                WorldBlock *b = &permanent->level.blocks[FLATTEN_3D_INDEX(x,y,z,permanent->dims.x, permanent->dims.y)];


                u32 x_ = getRotatedXInt(x, y, facing_side, permanent->dims);
                u32 y_ = getRotatedYInt(x, y, facing_side, permanent->dims);
                Block block = getRotatedBlock(b->object, facing_side);


                permanent->static_blocks[used_static_block_count].is_floor = 0;
                switch (block){
                case WindowBlock:
                    add_transparent_block(x_, y_, z, permanent, &used_transparent_block_count, texture_atlas_data[block]);
                    used_transparent_block_count++;
                    break;

                case WallBlock:
                case LadderUpDown:
                case LadderUp:
                case LadderDown:
                    add_static_block(x_, y_, z, permanent, &used_static_block_count, texture_atlas_data[block]);
                    used_static_block_count++;
                    break;

                case Floor:
                case Stairs1N: case Stairs2N: case Stairs3N: case Stairs4N:
                case Stairs1E: case Stairs2E: case Stairs3E: case Stairs4E:
                case Stairs1S: case Stairs2S: case Stairs3S: case Stairs4S:
                case Stairs1W: case Stairs2W: case Stairs3W: case Stairs4W:
                    add_static_block(x_, y_, z, permanent, &used_static_block_count, texture_atlas_data[block]);
                    permanent->static_blocks[used_static_block_count].is_floor = 1;
                    used_static_block_count++;
                    break;

                case EscalatorUp1N: case EscalatorUp2N: case EscalatorUp3N: case EscalatorUp4N:
                    permanent->dynamic_blocks[used_dynamic_block_count].is_floor = 1;
                    add_dynamic_block(x_, y_, z, permanent, &used_dynamic_block_count, texture_atlas_data[block], BL_escalator_north_up_000, BL_escalator_north_up_011, 0.5f/12, 1);
                    used_dynamic_block_count++;
                    break;
                case EscalatorDown1N: case EscalatorDown2N: case EscalatorDown3N: case EscalatorDown4N:
                    permanent->dynamic_blocks[used_dynamic_block_count].is_floor = 1;
                    add_dynamic_block(x_, y_, z, permanent, &used_dynamic_block_count, texture_atlas_data[block], BL_escalator_north_up_000, BL_escalator_north_up_011, 0.5f/12, 0);
                    used_dynamic_block_count++;
                    break;
                case EscalatorUp1E: case EscalatorUp2E: case EscalatorUp3E: case EscalatorUp4E:
                    permanent->dynamic_blocks[used_dynamic_block_count].is_floor = 1;
                    add_dynamic_block(x_, y_, z, permanent, &used_dynamic_block_count, texture_atlas_data[block], BL_escalator_east_up_000, BL_escalator_east_up_007, 0.5f/8, 1);
                    used_dynamic_block_count++;
                    break;
                case EscalatorDown1E: case EscalatorDown2E: case EscalatorDown3E: case EscalatorDown4E:
                    permanent->dynamic_blocks[used_dynamic_block_count].is_floor = 1;
                    add_dynamic_block(x_, y_, z, permanent, &used_dynamic_block_count, texture_atlas_data[block],  BL_escalator_east_up_000,  BL_escalator_east_up_007, 0.5f/8, 0);
                    used_dynamic_block_count++;
                    break;
                case EscalatorUp1W: case EscalatorUp2W: case EscalatorUp3W: case EscalatorUp4W:
                    permanent->dynamic_blocks[used_dynamic_block_count].is_floor = 1;
                    add_dynamic_block(x_, y_, z, permanent, &used_dynamic_block_count, texture_atlas_data[block], BL_escalator_west_up_000, BL_escalator_west_up_007, 0.5f/8, 1);
                    used_dynamic_block_count++;
                    break;
                case EscalatorDown1W: case EscalatorDown2W: case EscalatorDown3W: case EscalatorDown4W:
                    permanent->dynamic_blocks[used_dynamic_block_count].is_floor = 1;
                    add_dynamic_block(x_, y_, z, permanent, &used_dynamic_block_count, texture_atlas_data[block], BL_escalator_west_up_000, BL_escalator_west_up_007, 0.5f/8, 0);
                    used_dynamic_block_count++;
                    break;
                case EscalatorUp1S: case EscalatorUp2S: case EscalatorUp3S: case EscalatorUp4S:
                    permanent->dynamic_blocks[used_dynamic_block_count].is_floor = 1;
                    add_dynamic_block(x_, y_, z, permanent, &used_dynamic_block_count, texture_atlas_data[block], BL_escalator_south_up_000, BL_escalator_south_up_007, 0.5f/8, 1);
                    used_dynamic_block_count++;
                    break;
                case EscalatorDown1S: case EscalatorDown2S: case EscalatorDown3S: case EscalatorDown4S:
                    permanent->dynamic_blocks[used_dynamic_block_count].is_floor = 1;
                    add_dynamic_block(x_, y_, z, permanent, &used_dynamic_block_count, texture_atlas_data[block], BL_escalator_south_up_000, BL_escalator_south_up_007, 0.5f/8, 0);
                    used_dynamic_block_count++;
                    break;
                case Grass:
                case Wood:
                case Concrete:
                case Nothing:
                case Tiles:
                case Carpet:
                case EscalatorUpMeta:
                case EscalatorDownMeta:
                case StairsMeta:
                case StairsFollowUpMeta:
                case Shaded:
                case BlockTotal:

                default:
                    break;
                }
            }
        }
    }

    permanent->static_block_count      = used_static_block_count;
    permanent->dynamic_block_count     = used_dynamic_block_count;
    permanent->transparent_block_count = used_transparent_block_count;

    set_static_block_batch_sizes(permanent, renderer);
    set_dynamic_block_batch_sizes(permanent, renderer);
    set_transparent_block_batch_sizes(permanent, renderer);

    qsort(permanent->static_blocks, used_static_block_count, sizeof(StaticBlock), sort_static_blocks_front_back);
    qsort(permanent->transparent_blocks, used_transparent_block_count, sizeof(StaticBlock), sort_static_blocks_back_front);

    renderer->needs_prepare = 1;

    set_actor_batch_sizes(permanent, renderer);

    permanent->grid = PUSH_STRUCT(&permanent->arena, Grid);
    init_grid(permanent->grid, &permanent->arena, &permanent->level);
    preprocess_grid(permanent->grid);
    set_colored_line_batch_sizes(permanent, renderer);
    memory->is_initialized = true;

}
Esempio n. 4
0
void CollisionEngine::CalculateCollisions()
{
    _collidedObjects->clear();
    
    //calc
    collidedPoints.clear();
    Vector4 point1;
    Vector4 point2;
    Vector4 linePoint1;
    Vector4 linePoint2;
    Vector4 intersectionPoint;
    Vector4 intersectionPointTmp;
    for (int j = 0; j < _objectMeshes->GetCount(); j++)
    {
        CollisionObject *mesh = _objectMeshes->objectAtIndex(j);
        if (mesh->GetCollisionObjectPointsCount() > _pointBuffer->GetSize())
            _pointBuffer->Resize(mesh->GetCollisionObjectPointsCount());
        
        {
            //transform points
            Matrix4 transform = mesh->GetCollisionObjectTransform();
            for (int i = 0; i < mesh->GetCollisionObjectPointsCount(); i++)
                _pointBuffer->GetArrayPointer()[i] = Matrix4MultiplyVector4(transform, mesh->GetCollisionObjectPoints()[i]);
        }
        
        Vector4 tmp =_pointBuffer->objectAtIndex(2);
        tmp = tmp;
        
        for (int i = 0; i < _objectPoints->GetCount(); i++)
        {
            CollisionObject *point = _objectPoints->objectAtIndex(i);
            if (collidedPoints.indexOf(point) != -1)
                continue;
            
            point1 = Vector4MakeWithVector3(Matrix4GetTranslation(point->GetCollisionObjectPreviousTransform()), 1);
            point2 = Vector4MakeWithVector3(Matrix4GetTranslation(point->GetCollisionObjectTransform()), 1);
            
            int lineCount = mesh->GetCollisionObjectPointsCount() / 2;
            float intersectonRange = 1000;
            bool foundIntersection = false;
            for (int p = 0; p < lineCount; p++) {
                linePoint1 = _pointBuffer->objectAtIndex(p * 2);
                linePoint2 = _pointBuffer->objectAtIndex(p * 2 + 1);
                
                if (intersection(linePoint1, linePoint2, point1, point2, &intersectionPointTmp)) {
                    foundIntersection = true;
                    float currentIntersectonRange = Vector3LengthSquired(Vector3Make(point1.x - intersectionPointTmp.x, point1.y - intersectionPointTmp.y, point1.z - intersectionPointTmp.z));
                    if (currentIntersectonRange < intersectonRange) {
                        intersectionPoint = intersectionPointTmp;
                        intersectonRange = currentIntersectonRange;
                    }
                }
            }
            if (foundIntersection) {
                _collidedObjects->addObject(CollisionPair(mesh, point));
                break; //only 1 collision - much more easy
            }
        }
    }
    
    
    //updateObjects
    for (int i = 0; i < _objectPoints->GetCount(); i++)
        _objectPoints->objectAtIndex(i)->Update();
    
    for (int i = 0; i < _objectMeshes->GetCount(); i++)
        _objectMeshes->objectAtIndex(i)->Update();
    
}
Esempio n. 5
0
GameAsteroid::GameAsteroid(bool large)
:_delegate(NULL), _isLarge(large)
{
    _random = nextFloatMinMax(0, M_2_PI);
    _rotationRandom = nextFloatMinMax(-1, 1);
    shared_ptr<EngineWireframe> wf = nullptr;
    CollisionObject *collisionObject = NULL;
    
    Vector3 vertices[10];
    int count = 10;
    if (_isLarge)
    {
        vertices[0].x = -10; vertices[0].y = 10; vertices[0].z = 0;
        vertices[1].x = 12; vertices[1].y = 13; vertices[1].z = 0;
        
        vertices[2].x = 12; vertices[2].y = 13; vertices[2].z = 0;
        vertices[3].x = 10; vertices[3].y = -10; vertices[3].z = 0;
        
        vertices[4].x = 10; vertices[4].y = -10; vertices[4].z = 0;
        vertices[5].x = -8; vertices[5].y = -12; vertices[5].z = 0;
        
        vertices[6].x = -8; vertices[6].y = -12; vertices[6].z = 0;
        vertices[7].x = -15; vertices[7].y = 0; vertices[7].z = 0;
        
        vertices[8].x = -15; vertices[8].y = 0; vertices[8].z = 0;
        vertices[9].x = -10; vertices[9].y = 10; vertices[9].z = 0;
    }
    else
    {
        count = 6;
        vertices[0].x = 5; vertices[0].y = 10; vertices[0].z = 0;
        vertices[1].x = -6; vertices[1].y = 7; vertices[1].z = 0;
        
        vertices[2].x = -6; vertices[2].y = 7; vertices[2].z = 0;
        vertices[3].x = 10; vertices[3].y = -10; vertices[3].z = 0;
        
        vertices[4].x = 10; vertices[4].y = -10; vertices[4].z = 0;
        vertices[5].x = 5; vertices[5].y = 10; vertices[5].z = 0;
    }
    wf = shared_ptr<EngineWireframe>(new EngineWireframe(count, vertices));
    Vector4 *points = new Vector4[count];
    for (int i = 0; i < count; i++) {
        points[i].x = vertices[i].x;
        points[i].y = vertices[i].y;
        points[i].z = vertices[i].z;
        points[i].w = 1;
    }
    collisionObject = new CollisionObject(points, count);
    collisionObject->_owner_w = this;
    
    
    UnAnimRenderObject *_renderObject = new UnAnimRenderObject(wf);
    ObjectControlledBehaviorModel *_behaviourModel = new ObjectControlledBehaviorModel(collisionObject, this, true);
    
    SimpleWireframeObject *object = new SimpleWireframeObject(_renderObject, _behaviourModel, Vector4Make(1, 1, 1, 1));
    this->_object = object;
    
    _directionVector = Vector3Make(1, 0, 0);
    
    _startTime = engine->FullTime();
    
    
}
Esempio n. 6
0
Vector3 GameAsteroid::GetDirectionVector(void *sender)
{
    float elapsed = engine->FullTime() - _startTime;
    float rotation = elapsed * _rotationRandom;
    return Vector3Make(cosf(rotation), sinf(rotation), 0);
}