Exemple #1
0
 def create_particles(plus, scene, file_name, num, name):
     particles = []
     for i in range(num):
         node, geo = load_object(plus, file_name, name + "." + str(i), True)
         # scene.AddNode(node)
         particles.append([geo, hg.Matrix4(), geo.GetMaterial(0)])
     return particles
Exemple #2
0
def update_camera_follow(camera: hg.Node, dts):
    global target_point, target_node
    update_target_point(dts)
    rot_mat = update_follow_direction(camera)
    pos = update_follow_translation(camera, dts)
    mat = hg.Matrix4(rot_mat)
    mat.SetTranslation(pos)
    return mat
Exemple #3
0
def update_camera_tracking(camera: hg.Node, dts, noise_level=0):
    global target_point, target_node
    update_target_point(dts)
    rot_mat = update_track_direction(camera, dts, noise_level)
    pos = update_track_translation(camera, dts)
    mat = hg.Matrix4(rot_mat)
    mat.SetTranslation(pos)
    return mat
Exemple #4
0
def create_explosion(plus, scn, pos, debris_amount=32, debris_radius=0.5):
	scn.GetPhysicSystem().SetForceRigidBodyAxisLockOnCreation(0)
	new_debris_list = []
	for i in range(debris_amount):
		debris_size = uniform(0.1, 0.25)
		debris = plus.AddPhysicCube(scn, hg.Matrix4().TransformationMatrix(pos + rvect(debris_radius), rvect(radians(45))),
									debris_size, debris_size, debris_size, 0.05, "assets/materials/green.mat")
		debris[1].ApplyLinearImpulse(rvect(0.25))
		new_debris_list.append(debris[0])

	return new_debris_list
Exemple #5
0
    def set_particle(self, position: hg.Vector2):
        self.num_tiles += 1
        # x = int(position.x / self.map_scale.x * self.map_size.x)
        # y = int(position.y / self.map_scale.y * self.map_size.y)
        # c = self.bitmap_clouds.GetPixelRGBA(int(x % self.map_size.x), int(y % self.map_size.y))
        c = self.get_pixel_bilinear(
            (position + self.offset * self.morph_level) / self.map_scale)

        scale_factor = pow(c.x, self.scale_falloff)
        # id = int(max(0,scale_factor - self.layer_2_alpha_threshold) / (1 - self.layer_2_alpha_threshold) * 7)
        id = int(
            (sin(position.x * 1735.972 + position.y * 345.145) * 0.5 + 0.5) *
            (self.num_geometries - 1))
        if self.particle_index[id] < self.num_particles[id]:

            particle = self.particles[id][self.particle_index[id]]
            if c.x > self.alpha_threshold:
                smooth_alpha_threshold = min(1, (c.x - self.alpha_threshold) /
                                             self.smooth_alpha_threshold_step)
                s = self.particles_scale_range.x + scale_factor * self.scale_size
                py = self.altitude + s * self.altitude_floor + (
                    self.perturbation * (1 - c.x) * sin(position.x * 213))
                pos = hg.Vector3(position.x - self.offset.x, py,
                                 position.y - self.offset.y)

                d = (hg.Vector2(pos.x, pos.z) -
                     hg.Vector2(self.cam_pos.x, self.cam_pos.z)).Len()
                layer_n = abs(
                    max(
                        0,
                        min(1, (d - self.distance_min) /
                            (self.distance_max - self.distance_min))) * 2 - 1)
                self.pc.a = (1 - min(pow(layer_n, 8), 1)) * (
                    1 - pow(1. - scale_factor,
                            self.alpha_scale_falloff)) * smooth_alpha_threshold

                particle[1] = hg.Matrix4(hg.Matrix3.Identity)
                particle[1].SetScale(hg.Vector3(s, s, s))

                particle[1].SetTranslation(pos)
                material = particle[2]
                material.SetFloat2("pos0", position.x, position.y)
                material.SetFloat("alpha_cloud", self.pc.a)

                self.renderable_system.DrawGeometry(particle[0], particle[1])

                self.particle_index[id] += 1