3D iron sights
Note: This update breaks mod compatibility for rifle skins. To use old skins, you need to copy Scripts/Skin/[weapon name here]/View.as from the 0.0.9 official release.
This commit is contained in:
parent
4db816a94c
commit
63fc860a88
@ -1,6 +1,6 @@
|
||||
|
||||
All paks for development vesion:
|
||||
|
||||
http://yvt.jp/files/programs/osppaks/DevPaks9.zip
|
||||
http://yvt.jp/files/programs/osppaks/DevPaks10.zip
|
||||
|
||||
|
||||
|
@ -31,6 +31,8 @@
|
||||
private AudioChunk@ fireFarSound;
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@ reloadSound;
|
||||
private Model@ sightModel1;
|
||||
private Model@ sightModel2;
|
||||
|
||||
ViewRifleSkin(Renderer@ r, AudioDevice@ dev){
|
||||
super(r);
|
||||
@ -39,6 +41,10 @@
|
||||
("Models/Weapons/Rifle/WeaponNoMagazine.kv6");
|
||||
@magazineModel = renderer.RegisterModel
|
||||
("Models/Weapons/Rifle/Magazine.kv6");
|
||||
@sightModel1 = renderer.RegisterModel
|
||||
("Models/Weapons/Rifle/Sight1.kv6");
|
||||
@sightModel2 = renderer.RegisterModel
|
||||
("Models/Weapons/Rifle/Sight2.kv6");
|
||||
|
||||
@fireSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Rifle/FireLocal.wav");
|
||||
@ -79,7 +85,22 @@
|
||||
}
|
||||
|
||||
float GetZPos() {
|
||||
return 0.2f - AimDownSightStateSmooth * 0.05f;
|
||||
return 0.2f - AimDownSightStateSmooth * 0.0520f;
|
||||
}
|
||||
|
||||
// rotates gun matrix to ensure the sight is in
|
||||
// the center of screen (0, ?, 0).
|
||||
Matrix4 AdjustToAlignSight(Matrix4 mat, Vector3 sightPos, float fade) {
|
||||
Vector3 p = mat * sightPos;
|
||||
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), atan(p.x / p.y) * fade) * mat;
|
||||
mat = CreateRotateMatrix(Vector3(-1.f, 0.f, 0.f), atan(p.z / p.y) * fade) * mat;
|
||||
return mat;
|
||||
}
|
||||
|
||||
void Draw2D() {
|
||||
if(AimDownSightState > 0.6)
|
||||
return;
|
||||
BasicViewWeapon::Draw2D();
|
||||
}
|
||||
|
||||
void AddToScene() {
|
||||
@ -97,11 +118,30 @@
|
||||
Vector3 rightHand3 = mat * Vector3(-2.f, -7.f, -4.f);
|
||||
Vector3 rightHand4 = mat * Vector3(-3.f, -4.f, -6.f);
|
||||
|
||||
if(AimDownSightStateSmooth > 0.8f){
|
||||
mat = AdjustToAlignSight(mat, Vector3(0.f, 16.f, -4.6f), (AimDownSightStateSmooth - 0.8f) / 0.2f);
|
||||
}
|
||||
|
||||
ModelRenderParam param;
|
||||
param.matrix = eyeMatrix * mat;
|
||||
Matrix4 weapMatrix = eyeMatrix * mat;
|
||||
param.matrix = weapMatrix * CreateScaleMatrix(0.5f) *
|
||||
CreateTranslateMatrix(-0.5f, 0.f, 0.f);
|
||||
param.depthHack = true;
|
||||
renderer.AddModel(gunModel, param);
|
||||
|
||||
// draw sights
|
||||
Matrix4 sightMat = weapMatrix;
|
||||
sightMat *= CreateTranslateMatrix(0.0125f, -8.f, -4.5f);
|
||||
sightMat *= CreateScaleMatrix(0.025f);
|
||||
param.matrix = sightMat;
|
||||
renderer.AddModel(sightModel1, param); // rear
|
||||
|
||||
sightMat = weapMatrix;
|
||||
sightMat *= CreateTranslateMatrix(0.025f, 16.f, -4.6f);
|
||||
sightMat *= CreateScaleMatrix(0.05f);
|
||||
param.matrix = sightMat;
|
||||
renderer.AddModel(sightModel2, param); // front pin
|
||||
|
||||
// magazine/reload action
|
||||
mat *= CreateTranslateMatrix(0.f, 1.f, 1.f);
|
||||
reload *= 2.5f;
|
||||
|
@ -26,6 +26,9 @@
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ gunModel;
|
||||
private Model@ magazineModel;
|
||||
private Model@ sightModel1;
|
||||
private Model@ sightModel2;
|
||||
private Model@ sightModel3;
|
||||
|
||||
private AudioChunk@[] fireSounds(4);
|
||||
private AudioChunk@ fireFarSound;
|
||||
@ -39,6 +42,12 @@
|
||||
("Models/Weapons/SMG/WeaponNoMagazine.kv6");
|
||||
@magazineModel = renderer.RegisterModel
|
||||
("Models/Weapons/SMG/Magazine.kv6");
|
||||
@sightModel1 = renderer.RegisterModel
|
||||
("Models/Weapons/SMG/Sight1.kv6");
|
||||
@sightModel2 = renderer.RegisterModel
|
||||
("Models/Weapons/SMG/Sight2.kv6");
|
||||
@sightModel3 = renderer.RegisterModel
|
||||
("Models/Weapons/SMG/Sight3.kv6");
|
||||
|
||||
@fireSounds[0] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireLocal1.wav");
|
||||
@ -87,7 +96,22 @@
|
||||
}
|
||||
|
||||
float GetZPos() {
|
||||
return 0.2f - AimDownSightStateSmooth * 0.028f;
|
||||
return 0.2f - AimDownSightStateSmooth * 0.038f;
|
||||
}
|
||||
|
||||
// rotates gun matrix to ensure the sight is in
|
||||
// the center of screen (0, ?, 0).
|
||||
Matrix4 AdjustToAlignSight(Matrix4 mat, Vector3 sightPos, float fade) {
|
||||
Vector3 p = mat * sightPos;
|
||||
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), atan(p.x / p.y) * fade) * mat;
|
||||
mat = CreateRotateMatrix(Vector3(-1.f, 0.f, 0.f), atan(p.z / p.y) * fade) * mat;
|
||||
return mat;
|
||||
}
|
||||
|
||||
void Draw2D() {
|
||||
if(AimDownSightState > 0.6)
|
||||
return;
|
||||
BasicViewWeapon::Draw2D();
|
||||
}
|
||||
|
||||
void AddToScene() {
|
||||
@ -105,11 +129,35 @@
|
||||
Vector3 leftHand3 = mat * Vector3(1.f, 6.f, -4.f);
|
||||
Vector3 leftHand4 = mat * Vector3(1.f, 9.f, -6.f);
|
||||
|
||||
if(AimDownSightStateSmooth > 0.8f){
|
||||
mat = AdjustToAlignSight(mat, Vector3(0.f, 5.f, -4.9f), (AimDownSightStateSmooth - 0.8f) / 0.2f);
|
||||
}
|
||||
|
||||
ModelRenderParam param;
|
||||
param.matrix = eyeMatrix * mat;
|
||||
Matrix4 weapMatrix = eyeMatrix * mat;
|
||||
param.matrix = weapMatrix;
|
||||
param.depthHack = true;
|
||||
renderer.AddModel(gunModel, param);
|
||||
|
||||
// draw sights
|
||||
Matrix4 sightMat = weapMatrix;
|
||||
sightMat *= CreateTranslateMatrix(0.05f, 5.f, -4.85f);
|
||||
sightMat *= CreateScaleMatrix(0.1f);
|
||||
param.matrix = sightMat;
|
||||
renderer.AddModel(sightModel1, param); // front
|
||||
|
||||
sightMat = weapMatrix;
|
||||
sightMat *= CreateTranslateMatrix(0.025f, 5.f, -4.85f);
|
||||
sightMat *= CreateScaleMatrix(0.05f);
|
||||
param.matrix = sightMat;
|
||||
renderer.AddModel(sightModel3, param); // front pin
|
||||
|
||||
sightMat = weapMatrix;
|
||||
sightMat *= CreateTranslateMatrix(0.04f, -9.f, -4.9f);
|
||||
sightMat *= CreateScaleMatrix(0.08f);
|
||||
param.matrix = sightMat;
|
||||
renderer.AddModel(sightModel2, param); // rear
|
||||
|
||||
// magazine/reload action
|
||||
mat *= CreateTranslateMatrix(0.f, 3.f, 1.f);
|
||||
reload *= 2.5f;
|
||||
|
@ -26,6 +26,8 @@
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ gunModel;
|
||||
private Model@ pumpModel;
|
||||
private Model@ sightModel1;
|
||||
private Model@ sightModel2;
|
||||
|
||||
private AudioChunk@ fireSound;
|
||||
private AudioChunk@ fireFarSound;
|
||||
@ -40,6 +42,10 @@
|
||||
("Models/Weapons/Shotgun/WeaponNoPump.kv6");
|
||||
@pumpModel = renderer.RegisterModel
|
||||
("Models/Weapons/Shotgun/Pump.kv6");
|
||||
@sightModel1 = renderer.RegisterModel
|
||||
("Models/Weapons/Shotgun/Sight1.kv6");
|
||||
@sightModel2 = renderer.RegisterModel
|
||||
("Models/Weapons/Shotgun/Sight2.kv6");
|
||||
|
||||
|
||||
@fireSound = dev.RegisterSound
|
||||
@ -92,7 +98,22 @@
|
||||
}
|
||||
|
||||
float GetZPos() {
|
||||
return 0.2f - AimDownSightStateSmooth * 0.05f;
|
||||
return 0.2f - AimDownSightStateSmooth * 0.0535f;
|
||||
}
|
||||
|
||||
// rotates gun matrix to ensure the sight is in
|
||||
// the center of screen (0, ?, 0).
|
||||
Matrix4 AdjustToAlignSight(Matrix4 mat, Vector3 sightPos, float fade) {
|
||||
Vector3 p = mat * sightPos;
|
||||
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), atan(p.x / p.y) * fade) * mat;
|
||||
mat = CreateRotateMatrix(Vector3(-1.f, 0.f, 0.f), atan(p.z / p.y) * fade) * mat;
|
||||
return mat;
|
||||
}
|
||||
|
||||
void Draw2D() {
|
||||
if(AimDownSightState > 0.6)
|
||||
return;
|
||||
BasicViewWeapon::Draw2D();
|
||||
}
|
||||
|
||||
void AddToScene() {
|
||||
@ -108,11 +129,30 @@
|
||||
Vector3 leftHand2 = mat * Vector3(5.f, -10.f, 4.f);
|
||||
Vector3 leftHand3 = mat * Vector3(1.f, 1.f, 2.f);
|
||||
|
||||
if(AimDownSightStateSmooth > 0.8f){
|
||||
mat = AdjustToAlignSight(mat, Vector3(0.f, 8.5f, -4.4f),
|
||||
(AimDownSightStateSmooth - 0.8f) / 0.2f);
|
||||
}
|
||||
|
||||
ModelRenderParam param;
|
||||
param.matrix = eyeMatrix * mat;
|
||||
Matrix4 weapMatrix = eyeMatrix * mat;
|
||||
param.matrix = weapMatrix;
|
||||
param.depthHack = true;
|
||||
renderer.AddModel(gunModel, param);
|
||||
|
||||
// draw sights
|
||||
Matrix4 sightMat = weapMatrix;
|
||||
sightMat *= CreateTranslateMatrix(0.025f, -9.f, -4.4f);
|
||||
sightMat *= CreateScaleMatrix(0.05f);
|
||||
param.matrix = sightMat;
|
||||
renderer.AddModel(sightModel2, param); // rear
|
||||
|
||||
sightMat = weapMatrix;
|
||||
sightMat *= CreateTranslateMatrix(0.025f, 8.5f, -4.4f);
|
||||
sightMat *= CreateScaleMatrix(0.05f);
|
||||
param.matrix = sightMat;
|
||||
renderer.AddModel(sightModel1, param); // front pin
|
||||
|
||||
// reload action
|
||||
reload *= 0.5f;
|
||||
leftHand = mat * Vector3(0.f, 4.f, 2.f);
|
||||
|
Loading…
x
Reference in New Issue
Block a user