예제 #1
0
CCRect CCSkeleton::boundingBox () {
	float minX = FLT_MAX, minY = FLT_MAX, maxX = FLT_MIN, maxY = FLT_MIN;
	float scaleX = getScaleX();
	float scaleY = getScaleY();
	float vertices[8];
	for (int i = 0; i < skeleton->slotCount; ++i) {
		Slot* slot = skeleton->slots[i];
		if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
		RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
		RegionAttachment_computeVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices);
		minX = min(minX, vertices[VERTEX_X1] * scaleX);
		minY = min(minY, vertices[VERTEX_Y1] * scaleY);
		maxX = max(maxX, vertices[VERTEX_X1] * scaleX);
		maxY = max(maxY, vertices[VERTEX_Y1] * scaleY);
		minX = min(minX, vertices[VERTEX_X4] * scaleX);
		minY = min(minY, vertices[VERTEX_Y4] * scaleY);
		maxX = max(maxX, vertices[VERTEX_X4] * scaleX);
		maxY = max(maxY, vertices[VERTEX_Y4] * scaleY);
		minX = min(minX, vertices[VERTEX_X2] * scaleX);
		minY = min(minY, vertices[VERTEX_Y2] * scaleY);
		maxX = max(maxX, vertices[VERTEX_X2] * scaleX);
		maxY = max(maxY, vertices[VERTEX_Y2] * scaleY);
		minX = min(minX, vertices[VERTEX_X3] * scaleX);
		minY = min(minY, vertices[VERTEX_Y3] * scaleY);
		maxX = max(maxX, vertices[VERTEX_X3] * scaleX);
		maxY = max(maxY, vertices[VERTEX_Y3] * scaleY);
	}
	CCPoint position = getPosition();
	return CCRectMake(position.x + minX, position.y + minY, maxX - minX, maxY - minY);
}
예제 #2
0
void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, V3F_C4B_T2F_Quad* quad, bool premultipliedAlpha) {
	float vertices[8];
	RegionAttachment_computeVertices(self, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices);

	GLubyte r = slot->skeleton->r * slot->r * 255;
	GLubyte g = slot->skeleton->g * slot->g * 255;
	GLubyte b = slot->skeleton->b * slot->b * 255;
	float normalizedAlpha = slot->skeleton->a * slot->a;
	if (premultipliedAlpha) {
		r *= normalizedAlpha;
		g *= normalizedAlpha;
		b *= normalizedAlpha;
	}
	GLubyte a = normalizedAlpha * 255;
	quad->bl.colors.r = r;
	quad->bl.colors.g = g;
	quad->bl.colors.b = b;
	quad->bl.colors.a = a;
	quad->tl.colors.r = r;
	quad->tl.colors.g = g;
	quad->tl.colors.b = b;
	quad->tl.colors.a = a;
	quad->tr.colors.r = r;
	quad->tr.colors.g = g;
	quad->tr.colors.b = b;
	quad->tr.colors.a = a;
	quad->br.colors.r = r;
	quad->br.colors.g = g;
	quad->br.colors.b = b;
	quad->br.colors.a = a;

	quad->bl.vertices.x = vertices[VERTEX_X1];
	quad->bl.vertices.y = vertices[VERTEX_Y1];
	quad->tl.vertices.x = vertices[VERTEX_X2];
	quad->tl.vertices.y = vertices[VERTEX_Y2];
	quad->tr.vertices.x = vertices[VERTEX_X3];
	quad->tr.vertices.y = vertices[VERTEX_Y3];
	quad->br.vertices.x = vertices[VERTEX_X4];
	quad->br.vertices.y = vertices[VERTEX_Y4];

	quad->bl.texCoords.u = self->uvs[VERTEX_X1];
	quad->bl.texCoords.v = self->uvs[VERTEX_Y1];
	quad->tl.texCoords.u = self->uvs[VERTEX_X2];
	quad->tl.texCoords.v = self->uvs[VERTEX_Y2];
	quad->tr.texCoords.u = self->uvs[VERTEX_X3];
	quad->tr.texCoords.v = self->uvs[VERTEX_Y3];
	quad->br.texCoords.u = self->uvs[VERTEX_X4];
	quad->br.texCoords.v = self->uvs[VERTEX_Y4];
}
예제 #3
0
void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const {
	vertexArray->clear();
	float vertexPositions[8];
	for (int i = 0; i < skeleton->slotCount; ++i) {
		Slot* slot = skeleton->slots[i];
		Attachment* attachment = slot->attachment;
		if (!attachment || attachment->type != ATTACHMENT_REGION) continue;
		RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
		RegionAttachment_computeVertices(regionAttachment, slot, vertexPositions);

		Uint8 r = skeleton->r * slot->r * 255;
		Uint8 g = skeleton->g * slot->g * 255;
		Uint8 b = skeleton->b * slot->b * 255;
		Uint8 a = skeleton->a * slot->a * 255;

		sf::Vertex vertices[4];
		vertices[0].color.r = r;
		vertices[0].color.g = g;
		vertices[0].color.b = b;
		vertices[0].color.a = a;
		vertices[1].color.r = r;
		vertices[1].color.g = g;
		vertices[1].color.b = b;
		vertices[1].color.a = a;
		vertices[2].color.r = r;
		vertices[2].color.g = g;
		vertices[2].color.b = b;
		vertices[2].color.a = a;
		vertices[3].color.r = r;
		vertices[3].color.g = g;
		vertices[3].color.b = b;
		vertices[3].color.a = a;

		vertices[0].position.x = vertexPositions[VERTEX_X1];
		vertices[0].position.y = vertexPositions[VERTEX_Y1];
		vertices[1].position.x = vertexPositions[VERTEX_X2];
		vertices[1].position.y = vertexPositions[VERTEX_Y2];
		vertices[2].position.x = vertexPositions[VERTEX_X3];
		vertices[2].position.y = vertexPositions[VERTEX_Y3];
		vertices[3].position.x = vertexPositions[VERTEX_X4];
		vertices[3].position.y = vertexPositions[VERTEX_Y4];

		// SMFL doesn't handle batching for us, so we'll just force a single texture per skeleton.
		states.texture = (Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;

		Vector2u size = states.texture->getSize();
		vertices[0].texCoords.x = regionAttachment->uvs[VERTEX_X1] * size.x;
		vertices[0].texCoords.y = regionAttachment->uvs[VERTEX_Y1] * size.y;
		vertices[1].texCoords.x = regionAttachment->uvs[VERTEX_X2] * size.x;
		vertices[1].texCoords.y = regionAttachment->uvs[VERTEX_Y2] * size.y;
		vertices[2].texCoords.x = regionAttachment->uvs[VERTEX_X3] * size.x;
		vertices[2].texCoords.y = regionAttachment->uvs[VERTEX_Y3] * size.y;
		vertices[3].texCoords.x = regionAttachment->uvs[VERTEX_X4] * size.x;
		vertices[3].texCoords.y = regionAttachment->uvs[VERTEX_Y4] * size.y;

		vertexArray->append(vertices[0]);
		vertexArray->append(vertices[1]);
		vertexArray->append(vertices[2]);
		vertexArray->append(vertices[3]);
	}
	target.draw(*vertexArray, states);
}
예제 #4
0
void ofxSkeleton::updateMeshData(){
    
	mesh.clearVertices();
	mesh.clearTexCoords();
	mesh.clearColors();
    
	float vertexPositions[8];
    
	for(int i = 0; i < skeleton->slotCount; ++i){
        
		Slot * slot = skeleton->slots[i];
        
		Attachment * attachment = slot->attachment;
        
		if(!attachment || attachment->type != ATTACHMENT_REGION){
			continue;
		}
        
		RegionAttachment * regionAttachment = (RegionAttachment *)attachment;
        
		RegionAttachment_computeVertices(regionAttachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertexPositions);
        
		int r = skeleton->r * slot->r * 255;
		int g = skeleton->g * slot->g * 255;
		int b = skeleton->b * slot->b * 255;
		int a = skeleton->a * slot->a * 255;
        
		colors[0].r = r;
		colors[0].g = g;
		colors[0].b = b;
		colors[0].a = a;
		colors[1].r = r;
		colors[1].g = g;
		colors[1].b = b;
		colors[1].a = a;
		colors[2].r = r;
		colors[2].g = g;
		colors[2].b = b;
		colors[2].a = a;
		colors[3].r = r;
		colors[3].g = g;
		colors[3].b = b;
		colors[3].a = a;
		colors[4].r = r;
		colors[4].g = g;
		colors[4].b = b;
		colors[4].a = a;
		colors[5].r = r;
		colors[5].g = g;
		colors[5].b = b;
		colors[5].a = a;
        
		vertices[0].x = vertexPositions[VERTEX_X1];
		vertices[0].y = vertexPositions[VERTEX_Y1];
		vertices[1].x = vertexPositions[VERTEX_X2];
		vertices[1].y = vertexPositions[VERTEX_Y2];
		vertices[2].x = vertexPositions[VERTEX_X3];
		vertices[2].y = vertexPositions[VERTEX_Y3];
        
		vertices[3].x = vertexPositions[VERTEX_X4];
		vertices[3].y = vertexPositions[VERTEX_Y4];
		vertices[4].x = vertexPositions[VERTEX_X1];
		vertices[4].y = vertexPositions[VERTEX_Y1];
		vertices[5].x = vertexPositions[VERTEX_X3];
		vertices[5].y = vertexPositions[VERTEX_Y3];
        
		// kikko : here we update the global texture object for each region, not quite optimal
		texture = (ofTexture *)((AtlasRegion *)regionAttachment->rendererObject)->page->rendererObject;
        
		ofPoint size = ofPoint(texture->getWidth(), texture->getHeight());
        
		texCoords[0].x = regionAttachment->uvs[VERTEX_X1] * size.x;
		texCoords[0].y = regionAttachment->uvs[VERTEX_Y1] * size.y;
		texCoords[1].x = regionAttachment->uvs[VERTEX_X2] * size.x;
		texCoords[1].y = regionAttachment->uvs[VERTEX_Y2] * size.y;
		texCoords[2].x = regionAttachment->uvs[VERTEX_X3] * size.x;
		texCoords[2].y = regionAttachment->uvs[VERTEX_Y3] * size.y;
        
		texCoords[3].x = regionAttachment->uvs[VERTEX_X4] * size.x;
		texCoords[3].y = regionAttachment->uvs[VERTEX_Y4] * size.y;
		texCoords[4].x = regionAttachment->uvs[VERTEX_X1] * size.x;
		texCoords[4].y = regionAttachment->uvs[VERTEX_Y1] * size.y;
		texCoords[5].x = regionAttachment->uvs[VERTEX_X3] * size.x;
		texCoords[5].y = regionAttachment->uvs[VERTEX_Y3] * size.y;
        
		mesh.addVertices(vertices, 6);
		mesh.addTexCoords(texCoords, 6);
		mesh.addColors(colors, 6);
	}
}
예제 #5
0
void SkeletonDrawable::draw (SDL_Renderer *renderer) {
    // Single texture rendering (no batching).

	float vertexPositions[8];
	int vertexCount = 0;
	SDL_Texture *texture = NULL;
	SDL_Vertex vertices[4];

	vertexArray.clear();
	indices.clear();

	for (int i = 0; i < skeleton->slotCount; ++i) {
		Slot* slot = skeleton->slots[i];
		Attachment* attachment = slot->attachment;
		if (!attachment || attachment->type != ATTACHMENT_REGION) continue;
		RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
		RegionAttachment_computeVertices(regionAttachment, slot, vertexPositions);

		Uint8 r = skeleton->r * slot->r * 255;
		Uint8 g = skeleton->g * slot->g * 255;
		Uint8 b = skeleton->b * slot->b * 255;
		Uint8 a = skeleton->a * slot->a * 255;

		vertices[0].color.r = r;
        vertices[0].color.g = g;
        vertices[0].color.b = b;
        vertices[0].color.a = a;
        vertices[1].color.r = r;
        vertices[1].color.g = g;
        vertices[1].color.b = b;
        vertices[1].color.a = a;
        vertices[2].color.r = r;
        vertices[2].color.g = g;
        vertices[2].color.b = b;
        vertices[2].color.a = a;
        vertices[3].color.r = r;
        vertices[3].color.g = g;
        vertices[3].color.b = b;
        vertices[3].color.a = a;

		vertices[0].position.x = vertexPositions[VERTEX_X1];
		vertices[0].position.y = vertexPositions[VERTEX_Y1];
		vertices[1].position.x = vertexPositions[VERTEX_X2];
		vertices[1].position.y = vertexPositions[VERTEX_Y2];
		vertices[2].position.x = vertexPositions[VERTEX_X3];
		vertices[2].position.y = vertexPositions[VERTEX_Y3];
		vertices[3].position.x = vertexPositions[VERTEX_X4];
		vertices[3].position.y = vertexPositions[VERTEX_Y4];

		texture = (SDL_Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;

		vertices[0].tex_coord.x = regionAttachment->uvs[VERTEX_X1];
		vertices[0].tex_coord.y = regionAttachment->uvs[VERTEX_Y1];
		vertices[1].tex_coord.x = regionAttachment->uvs[VERTEX_X2];
		vertices[1].tex_coord.y = regionAttachment->uvs[VERTEX_Y2];
		vertices[2].tex_coord.x = regionAttachment->uvs[VERTEX_X3];
		vertices[2].tex_coord.y = regionAttachment->uvs[VERTEX_Y3];
		vertices[3].tex_coord.x = regionAttachment->uvs[VERTEX_X4];
		vertices[3].tex_coord.y = regionAttachment->uvs[VERTEX_Y4];

        indices.push_back(vertexCount);
        indices.push_back(vertexCount+1);
        indices.push_back(vertexCount+2);
        indices.push_back(vertexCount);
        indices.push_back(vertexCount+2);
        indices.push_back(vertexCount+3);
        vertexCount+=4;

		vertexArray.push_back(vertices[0]);
        vertexArray.push_back(vertices[1]);
        vertexArray.push_back(vertices[2]);
        vertexArray.push_back(vertices[3]);
	}

	/*for (int i=0; i<vertexArray.size(); i++) {
	    SDL_Vertex *v = (SDL_Vertex*)&vertexArray[i];
	    printf("Vertex %d, at %fx%f texcoord %fx%f color %d,%d,%d,%d\n", i, v->position.x, v->position.y, v->tex_coord.x, v->tex_coord.y, v->color.r, v->color.g, v->color.b, v->color.a);
	}
	printf("skeleton::draw %lu %u\n", vertexArray.size(), texture);*/

	if (texture) {
	    SDL_RenderGeometry(renderer, texture, (SDL_Vertex*)&vertexArray[0], vertexArray.size(), (int*)&indices[0], indices.size(), NULL);
	}
}