コード例 #1
0
 bool isHitFromTop(Polygon p) {
     return (this->getTopLeft().getOrdinat() < p.getBottomRight().getOrdinat());
 }
コード例 #2
0
 bool isHitFromRight(Polygon p) {
     return (this->getBottomRight().getAxis() > p.getTopLeft().getAxis());
 }
コード例 #3
0
ファイル: Camera.cpp プロジェクト: blusquare/TraceTheRay
PixelMap * Camera::render(short aa=1) {
	//local variables
	int tVW				= aa*this->getVWidth();
	int tVH				= aa*this->getVHeight();
	Polygon * tracedPg;
	Color tracedColor;
	bool end;
	
	//Initialize PixelMap with given dimensions
	PixelMap * render	= new PixelMap ("render", tVW, tVH);
	
	//apply the new vWidth and Height to Camera
	if (aa != 1) {
		this->setView(tVW, tVH, this->getVAngle(), true);
	}
	
	//reset vPos in Camera
	resetVPos();
	
	//generate first ray
	generateRay(true);
	
	cout << "\nRendering initialized.\n\tResolution: \t" << tVW/aa << "x" << tVH/aa << " at " << aa << "xAA\n\tPolygons: \t" << allPolygons.size() << endl;
	
	while (true) {
		//generate ray for new vPos
		generateRay();
		
		//start of new position --> update vector inDivPolygons to pass to trace()
		if (this->checkDiv) this->checkDivPgs();
		
		//RayTracing. Returns pointer to the valid polygon from a given vector including pointers to polygons in that division
		if (this->getDivSize() != 1) {
			tracedPg	= this->vRay.trace(&(this->inDivPolygons));
		}
		else {
			tracedPg	= this->vRay.trace();	//use all polygons
		}
		
		//check for intersection. No intersection: set pixel to backgroundcolor
		if (tracedPg->isActive()) {
			tracedColor	= tracedPg->getColor();
		}
		else {
			tracedColor = black;
		}
		
		//set pixel in PixelMap to color of polygon and move to next pixel (2nd arg TRUE) in the PixelMap
		render->setPixel(tracedColor, this->getVPos());
		
		//move to the next pixel in vPos. End loop if vPos reached top right
		end		= nextPixel();
		if (end) break;
	}
	
	
	//apply AntiAliasing
	*render	= render->antiAliase(aa);
	
	cout << "Rendering finished.\n" << endl;
	
	//reset vWidth and Height to old values
	if (aa != 1) {
		this->setView(tVW/aa, tVH/aa, this->getVAngle(), true);
	}
	
	return render;
}
コード例 #4
0
ファイル: PolySceneMesh.cpp プロジェクト: gmacd/Polycode
void SceneMesh::renderMeshLocally() {
	Renderer *renderer = CoreServices::getInstance()->getRenderer();
	
	if(skeleton) {	
		for(int i=0; i < mesh->getPolygonCount(); i++) {
			Polygon *polygon = mesh->getPolygon(i);			
			unsigned int vCount = polygon->getVertexCount();			
			for(int j=0; j < vCount; j++) {
				Vertex *vert = polygon->getVertex(j);
				Vector3 norm;
				
					Vector3 aPos = vert->restPosition;
					Vector3 tPos;

					Number mult = 1;					
/*				
					Number mult = 0;
					for(int b =0; b < vert->getNumBoneAssignments(); b++) {
						BoneAssignment *bas = vert->getBoneAssignment(b);
						mult += bas->weight;
					}
					mult = 1.0f/mult;
*/				
					for(int b =0; b < vert->getNumBoneAssignments(); b++) {
						BoneAssignment *bas = vert->getBoneAssignment(b);
						Bone *bone = bas->bone;
						if(bone) {
							
							Matrix4 restMatrix = bone->getRestMatrix();
							Matrix4 finalMatrix = bone->getFinalMatrix();
							
							Vector3 vec = restMatrix * aPos;
							tPos += finalMatrix * vec * (bas->weight*mult);
							
							Vector3 nvec = vert->restNormal;
							nvec = restMatrix.rotateVector(nvec);
							nvec = finalMatrix.rotateVector(nvec);
							
							norm += nvec * (bas->weight*mult);
						}
					}					
					
				
					vert->x = tPos.x;
					vert->y = tPos.y;
					vert->z = tPos.z;				
				
					norm.Normalize();
					vert->setNormal(norm.x, norm.y, norm.z);
				
			}
		}
		mesh->arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;		
		mesh->arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;	
		mesh->arrayDirtyMap[RenderDataArray::TANGENT_DATA_ARRAY] = true;				
	}

	if(mesh->useVertexColors) {
		renderer->pushDataArrayForMesh(mesh, RenderDataArray::COLOR_DATA_ARRAY);
	}
	 
	renderer->pushDataArrayForMesh(mesh, RenderDataArray::VERTEX_DATA_ARRAY);
	renderer->pushDataArrayForMesh(mesh, RenderDataArray::NORMAL_DATA_ARRAY);		
	renderer->pushDataArrayForMesh(mesh, RenderDataArray::TANGENT_DATA_ARRAY);			
	renderer->pushDataArrayForMesh(mesh, RenderDataArray::TEXCOORD_DATA_ARRAY);	
	
	renderer->drawArrays(mesh->getMeshType());
}
コード例 #5
0
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_Polygon::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
                                   tcpip::Storage& outputStorage) {
    // variable & id
    int variable = inputStorage.readUnsignedByte();
    std::string id = inputStorage.readString();
    // check variable
    if (variable != ID_LIST && variable != VAR_TYPE && variable != VAR_COLOR && variable != VAR_SHAPE && variable != VAR_FILL
            && variable != ID_COUNT) {
        return server.writeErrorStatusCmd(CMD_GET_POLYGON_VARIABLE, "Get Polygon Variable: unsupported variable specified", outputStorage);
    }
    // begin response building
    tcpip::Storage tempMsg;
    //  response-code, variableID, objectID
    tempMsg.writeUnsignedByte(RESPONSE_GET_POLYGON_VARIABLE);
    tempMsg.writeUnsignedByte(variable);
    tempMsg.writeString(id);
    // process request
    if (variable == ID_LIST || variable == ID_COUNT) {
        std::vector<std::string> ids;
        ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
        shapeCont.getPolygons().insertIDs(ids);
        if (variable == ID_LIST) {
            tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
            tempMsg.writeStringList(ids);
        } else {
            tempMsg.writeUnsignedByte(TYPE_INTEGER);
            tempMsg.writeInt((int) ids.size());
        }
    } else {
        Polygon* p = getPolygon(id);
        if (p == 0) {
            return server.writeErrorStatusCmd(CMD_GET_POLYGON_VARIABLE, "Polygon '" + id + "' is not known", outputStorage);
        }
        switch (variable) {
            case VAR_TYPE:
                tempMsg.writeUnsignedByte(TYPE_STRING);
                tempMsg.writeString(p->getType());
                break;
            case VAR_COLOR:
                tempMsg.writeUnsignedByte(TYPE_COLOR);
                tempMsg.writeUnsignedByte(p->getColor().red());
                tempMsg.writeUnsignedByte(p->getColor().green());
                tempMsg.writeUnsignedByte(p->getColor().blue());
                tempMsg.writeUnsignedByte(p->getColor().alpha());
                break;
            case VAR_SHAPE:
                tempMsg.writeUnsignedByte(TYPE_POLYGON);
                tempMsg.writeUnsignedByte(MIN2(static_cast<int>(255), static_cast<int>(p->getShape().size())));
                for (unsigned int iPoint = 0; iPoint < MIN2(static_cast<size_t>(255), p->getShape().size()); ++iPoint) {
                    tempMsg.writeDouble(p->getShape()[iPoint].x());
                    tempMsg.writeDouble(p->getShape()[iPoint].y());
                }
                break;
            case VAR_FILL:
                tempMsg.writeUnsignedByte(TYPE_UBYTE);
                tempMsg.writeUnsignedByte(p->getFill() ? 1 : 0);
                break;
            default:
                break;
        }
    }
    server.writeStatusCmd(CMD_GET_POLYGON_VARIABLE, RTYPE_OK, "", outputStorage);
    server.writeResponseWithLength(outputStorage, tempMsg);
    return true;
}
コード例 #6
0
bool
TraCIServerAPI_Polygon::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
                                   tcpip::Storage& outputStorage) {
    std::string warning = ""; // additional description for response
    // variable
    int variable = inputStorage.readUnsignedByte();
    if (variable != VAR_TYPE && variable != VAR_COLOR && variable != VAR_SHAPE && variable != VAR_FILL
            && variable != ADD && variable != REMOVE) {
        return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Change Polygon State: unsupported variable specified", outputStorage);
    }
    // id
    std::string id = inputStorage.readString();
    Polygon* p = 0;
    ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
    if (variable != ADD && variable != REMOVE) {
        p = getPolygon(id);
        if (p == 0) {
            return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Polygon '" + id + "' is not known", outputStorage);
        }
    }
    // process
    switch (variable) {
        case VAR_TYPE: {
            std::string type;
            if (!server.readTypeCheckingString(inputStorage, type)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The type must be given as a string.", outputStorage);
            }
            p->setType(type);
        }
        break;
        case VAR_COLOR: {
            RGBColor col;
            if (!server.readTypeCheckingColor(inputStorage, col)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The color must be given using an according type.", outputStorage);
            }
            p->setColor(col);
        }
        break;
        case VAR_SHAPE: {
            PositionVector shape;
            if (!server.readTypeCheckingPolygon(inputStorage, shape)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The shape must be given using an accoring type.", outputStorage);
            }
            shapeCont.reshapePolygon(id, shape);
        }
        break;
        case VAR_FILL: {
            int value = 0;
            if (!server.readTypeCheckingUnsignedByte(inputStorage, value)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "'fill' must be defined using an unsigned byte.", outputStorage);
            }
            p->setFill(value != 0);
        }
        break;
        case ADD: {
            if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "A compound object is needed for setting a new polygon.", outputStorage);
            }
            //readt itemNo
            inputStorage.readInt();
            std::string type;
            if (!server.readTypeCheckingString(inputStorage, type)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The type must be given as a string.", outputStorage);
            }
            RGBColor col;
            if (!server.readTypeCheckingColor(inputStorage, col)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The second polygon parameter must be the color.", outputStorage);
            }
            int value = 0;
            if (!server.readTypeCheckingUnsignedByte(inputStorage, value)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The third polygon parameter must be 'fill' encoded as ubyte.", outputStorage);
            }
            bool fill = value != 0;
            int layer = 0;
            if (!server.readTypeCheckingInt(inputStorage, layer)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The fourth polygon parameter must be the layer encoded as int.", outputStorage);
            }
            PositionVector shape;
            if (!server.readTypeCheckingPolygon(inputStorage, shape)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The fifth polygon parameter must be the shape.", outputStorage);
            }
            //
            if (!shapeCont.addPolygon(id, type, col, (SUMOReal)layer,
                                      Shape::DEFAULT_ANGLE, Shape::DEFAULT_IMG_FILE, shape, fill)) {
                delete p;
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Could not add polygon.", outputStorage);
            }
        }
        break;
        case REMOVE: {
            int layer = 0; // !!! layer not used yet (shouldn't the id be enough?)
            if (!server.readTypeCheckingInt(inputStorage, layer)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The layer must be given using an int.", outputStorage);
            }
            if (!shapeCont.removePolygon(id)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Could not remove polygon '" + id + "'", outputStorage);
            }
        }
        break;
        default:
            break;
    }
    server.writeStatusCmd(CMD_SET_POLYGON_VARIABLE, RTYPE_OK, warning, outputStorage);
    return true;
}
コード例 #7
0
ファイル: Line.cpp プロジェクト: clement-z/MathGeoLib
bool Line::Intersects(const Polygon &polygon) const
{
	return polygon.Intersects(*this);
}