Ejemplo n.º 1
0
HRESULT CCubeBox::Init(LPDIRECT3DDEVICE9 device)
{
	CObject3D::Init(device);

	WORD Indices[6*2*3];
    for (int i = 0, j = 0; i < 36; i+=6, j+=4){
        fillIndices(Indices+i, j, j+1, j+2, j+3);
    }


    DWORD SizeVertices = sizeof(m_Vertices);
    DWORD SizeIndices =  sizeof(Indices);

    if ( FAILED(m_device->CreateVertexBuffer(
        SizeVertices, 
        D3DUSAGE_WRITEONLY,
        VERTEX_BOX::FVF,
        D3DPOOL_MANAGED,
        &m_pVB,
        NULL))) return E_FAIL;

    VERTEX_BOX *pVertices;
    if ( FAILED(m_pVB->Lock( 0, SizeVertices, (VOID **)&pVertices, 0 ) ) ) return E_FAIL;
    memcpy(pVertices, m_Vertices, SizeVertices);
    m_pVB->Unlock();

    if ( FAILED(m_device->CreateIndexBuffer(SizeIndices, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIB,                 NULL) ) )
        return E_FAIL;

    VOID * pIndices;
    if ( FAILED(m_pIB->Lock( 0, SizeIndices, (VOID **)&pIndices, 0 ) ) ) return E_FAIL;
    memcpy(pIndices, Indices, SizeIndices);
    m_pIB->Unlock();
    return S_OK;
}
Ejemplo n.º 2
0
	void computeIndices(dae_reader_t *reader, int geometryID)
	{
		geometry_t *geometry = &reader->geometry[geometryID];
		int totalTrianglesSize = getTrianglesSize(geometry);
		int arrayBufferSize = 3 * totalTrianglesSize;
		vector<float> rawData;
		rawData.reserve(arrayBufferSize);

		for (uint32_t meshes = 0; meshes < geometry->triangles.size(); meshes++)
		{
			fillTempBuffer(reader, geometry, meshes, rawData);
		}

		fillIndices(reader, geometryID, rawData);
	}
Ejemplo n.º 3
0
SceneHeightmap::SceneHeightmap(RendererInterface* argRenderer, std::string argHeightmap, ResourceTexture* argTexture)
{
	// Set default position and orientation of the heightmap.
	position = Vector(	50.0f, -50.0f, -50.0f);
	orientation = Vector(0.0f, 0.0f, 0.0f);

	// Save the renderer and texture for later use.
	texture = argTexture;
	renderer = argRenderer;

	// "Location/name.bmp" of the heightmap bitmap file are converted to a LPCSTR.
	// InitializeImensions will read the height, width and offset info from the bitmap file header.
	LPCTSTR bitmap = argHeightmap.c_str();
	initializeDimensions(bitmap);

	// Create the index and vertexbuffer for the heightmap.
	fillVertices(bitmap);
	fillIndices();
}
Ejemplo n.º 4
0
SWIGEXPORT jint JNICALL Java_org_scilab_modules_graphic_1objects_DataLoaderJNI_fillIndices(JNIEnv *jenv, jclass jcls, jint jarg1, jobject jarg2, jint jarg3, jint jarg4) {
  jint jresult = 0 ;
  int arg1 ;
  int *arg2 = (int *) 0 ;
  int arg3 ;
  int arg4 ;
  int result;
  
  (void)jenv;
  (void)jcls;
  arg1 = (int)jarg1; 
  {
    arg2 = (*jenv)->GetDirectBufferAddress(jenv, jarg2);
    if (arg2 == NULL) {
      SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unable to get address of direct buffer. Buffer must be allocated direct.");
    }
  }
  arg3 = (int)jarg3; 
  arg4 = (int)jarg4; 
  result = (int)fillIndices(arg1,arg2,arg3,arg4);
  jresult = (jint)result; 
  return jresult;
}
Ejemplo n.º 5
0
GLLObjFile::GLLObjFile(CFURLRef location)
{
    std::string filename = GLLStringFromFileURL(location);
    
    int fdes = ::open(filename.c_str(), O_RDONLY);
    if (fdes < 0) {
        throw std::runtime_error("Could not open file");
    }
    
    struct stat statistics;
    if (fstat(fdes, &statistics) < 0) {
        close(fdes);
        throw std::runtime_error("Could not get file size");
    }
    
    const char *buffer = (const char *) mmap(nullptr, statistics.st_size, PROT_READ, MAP_PRIVATE, fdes, 0);
    close(fdes);
    const char *current = buffer;
    const char *end = &buffer[statistics.st_size];
    
    materialLibraryURLs = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
    std::string activeMaterial("");
    unsigned activeMaterialStart = 0;
    bool hasFirstMaterial = false;
    while(current != end)
    {
        while (current != end && (*current == ' ' || *current == '\n' || *current == '\r')) {
            current++;
        }
        if (current == end)
            break;
        
        switch (*current) {
            case 'f':
                parseFace(current, end);
                break;
            case 'v':
                current += 1;
                switch (*current) {
                    case 'n': // Normals
                        current += 1;
                        parseVector(current, end, normals, 3);
                        break;
                    case 't': // Tex coords
                        current += 1;
                        parseVector(current, end, texCoords, 2);
                        break;
                    case 'c': // Colors
                        current += 1;
                        parseVector(current, end, colors, 4);
                        break;
                    case ' ': // Vertex
                        parseVector(current, end, vertices, 3);
                        break;
                    default:
                        skipToEndOfLine(current, end);
                        break;
                }
                break;
            case 'm':
                if (followsString(current, end, "mtllib")) {
                    std::string mtllib = stringToEndOfLine(current, end);
                    
                    try
                    {
                        CFURLRef mtllibLocation = GLLCreateURLFromString(mtllib, location);
                        CFArrayAppendValue(materialLibraryURLs, mtllibLocation);
                        CFRelease(mtllibLocation);
                    }
                    catch (std::exception &e)
                    {
                        std::cerr << "Ignoring mtllib: " << e.what() << std::endl;
                    }
                } else {
                    skipToEndOfLine(current, end);
                }
                break;
            case 'u':
                if (followsString(current, end, "usemtl")) {
                    if (hasFirstMaterial)
                    {
                        // End previous material run
                        materialRanges.push_back(MaterialRange(activeMaterialStart, (unsigned) originalIndices.size(), activeMaterial));
                    }
                    else
                        hasFirstMaterial = true;
                    
                    current += 1;
                    activeMaterial = stringToEndOfLine(current, end);
                    activeMaterialStart = (unsigned) originalIndices.size();
                } else {
                    skipToEndOfLine(current, end);
                }
                break;
            case '#': // Comment
            default:
                skipToEndOfLine(current, end);
                break;
        }
    }
    munmap((void *) buffer, statistics.st_size);
    
    // Wrap up final material group
    materialRanges.push_back(MaterialRange(activeMaterialStart, (unsigned) originalIndices.size(), activeMaterial));
    
    fillIndices();
}