예제 #1
0
TEXTURE *material_map(const Vector3d& EPoint, const TEXTURE *Texture)
{
    int reg_number = -1;
    int Material_Number;
    DBL xcoor = 0.0, ycoor = 0.0;
    RGBFTColour colour;

    /*
     * Now we have transformed x, y, z we use image mapping routine to determine
     * texture index.
     */

    if(map_pos(EPoint, Texture->pattern.get(), &xcoor, &ycoor))
        Material_Number = 0;
    else
    {
        if (const ImagePatternImpl *pattern = dynamic_cast<ImagePatternImpl*>(Texture->pattern.get()))
            image_colour_at(pattern->pImage, xcoor, ycoor, colour, &reg_number); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha
        else
            POV_PATTERN_ASSERT(false);

        if(reg_number == -1)
            Material_Number = (int)(colour.red() * 255.0);
        else
            Material_Number = reg_number;
    }

    if(Material_Number > Texture->Materials.size())
        Material_Number %= Texture->Materials.size();

    return Texture->Materials[Material_Number % Texture->Materials.size()];
}
예제 #2
0
bool image_map(const Vector3d& EPoint, const PIGMENT *Pigment, TransColour& colour)
{
    // TODO ALPHA - the caller does expect non-premultiplied data, but maybe he could profit from premultiplied data?

    int reg_number;
    DBL xcoor = 0.0, ycoor = 0.0;

    // If outside map coverage area, return clear

    if(map_pos(EPoint, Pigment->pattern.get(), &xcoor, &ycoor))
    {
        colour = ToTransColour(RGBFTColour(1.0, 1.0, 1.0, 0.0, 1.0));
        return false;
    }
    else
    {
        RGBFTColour rgbft;
        if (const ImagePatternImpl *pattern = dynamic_cast<ImagePatternImpl*>(Pigment->pattern.get()))
            image_colour_at(pattern->pImage, xcoor, ycoor, rgbft, &reg_number, false);
        else
            POV_PATTERN_ASSERT(false);
        colour = ToTransColour(rgbft);
        return true;
    }
}
예제 #3
0
DBL image_pattern(const Vector3d& EPoint, const BasicPattern* pPattern)
{
    DBL xcoor = 0.0, ycoor = 0.0;
    int index = -1;
    RGBFTColour colour;
    const ImageData *image = dynamic_cast<const ImagePatternImpl*>(pPattern)->pImage;
    DBL Value;

    colour.Clear();

    // going to have to change this
    // need to know if bump point is off of image for all 3 points

    if(map_pos(EPoint, pPattern, &xcoor, &ycoor))
        return 0.0;
    else
        image_colour_at(image, xcoor, ycoor, colour, &index); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha

    if((index == -1) || image->Use)
    {
        if(image->Use == USE_ALPHA)
        {
            // use alpha channel or red channel
            if(image->data->HasTransparency() == true)
                Value = colour.transm();
            else
                Value = colour.red();   // otherwise, just use the red channel
        }
        else
            // use grey-scaled version of the color
            Value = colour.Greyscale();
    }
    else
        Value = index / 255.0;

    if(Value < 0)
        Value = 0;
    else if(Value > 1.0)
        Value = 1.0;

    return Value;
}
예제 #4
0
void location_view(/*@unused@*/ Widget w, /*@unused@*/ XtPointer clientData, /*@unused@*/ XtPointer callData) {
    int i,x;
    char *location;
    XmString *list;
    int found,done;
    FILE *f;
    char temp[200];
    char name[100];
    char pos[100];
    char *temp_ptr;
    char s_lat[20];
    char s_long[20];
    char s_sz[10];
    char location_file_path[MAX_VALUE];

    found=0;
    XtVaGetValues(location_list,XmNitemCount,&i,XmNitems,&list,NULL);

    for (x=1; x<=i;x++) {
        if (XmListPosSelected(location_list,x)) {
            found=1;
            if (XmStringGetLtoR(list[(x-1)],XmFONTLIST_DEFAULT_TAG,&location))
                x=i+1;
        }
    }
    get_user_base_dir("config/locations.sys", location_file_path, 
                      sizeof(location_file_path));
    if (found) {
        f=fopen(location_file_path,"r");
        if (f!=NULL) {
            done=0;
            while (!feof(f) & !done) {
                (void)get_line(f,temp,200);
                if (!feof(f) && strlen(temp)>8) {
                    temp_ptr=strtok(temp,"|");  /* get the name */
                    if (temp_ptr!=NULL) {
                        xastir_snprintf(name,
                            sizeof(name),
                            "%s",
                            temp);
                        temp_ptr=strtok(NULL,"|");  /* get the pos */
                        xastir_snprintf(pos,
                            sizeof(pos),
                            "%s",
                            temp_ptr);
                        if (strcmp(location,name)==0) {
                            if (3 != sscanf(pos,"%19s %19s %9s", s_lat, s_long, s_sz)) {
                                fprintf(stderr,"location_view:sscanf parsing error\n");
                            }
                            map_pos(convert_lat_s2l(s_lat),convert_lon_s2l(s_long),atol(s_sz));
                            done=1;
                        }
                    }
                }
            }
            (void)fclose(f);
        }
        else {
            fprintf(stderr,"Couldn't open file: %s\n", location_file_path );
        }
        XtFree(location);
    }
}
예제 #5
0
void bump_map(const Vector3d& EPoint, const TNORMAL *Tnormal, Vector3d& normal)
{
    DBL xcoor = 0.0, ycoor = 0.0;
    int index = -1, index2 = -1, index3 = -1;
    RGBFTColour colour1, colour2, colour3;
    Vector3d p1, p2, p3;
    Vector3d bump_normal;
    Vector3d xprime, yprime, zprime;
    DBL Length;
    DBL Amount = Tnormal->Amount;
    const ImageData *image;

    if (const ImagePatternImpl *pattern = dynamic_cast<ImagePatternImpl*>(Tnormal->pattern.get()))
        image = pattern->pImage;
    else
        POV_PATTERN_ASSERT(false);

    // going to have to change this
    // need to know if bump point is off of image for all 3 points

    if(map_pos(EPoint, Tnormal->pattern.get(), &xcoor, &ycoor))
        return;
    else
        image_colour_at(image, xcoor, ycoor, colour1, &index); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha

    xcoor--;
    ycoor++;

    if(xcoor < 0.0)
        xcoor += (DBL)image->iwidth;
    else if(xcoor >= image->iwidth)
        xcoor -= (DBL)image->iwidth;

    if(ycoor < 0.0)
        ycoor += (DBL)image->iheight;
    else if(ycoor >= (DBL)image->iheight)
        ycoor -= (DBL)image->iheight;

    image_colour_at(image, xcoor, ycoor, colour2, &index2); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha

    xcoor += 2.0;

    if(xcoor < 0.0)
        xcoor += (DBL)image->iwidth;
    else if(xcoor >= image->iwidth)
        xcoor -= (DBL)image->iwidth;

    image_colour_at(image, xcoor, ycoor, colour3, &index3); // TODO ALPHA - we should decide whether we prefer premultiplied or non-premultiplied alpha

    if(image->Use || (index == -1) || (index2 == -1) || (index3 == -1))
    {
        p1[X] = 0;
        p1[Y] = Amount * colour1.Greyscale();
        p1[Z] = 0;

        p2[X] = -1;
        p2[Y] = Amount * colour2.Greyscale();
        p2[Z] = 1;

        p3[X] = 1;
        p3[Y] = Amount * colour3.Greyscale();
        p3[Z] = 1;
    }
    else
    {
        p1[X] = 0;
        p1[Y] = Amount * index;
        p1[Z] = 0;

        p2[X] = -1;
        p2[Y] = Amount * index2;
        p2[Z] = 1;

        p3[X] = 1;
        p3[Y] = Amount * index3;
        p3[Z] = 1;
    }

    // we have points 1,2,3 for a triangle now we need the surface normal for it

    xprime = p1 - p2;
    yprime = p3 - p2;
    bump_normal = cross(yprime, xprime).normalized();

    yprime = normal;
    xprime = cross(yprime, Vector3d(0.0, 1.0, 0.0));
    Length = xprime.length();

    if(Length < EPSILON)
    {
        if(fabs(normal[Y] - 1.0) < EPSILON)
        {
            yprime = Vector3d(0.0, 1.0, 0.0);
            xprime = Vector3d(1.0, 0.0, 0.0);
            Length = 1.0;
        }
        else
        {
            yprime = Vector3d(0.0,-1.0, 0.0);
            xprime = Vector3d(1.0, 0.0, 0.0);
            Length = 1.0;
        }
    }

    xprime /= Length;
    zprime = cross(xprime, yprime).normalized();
    xprime *= bump_normal[X];
    yprime *= bump_normal[Y];
    zprime *= bump_normal[Z];
    normal = xprime + yprime - zprime;
}
예제 #6
0
파일: Map.cpp 프로젝트: nunosan12/jin
Map::Map()
{
	map_pos(0, 0);

}