Ejemplo n.º 1
0
void  Box::create(Vector3 origin, float length, float depth, float width)
{
	this->center = origin;
	this->sizeX = length;
	this->sizeY = depth;
	this->sizeZ = width;

 	Vector3 V0(origin.x()-(length/2), origin.y()-(depth/2), origin.z()-(width/2));
 	Vector3 V1(origin.x()+(length/2), origin.y()-(depth/2), origin.z()-(width/2));
 	Vector3 V2(origin.x()+(length/2), origin.y()+(depth/2), origin.z()-(width/2));
	Vector3 V3(origin.x()-(length/2), origin.y()+(depth/2), origin.z()-(width/2));
	Vector3 V4(origin.x()-(length/2), origin.y()-(depth/2), origin.z()+(width/2));
	Vector3 V5(origin.x()+(length/2), origin.y()-(depth/2), origin.z()+(width/2));
	Vector3 V6(origin.x()+(length/2), origin.y()+(depth/2), origin.z()+(width/2));
	Vector3 V7(origin.x()-(length/2), origin.y()+(depth/2), origin.z()+(width/2));

	vector<Quadrilateral> Q;
	Q.push_back(Quadrilateral(V0,V1,V5,V4));
	Q.push_back(Quadrilateral(V2,V3,V7,V6));
	Q.push_back(Quadrilateral(V0,V4,V7,V3));
	Q.push_back(Quadrilateral(V5,V1,V2,V6));
	Q.push_back(Quadrilateral(V1,V0,V3,V2));
	Q.push_back(Quadrilateral(V4,V5,V6,V7));
        setFaces(Q);

	calculateMinMax();
}
Ejemplo n.º 2
0
Box::Box(vector<Quadrilateral> faces):ObjectGeo()
{
	assert(faces.size()==6);
	this->faces.clear();
	for(unsigned int i=0;i<faces.size();i++)
		this->faces.push_back(faces[i]);
	calculateMinMax();
}
Ejemplo n.º 3
0
void FITSImage::calculateStats(bool refresh)
{
    calculateMinMax(refresh);
    // #1 call average, average is used in std deviation
    stats.average = average();
    // #2 call std deviation
    stats.stddev  = stddev();

    if (refresh && markStars)
        // Let's try to find star positions again after transformation
        starsSearched = false;

}
Ejemplo n.º 4
0
void CCJSPrimitiveFBX::moveVerticesToOrigin()
{
    if( movedToOrigin == false )
    {
        const CCVector3 origin = getOrigin();

        if( animations != NULL && animations->length > 0 )
        {
            for( int animationIndex=0; animationIndex<animations->length; ++animationIndex )
            {
                Animation &animation = *animations->list[animationIndex];
                for( int frameIndex=0; frameIndex<animation.frames.length; ++frameIndex )
                {
                    AnimationFrame &animationFrame = *animation.frames.list[frameIndex];
                    if( animationFrame.submodels.length > 0 )
                    {
                        for( int modelIndex=0; modelIndex<animationFrame.submodels.length; ++modelIndex )
                        {
                            AnimationFrameSubmodel &modelAnimation = *animationFrame.submodels.list[modelIndex];
                            if( modelAnimation.vertices != NULL )
                            {
                                // Find vertices from our submodels
                                for( int subModelIndex=0; subModelIndex<submodels.length; ++subModelIndex )
                                {
                                    Submodel &submodel = *submodels.list[subModelIndex];
                                    if( CCText::Equals( submodel.name, modelAnimation.name ) )
                                    {
                                        int vertexCount = submodel.vertexCount;
                                        for( int vertexIndex=0; vertexIndex<vertexCount; ++vertexIndex )
                                        {
                                            int index = vertexIndex*3;
                                            modelAnimation.vertices[index+0] -= origin.x;
                                            modelAnimation.vertices[index+1] -= origin.y;
                                            modelAnimation.vertices[index+2] -= origin.z;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        for( int subModelIndex=0; subModelIndex<submodels.length; ++subModelIndex )
        {
            Submodel &submodel = *submodels.list[subModelIndex];
            for( int i=0; i<submodel.vertexCount; ++i )
            {
                int index = i*3;
                int x = index+0;
                int y = index+1;
                int z = index+2;

                submodel.vertices[x] -= origin[0];
                submodel.vertices[y] -= origin[1];
                submodel.vertices[z] -= origin[2];
                submodel.skinnedVertices[x] -= origin[0];
                submodel.skinnedVertices[y] -= origin[1];
                submodel.skinnedVertices[z] -= origin[2];
            }

            gRenderer->updateVertexPointer( ATTRIB_VERTEX, submodel.skinnedVertices );
        }

        calculateMinMax();
        movedToOrigin = true;
    }
}
Ejemplo n.º 5
0
bool CCJSPrimitiveFBX::loadData(const char *fileData)
{
    json_error_t error;
    json_t *json = json_loads( fileData, 0, &error );
    if( json != NULL )
    {
        fileSize = strlen( fileData );

        if( json_object_get( json, "animations" ) )
        {
            animations = new CCList<Animation>();

            json_t *json_animations = json_object_get( json, "animations" );
            if( json_animations != NULL && json_is_array( json_animations ) )
            {
                const uint json_animations_length = json_array_size( json_animations );
                for( uint animationIndex=0; animationIndex<json_animations_length; ++animationIndex )
                {
                    json_t *json_animation = json_array_get( json_animations, animationIndex );
                    if( json_animation != NULL )
                    {
                        Animation *animation = new Animation();
                        animations->add( animation );

                        json_object_string( animation->name, json_animation, "name" );
                        json_t *json_animation_frames = json_object_get( json_animation, "frames" );
                        if( json_animation_frames != NULL && json_is_array( json_animation_frames ) )
                        {
                            const uint json_animation_frames_length = json_array_size( json_animation_frames );
                            for( uint frameIndex=0; frameIndex<json_animation_frames_length; ++frameIndex )
                            {
                                AnimationFrame *frame = new AnimationFrame();
                                animation->frames.add( frame );

                                json_t *json_frame_submodels = json_array_get( json_animation_frames, frameIndex );
                                if( json_frame_submodels != NULL && json_is_array( json_frame_submodels ) )
                                {
                                    const uint json_frame_submodels_length = json_array_size( json_frame_submodels );
                                    for( uint submodelIndex=0; submodelIndex<json_frame_submodels_length; ++submodelIndex )
                                    {
                                        AnimationFrameSubmodel *frameSubmodel = new AnimationFrameSubmodel();
                                        frame->submodels.add( frameSubmodel );

                                        json_t *json_frame_submodel = json_array_get( json_frame_submodels, submodelIndex );
                                        json_object_string( frameSubmodel->name, json_frame_submodel, "n" );
                                        json_t *json_vertices = json_object_get( json_frame_submodel, "v" );
                                        if( json_vertices != NULL && json_is_array( json_vertices ) )
                                        {
                                            const uint json_vertices_length = json_array_size( json_vertices );
                                            frameSubmodel->vertices = (float*)malloc( sizeof( float ) * json_vertices_length );
                                            for( uint vertIndex=0; vertIndex<json_vertices_length; ++vertIndex )
                                            {
                                                const float vert = json_object_float( json_array_get( json_vertices, vertIndex ) );
                                                frameSubmodel->vertices[vertIndex] = vert;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                json_t *json_animationFPS = json_object_get( json, "animationFPS" );
                if( json_animationFPS != NULL )
                {
                    animationFPS = json_object_float( json_animationFPS );
                }
                
                json_t *json_animationFPSCompression = json_object_get( json, "animationFPSCompression" );
                if( json_animationFPSCompression != NULL )
                {
                    animationFPSCompression = json_object_int( json_animationFPSCompression );
                }
            }
        }

        json_t *json_models = json_object_get( json, "models" );
        if( json_models != NULL && json_is_array( json_models ) )
        {
            const uint json_models_length = json_array_size( json_models );
            for( uint i=0; i<json_models_length; ++i )
            {
                json_t *json_model = json_array_get( json_models, i );
                json_t *json_model_submeshes = json_object_get( json_model, "submeshes" );
                json_t *json_model_vertices = json_object_get( json_model, "vertices" );
                if( json_model_submeshes != NULL && json_model_vertices != NULL )
                {
                    int submodel_vertexCount = loadSubmodel( json_model );
                    vertexCount += submodel_vertexCount;
                }
            }
        }
        json_decref( json );

        calculateMinMax();
        width = mmX.size();
        height = mmY.size();
        depth = mmZ.size();

        return true;
    }

    return false;
}