Skip to content

Commit

Permalink
implement object position
Browse files Browse the repository at this point in the history
Signed-off-by: Yuji Ito <llamerada.jp@gmail.com>
  • Loading branch information
llamerada-jp committed Nov 12, 2023
1 parent cff6fb4 commit b7a8c9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
7 changes: 3 additions & 4 deletions cmd/app/fox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"
"os"
"sync"
"time"
Expand Down Expand Up @@ -161,10 +162,8 @@ func (f *fox) start() {
}

func (f *fox) loop() {
/*
f.Longitude += rand.Float64() * 0.00001
f.Latitude += rand.Float64() * 0.00001
//*/
f.Longitude += rand.Float64() * 0.00001
f.Latitude += rand.Float64() * 0.00001

f.object.Position.X = f.Longitude
f.object.Position.Y = f.Latitude
Expand Down
32 changes: 27 additions & 5 deletions src/ui/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,13 @@ class OinariOverlayView extends ThreeJSOverlayView {
for (let obj of objects) {
this.applyingObjects.set(obj.meta.uuid, obj);
}
this.requestRedraw();
}

deleteObjects(uuids: string[]): void {
for (let uuid of uuids) {
this.applyingObjects.delete(uuid);
this.deletingObjects.add(uuid);
}
this.requestRedraw();
}

onDraw({ gl, transformer }: google.maps.WebGLDrawOptions): void {
Expand All @@ -212,6 +210,19 @@ class OinariOverlayView extends ThreeJSOverlayView {
this.objects.delete(uuid);
}
this.deletingObjects.clear();

for (const [_, wrapper] of this.objects) {
// wrapper.transformPosition(transformer);
// TODO: this code is workaround. i couldn't find the correct way.
wrapper.position.copy(this.latLngAltitudeToVector3({
lat: wrapper.objPosition.y,
lng: wrapper.objPosition.x,
altitude: wrapper.objPosition.z,
}));

}

this.requestRedraw();
}
}

Expand All @@ -224,22 +235,33 @@ class ObjectWrapper extends THREE.Group {
sprites: Map<string, THREE.Sprite>;
materials: Map<string, THREE.Material>;
textures: Map<string, TextureEntry>;
// pos: Vec3;
objPosition: Vec3;
position!: THREE.Vector3;

constructor() {
super();

this.sprites = new Map<string, THREE.Sprite>();
this.materials = new Map<string, THREE.Material>();
this.textures = new Map<string, TextureEntry>();
// this.pos = { x: 0, y: 0, z: 0 };
this.objPosition = { x: 0, y: 0, z: 0 } as Vec3;
}

applyObject(obj: Object): void {
this.applyTextures(obj.spec.maps);
this.applyMaterials(obj.spec.materials);
this.applyParts(obj.spec.parts);
// this.pos = obj.spec.position;
this.objPosition = obj.spec.position;
}

transformPosition(transformer: google.maps.CoordinateTransformer): void {
// TODO: this is wrong code. i couldn't find the correct way.
let pos = transformer.fromLatLngAltitude({
lat: this.objPosition.y,
lng: this.objPosition.x,
altitude: this.objPosition.z
});
this.position.set(pos[0], pos[1], pos[2]);
}

applyParts(parts: PartSpec[]): void {
Expand Down

0 comments on commit b7a8c9f

Please sign in to comment.