aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/LightningBoltRenderer.cpp
blob: 46b628dfb0379b1b4a0f7feb79998a44f12f682b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "stdafx.h"
#include "LightningBoltRenderer.h"
#include "Tesselator.h"
#include "..\Minecraft.World\net.minecraft.world.entity.global.h"

void LightningBoltRenderer::render(shared_ptr<Entity> _bolt, double x, double y, double z, float rot, float a)
{
	// 4J - dynamic cast required because we aren't using templates/generics in our version
	shared_ptr<LightningBolt> bolt = dynamic_pointer_cast<LightningBolt>(_bolt);

    Tesselator *t = Tesselator::getInstance();

    glDisable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);


    double xOffs[8];
    double zOffs[8];
    double xOff = 0;
    double zOff = 0;
    {
        Random *random = new Random(bolt->seed);
        for (int h = 7; h >= 0; h--)
		{
            xOffs[h] = xOff;
            zOffs[h] = zOff;
            xOff += random->nextInt(11) - 5;
            zOff += random->nextInt(11) - 5;
        }
    }

    for (int r = 0; r < 4; r++)
	{
        Random *random = new Random(bolt->seed);
        for (int p = 0; p < 3; p++)
		{
            int hs = 7;
            int ht = 0;
            if (p > 0) hs = 7 - p;
            if (p > 0) ht = hs - 2;
            double xo0 = xOffs[hs] - xOff;
            double zo0 = zOffs[hs] - zOff;
            for (int h = hs; h >= ht; h--)
			{
                double xo1 = xo0;
                double zo1 = zo0;
                if (p == 0)
				{
                    xo0 += random->nextInt(11) - 5;
                    zo0 += random->nextInt(11) - 5;
                }
				else
				{
                    xo0 += random->nextInt(31) - 15;
                    zo0 += random->nextInt(31) - 15;
                }

                t->begin(GL_TRIANGLE_STRIP);
                float br = 0.5f;
                t->color(0.9f * br, 0.9f * br, 1 * br, 0.3f);

                double rr1 = (0.1 + r * 0.2);
                if (p == 0) rr1 *= (h * 0.1 + 1);

                double rr2 = (0.1 + r * 0.2);
                if (p == 0) rr2 *= ((h-1) * 0.1 + 1);

                for (int i = 0; i < 5; i++)
				{
                    double xx1 = x + 0.5 - rr1;
                    double zz1 = z + 0.5 - rr1;
                    if (i == 1 || i == 2) xx1 += rr1 * 2;
                    if (i == 2 || i == 3) zz1 += rr1 * 2;

                    double xx2 = x + 0.5 - rr2;
                    double zz2 = z + 0.5 - rr2;
                    if (i == 1 || i == 2) xx2 += rr2 * 2;
                    if (i == 2 || i == 3) zz2 += rr2 * 2;

                    t->vertex(static_cast<float>(xx2 + xo0), static_cast<float>(y + (h) * 16), static_cast<float>(zz2 + zo0));
                    t->vertex(static_cast<float>(xx1 + xo1), static_cast<float>(y + (h + 1) * 16), static_cast<float>(zz1 + zo1));

                }

                t->end();
            }
        }
    }


    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);

}