Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [code]
- loat Vec3DistanceSq(const float *p1, const float *p2)
- {
- return ((p2[0] - p1[0]) * (p2[0] - p1[0]) +
- ((p2[2] - p1[2]) * (p2[2] - p1[2]) +
- ((p2[1] - p1[1]) * (p2[1] - p1[1]))));
- }
- void LinkTo(int Entity, int parent)
- {
- if(G_EntLinkTo(Entity, parent, 0))
- *(byte *)(*(int *)(Entity + 0x218) + 0xA) = 0;
- }
- int roundUp(float floatVal)
- {
- if (int(floatVal) != floatVal)
- return int(floatVal+1);
- else
- return int(floatVal);
- }
- float Distance(float* p1, float* p2)
- {
- return sqrt(Vec3DistanceSq(p1, p2));
- }
- float Distance(float p1X, float p1Y, float p1Z, float p2X, float p2Y, float p2Z)
- {
- float p1[] = {p1X,p1Y,p1Z},
- p2[] = {p2X,p2Y,p2Z};
- return sqrt(Vec3DistanceSq(p1, p2));
- }
- void vectoangles(const float * Vec, float * angles)
- {
- float forward, yaw, pitch, PiDiv = (180.0f / XM_PI);
- if(Vec[1] == 0 && Vec[0] == 0)
- {
- yaw = 0;
- if (Vec[2] > 0)
- pitch = 90;
- else
- pitch = 270;
- }
- else
- {
- if (Vec[0])
- yaw = (atan2(Vec[1], Vec[0]) * PiDiv);
- else if (Vec[1] > 0)
- yaw = 90.0f;
- else
- yaw = 270.0f;
- if (yaw < 0.0f)
- yaw += 360.0f;
- forward = sqrt((Vec[0] * Vec[0]) + (Vec[1] * Vec[1]));
- pitch = (atan2(Vec[2], forward) * PiDiv);
- if (pitch < 0.0f)
- pitch += 360;
- }
- angles[0] = 360.0f - pitch;
- angles[1] = yaw;
- angles[2] = 0;
- for(int i = 0; i < 3; i++) {
- if(angles[i] > 360.0f)
- angles[i] -= 360.0f;
- if(angles[i] < 0.0f)
- angles[i] += 360.0f;
- }
- }
- [/code]
- [code]
- void CreateRamp(float* top, float* bottom)
- {
- float D = Distance(top, bottom);
- int blocks = roundUp(D/32);
- float CX = top[0] - bottom[0],
- CY = top[1] - bottom[1],
- CZ = top[2] - bottom[2];
- int XA = CX/blocks,
- YA = CY/blocks,
- ZA = CZ/blocks;
- float Temp[3] = {top[0], top[1], 0},
- Temp2[3] = {bottom[0], bottom[1], 0},
- CXY = Distance(Temp, Temp2);
- for(int i = 0; i < 3; i++)
- Temp2[i] = top[i] - bottom[i];
- vectoangles(Temp2, Temp);
- for(int b = 0; b < blocks; b++)
- spawnEntity(true, "carepackage_friendly_iw6", bottom[0] + (XA * b), bottom[1] + (YA * b), bottom[2] + (ZA * b), Temp[2], Temp[1] + 90, Temp[0]);
- spawnEntity(true, "carepackage_friendly_iw6", bottom[0] + (XA * blocks), bottom[1] + (YA * blocks), bottom[2] + (ZA * blocks) - 8, Temp[2], Temp[1] + 90, 0);
- }
- void CreateGrid(float* corner1, float* corner2, float* angle)
- {
- float W = Distance(corner1[0], 0, 0, corner2[0], 0, 0),
- L = Distance(0, corner1[1], 0, 0, corner2[1], 0),
- H = Distance(0, 0, corner1[2], 0, 0, corner2[2]),
- CX = corner2[0] - corner1[0],
- CY = corner2[1] - corner1[1],
- CZ = corner2[2] - corner1[2];
- int ROWS = roundUp(W/60),
- COLUMNS = roundUp(L/32),
- HEIGHT = roundUp(H/20);
- float XA = (!ROWS ? 0 : CX/ROWS),
- YA = (!COLUMNS ? 0 : CY/COLUMNS),
- ZA = (!HEIGHT ? 0 : CZ/HEIGHT);
- int center = spawnEntity(true, "carepackage_friendly_iw6", corner1[0], corner1[1], corner1[2], 0,0,0);
- for(int r = 0; r <= ROWS; r++) {
- for(int c = 0; c <= COLUMNS; c++) {
- for(int h = 0; h <= HEIGHT; h++) {
- int block = spawnEntity(true, "carepackage_friendly_iw6", corner1[0] + (XA * r), corner1[1] + (YA * c),
- corner1[2] + (ZA * h), 0, 0, 0);
- LinkTo(block, center);
- }
- }
- }
- G_SetAngle(center, angle);
- SV_LinkEntity(center);
- }
- void CreateWall(float* start, float *end)
- {
- float D = Distance(start[0], start[1], 0, end[0], end[1], 0),
- H = Distance(0, 0, start[2], 0, 0, end[2]);
- int blocks = roundUp(D/60),
- height = roundUp(H/32);
- float CX = end[0] - start[0],
- CY = end[1] - start[1],
- CZ = end[2] - start[2],
- XA = (CX/blocks),
- YA = (CY/blocks),
- ZA = (CZ/height),
- TXA = (XA/4),
- TYA = (YA/4),
- Temp[3], Temp2[3];
- for(int i = 0; i < 3; i ++)
- Temp2[i] = end[i] - start[i];
- vectoangles(Temp2, Temp);
- for(int h = 0; h < height; h++){
- spawnEntity(true, "carepackage_friendly_iw6", start[0] + TXA, start[1] + TYA,
- start[2] + 10 + (ZA*h), 0, Temp[1], 90);
- for(int i = 1; i < blocks; i++){
- spawnEntity(true, "carepackage_friendly_iw6", start[0] + (XA*i), start[1] + (YA*i),
- start[2] + 10 + (ZA*h), 0, Temp[1], 90);
- }
- spawnEntity(true, "carepackage_friendly_iw6",end[0] + (TXA*-1), end[1] + (TYA*-1),
- start[2] + 10 + (ZA*h), 0, Temp[1], 90);
- }
- }
- void CreateBridge(float* point1, float* point2, float* point3)//See the function below to understand
- {
- float *points[3] = {point1, point2, point3};
- for(int i = 0; i < 3; i++) {
- if(i+1 >= ((point3[0]==-1234543.3f&&point3[1]==0) ? 2 : 3))
- return;
- int blocks = roundUp(Distance(points[i], points[i+1])/32);
- float CX = points[i][0] - points[i+1][0],
- CY = points[i][1] - points[i+1][1],
- CZ = points[i][2] - points[i+1][2],
- XA = CX/blocks,
- YA = CY/blocks,
- ZA = CZ/blocks,
- CXY = Distance((points[i][0], points[i][1], 0), (points[i+1][0], points[i+1][1], 0)),
- Temp[3], Temp2[3] = {points[i][0] - points[i+1][0], points[i][1] - points[i+1][1],
- points[i][2] - points[i+1][2]};
- vectoangles(Temp2, Temp);
- for(int b = 0; b <= blocks; b++){
- spawnEntity(true, "carepackage_friendly_iw6", points[i+1][0] + (XA*b), points[i+1][1] + (YA*b), points[i+1][2] + (ZA*b),
- Temp[2], Temp[1] + 90, Temp[0]);
- }
- }
- }
- void CreateBridge(float point1X, float point1Y, float point1Z, float point2X, float point2Y,
- float point2Z, float point3X = -1234543.3f, float point3Y = 0, float point3Z = 0)//the point3 isn't needed unless you want to make a 3rd point
- {
- float point1[] = {point1X,point1Y,point1Z},
- point2[] = {point2X,point2Y,point2Z},
- point3[] = {point3X,point3Y,point3Z};
- CreateBridge(point1, point2, point3);
- }
- [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement