Ejemplo n.º 1
0
    def __init__(self, plus, scene, main_light, resolution, parameters):

        self.layers = []
        for layer_params in parameters["layers"]:
            self.layers.append(CloudsLayer(plus, scene, layer_params))

        self.name = parameters["name"]
        self.t = 0
        self.cam_pos = None
        self.bitmap_clouds = hg.Picture()
        self.bitmap_clouds_file = parameters["bitmap_clouds_file"]
        hg.LoadPicture(self.bitmap_clouds, self.bitmap_clouds_file)
        self.map_size = hg.IntVector2(self.bitmap_clouds.GetWidth(),
                                      self.bitmap_clouds.GetHeight())
        self.map_scale = list_to_vec2(parameters["map_scale"])
        self.map_position = list_to_vec2(parameters["map_position"])
        self.sun_light = main_light
        self.ambient_color = scene.GetEnvironment().GetAmbientColor(
        ) * scene.GetEnvironment().GetAmbientIntensity()
        self.v_wind = hg.Vector2(60, 60)
        if "v_wind" in parameters:
            self.v_wind = list_to_vec2(parameters["v_wind"])

        self.update_layers_cloud_map()
        self.update_layers_environment()
        self.update_particles()
Ejemplo n.º 2
0
 def set_map(self, bitmap: hg.Picture, map_scale: hg.Vector2,
             map_position: hg.Vector2):
     self.bitmap_clouds = bitmap
     self.map_scale = map_scale
     self.map_size = hg.IntVector2(self.bitmap_clouds.GetWidth(),
                                   self.bitmap_clouds.GetHeight())
     self.offset = map_position
Ejemplo n.º 3
0
    def __init__(self,
                 distance_min=0,
                 distance_max=1000,
                 tile_size=10,
                 margin=1.,
                 focal_margin=1.1):
        self.distance_min = distance_min
        self.distance_max = distance_max
        self.tile_size = tile_size
        self.O = hg.Vector2()
        self.A = hg.Vector2()
        self.B = hg.Vector2()
        self.focal_margin = focal_margin
        self.margin = margin
        self.Oint = hg.IntVector2()
        self.Aint = hg.IntVector2()
        self.Bint = hg.IntVector2()

        self.indiceA, self.indiceB = 0, 0
        self.ymin, self.ymax = 0, 0
        self.dAB, self.dBC, self.dAC = hg.IntVector2(), hg.IntVector2(
        ), hg.IntVector2()
        self.detAB, self.detBC, self.detAC = 0, 0, 0
        self.obs = None
        self.obs2D = None
        self.vertices = []
        self.case = 0
        self.send_position = self.default_send
Ejemplo n.º 4
0
res_w = 520
res_h = 360
monitors = None
monitors_names = []
modes = None
current_monitor = 0
current_mode = 0
ratio_filter = 0
flag_windowed = False

screenModes = [
    hg.FullscreenMonitor1, hg.FullscreenMonitor2, hg.FullscreenMonitor3
]
smr_screenMode = hg.FullscreenMonitor1
smr_resolution = hg.IntVector2(1280, 1024)


def gui_ScreenModeRequester():
    global flag_windowed
    global current_monitor, current_mode, monitors_names, modes

    hg.ImGuiSetNextWindowPosCenter(hg.ImGuiCond_Always)
    hg.ImGuiSetNextWindowSize(hg.Vector2(res_w, res_h), hg.ImGuiCond_Always)
    if hg.ImGuiBegin(
            "Choose screen mode", hg.ImGuiWindowFlags_NoTitleBar
            | hg.ImGuiWindowFlags_MenuBar
            | hg.ImGuiWindowFlags_NoMove
            | hg.ImGuiWindowFlags_NoSavedSettings
            | hg.ImGuiWindowFlags_NoCollapse):
        if hg.ImGuiBeginCombo("Monitor", monitors_names[current_monitor]):
Ejemplo n.º 5
0
# Blit from a picture to another picture

import os
import harfang as hg

hg.LoadPlugins()

# mount the system file driver
hg.MountFileDriver(hg.StdFileDriver())

# load pictures
owl = hg.Picture()
hg.LoadPicture(owl, "_data/owl.jpg")
blink = hg.Picture()
hg.LoadPicture(blink, "_data/blink.jpg")

# blit the center portion of the blinking owl to the lower right corner of the owl picture
owl.Blit(blink, hg.IntRect(128, 128, 384, 384), hg.IntVector2(256, 256))

# blit and stretch the complete blinking owl to the lower left corner of the owl picture
owl.Blit(blink, hg.IntRect(0, 0, 512, 512), hg.IntRect(0, 256, 256, 512),
         hg.FilterBlackman36)

owl.Convert(hg.PictureRGB8)
hg.SavePicture(owl, "blit_picture.jpg", "IJG", "q:100")
Ejemplo n.º 6
0
    def update_triangle(self, resolution, position: hg.Vector3,
                        direction: hg.Vector3, zoomFactor):
        self.obs = position
        self.obs2D = hg.Vector2(self.obs.x, self.obs.z)
        dir3D = direction
        dir2D = hg.Vector2(dir3D.x, dir3D.z).Normalized()
        focal_distance = zoomFactor * self.focal_margin
        view_width = 2 * resolution.x / resolution.y  # 2 because screen xmin=-1, screen xmax=1

        distAB = self.distance_max * view_width / focal_distance
        VUab = hg.Vector2(-dir2D.y, dir2D.x)
        dir2D *= self.distance_max
        VUab *= distAB / 2

        self.O = hg.Vector2(self.obs.x, self.obs.z)
        self.A = hg.Vector2(self.obs.x + dir2D.x - VUab.x,
                            self.obs.z + dir2D.y - VUab.y)
        self.B = hg.Vector2(self.obs.x + dir2D.x + VUab.x,
                            self.obs.z + dir2D.y + VUab.y)

        # Margin:
        cx = (self.O.x + self.A.x + self.B.x) / 3
        cy = (self.O.y + self.A.y + self.B.y) / 3
        self.O.x = (self.O.x - cx) * self.margin + cx
        self.O.y = (self.O.y - cy) * self.margin + cy
        self.A.x = (self.A.x - cx) * self.margin + cx
        self.A.y = (self.A.y - cy) * self.margin + cy
        self.B.x = (self.B.x - cx) * self.margin + cx
        self.B.y = (self.B.y - cy) * self.margin + cy

        # Tiled triangle:
        self.Oint = hg.IntVector2(int(round(self.O.x / self.tile_size)),
                                  int(round(self.O.y / self.tile_size)))
        self.Aint = hg.IntVector2(int(round(self.A.x / self.tile_size)),
                                  int(round(self.A.y / self.tile_size)))
        self.Bint = hg.IntVector2(int(round(self.B.x / self.tile_size)),
                                  int(round(self.B.y / self.tile_size)))

        self.vertices = [self.Oint, self.Aint, self.Bint]

        self.indiceA = 0
        self.ymin = self.Oint.y
        self.ymax = self.ymin
        if self.Aint.y < self.ymin:
            self.ymin = self.Aint.y
            self.indiceA = 1

        if self.Bint.y < self.ymin:
            self.ymin = self.Bint.y
            self.indiceA = 2
        if self.Aint.y > self.ymax:
            self.ymax = self.Aint.y
        if self.Bint.y > self.ymax:
            self.ymax = self.Bint.y

        self.indiceB = (self.indiceA + 1) % 3
        self.indiceC = (self.indiceA + 2) % 3

        if self.vertices[self.indiceA].y == self.vertices[self.indiceC].y:
            self.indiceA = self.indiceC
            self.indiceB = (self.indiceA + 1) % 3
            self.indiceC = (self.indiceA + 2) % 3

        self.dAB.x = self.vertices[self.indiceB].x - self.vertices[
            self.indiceA].x
        self.dAB.y = self.vertices[self.indiceB].y - self.vertices[
            self.indiceA].y
        self.dBC.x = self.vertices[self.indiceC].x - self.vertices[
            self.indiceB].x
        self.dBC.y = self.vertices[self.indiceC].y - self.vertices[
            self.indiceB].y
        self.dAC.x = self.vertices[self.indiceC].x - self.vertices[
            self.indiceA].x
        self.dAC.y = self.vertices[self.indiceC].y - self.vertices[
            self.indiceA].y

        if self.dAB.y == 0:
            self.detAB = 0
        else:
            self.detAB = float(self.dAB.x) / float(self.dAB.y)

        if self.dBC.y == 0:
            self.detBC = 0
        else:
            self.detBC = float(self.dBC.x) / float(self.dBC.y)

        if self.dAC.y == 0:
            self.detAC = 0
        else:
            self.detAC = float(self.dAC.x) / float(self.dAC.y)
Ejemplo n.º 7
0
cam.GetCamera().SetZNear(1)
cam.GetCamera().SetZFar(100000)  # 100km

# sky lighting
sky = hg.RenderScript("@core/lua/sky_lighting.lua")
sky.Set("time_of_day", 16.5)
sky.Set("attenuation", 0.75)
sky.Set("shadow_range", 10000.0)  # 10km shadow range
sky.Set("shadow_split", hg.Vector4(0.1, 0.2, 0.3, 0.4))
scn.AddComponent(sky)

# load terrain
terrain = hg.Terrain()
terrain.SetSize(hg.Vector3(68767, 5760, 68767))
terrain.SetHeightmap("@data/terrain/island.r16")
terrain.SetHeightmapResolution(hg.IntVector2(1024, 1024))
terrain.SetMinPrecision(
    50
)  # don't bother with a very fine grid given the low resolution heightmap in use
terrain.SetSurfaceShader("@data/terrain/island.isl")

terrain_node = hg.Node()
terrain_node.AddComponent(hg.Transform())
terrain_node.AddComponent(terrain)
scn.AddNode(terrain_node)

#
fps = hg.FPSController(0, 3000, -30000, 100, 400)

while not plus.IsAppEnded():
    dt = plus.UpdateClock()